-
Notifications
You must be signed in to change notification settings - Fork 300
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
Run insertion steps after DocumentFragment insertion completes #576
Conversation
@smaug---- would appreciate review from you as well (note that you can click on Diff in OP to see the changes rendered in HTML). |
Looks reasonable to me. |
@smaug---- see #575 which tests various scenarios along those lines. Unsurprisingly, browsers differ. |
This seems like a pretty big behavior change, if all we want to fix is "don't run scripts before the fragment insertion is done". That is, we would need to audit and test all the things in the spec that do insertion steps to make sure that this is OK, and browsers would need to add a bunch of complexity and runtime overhead to various nodes to make this work. I'm not a huge fan of this last; the runtime overhead of insertion is already bad enough. We do need some sort of delaying mechanism like this specifically for script execution (though possibly not all of "prepare a script"; Gecko does most of "prepare a script" immediately on insertion but defers the "immediately execute the script block" to a safe point, for example), but not necessarily across the board. |
Hmm yeah, you are correct. When I was reading the Firefox code I was led to believe this is in fact the model, but if we inserted a So yeah, we need something more akin to that "script queue" concept and define when to empty it. cc @domenic |
Other things to test:
Bonus:
|
Except in Edge (and maybe Safari given how it executes scripts while inserting them rather than after they are all inserted), <script>
var s1 = document.createElement("style"); s1.textContent = "body { background:lime }";
var s2 = document.createElement("script"); s2.textContent = "w(s1.sheet)";
var df = document.createDocumentFragment(); df.appendChild(s2); df.appendChild(s1);
document.head.appendChild(df);
</script> |
I confirm that Safari also logs |
That's wrong, turns out Chrome already created the stylesheet by the time the script is executed, and the only reason Safari logs <script>
var s1 = document.createElement("style"); s1.textContent = "body { background:lime }";
var s2 = document.createElement("script"); s2.textContent = "w(s1.sheet)";
var df = document.createElement("div"); df.appendChild(s2); df.appendChild(s1);
document.head.appendChild(df);
</script> |
Superseded by #732. |
Fixes whatwg/html#1127 and fixes #575.
Preview | Diff