Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible regression in waiting for DOMContentLoaded #25103

Closed
alan-knight opened this issue Dec 3, 2015 · 3 comments
Closed

Possible regression in waiting for DOMContentLoaded #25103

alan-knight opened this issue Dec 3, 2015 · 3 comments
Labels
P2 A bug or feature request we're likely to work on web-dart2js web-libraries Issues impacting dart:html, etc., libraries

Comments

@alan-knight
Copy link
Contributor

Opening a new bug for possible regression reported in #885 (comment)
@vsmenon did the original fix.

Comment from there by @joseluis is
On version 1.13.0 this doesn't seem true anymore.

Minimal example: querySelector('#someid'); returns null when the element is placed after the script tag that loads the Dart script compiled with dart2js. In order to make it work I must use the script defer attribute, like this:

<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <script src="dart-program.js" defer></script>
        <script id="someid"></script>
    </body>
</html>
@sigmundch
Copy link
Member

yes - dart2js's output requires that you either put the script tag at the end or use the defer attribute in order to be consistent with Dartium's behavior. By default, when you use packages/browser/dart.js, the code will replace the script tag after DOM content loaded, so this bug is not visible unless you load directly the generated .js code.

For production, people commonly want to load the .js code directly, so we request that they do so with the defer attribute. There are some packages that do this transformation automatically, but I've noticed that some of those transformers have a bug regarding this. For example, the package dart_to_js_script_rewriter is not adding the deferred attribute (see issue Workiva/dart_to_js_script_rewriter#21)

@joseluis how did you run into this? Did you update the HTML by hand or did you use a transformer like dart_to_js_script_rewriter?

@joseluis
Copy link

joseluis commented Dec 3, 2015

Thank you for the explanation @sigmundch. I believe it would be good to put this info in the current documentation.

Adding the defer attribute seems the only solid workaround to me, then.

I'm currently working in a Dart program and compiling it with dart2js. I wanted to see what was the simplest way to load it. That's why I wasn't using that dart.js script, and the HTML is also minimal intentionally.

@alan-knight
Copy link
Contributor Author

OK, so it sounds like I can close this.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on and removed Priority-Medium labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on web-dart2js web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

4 participants