Closed
Bug 789315
Opened 12 years ago
Closed 8 years ago
MutationObservers are notified about parsed content after <script> runs, not before
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
FIXED
mozilla45
Tracking | Status | |
---|---|---|
firefox45 | --- | fixed |
People
(Reporter: sicking, Assigned: smaug)
References
Details
Attachments
(4 files, 3 obsolete files)
583 bytes,
text/html
|
Details | |
3.13 KB,
patch
|
khuey
:
review+
baku
:
feedback+
|
Details | Diff | Splinter Review |
3.63 KB,
patch
|
Details | Diff | Splinter Review | |
1.81 KB,
patch
|
Details | Diff | Splinter Review |
When parsing and we hit a <script> element, we should flush all MutationObserver notifications before executing the contents of the script. Note that we should do this after inserting the <script> though. I.e. the MutationObservers should have been notified about the <script> element before the contents of the element begins to run.
Assignee | ||
Comment 1•12 years ago
|
||
(In reply to Jonas Sicking (:sicking) from comment #0) > When parsing and we hit a <script> element, we should flush all > MutationObserver notifications before executing the contents of the script. Why?
Assignee | ||
Comment 2•12 years ago
|
||
Looks like spec's event loop handling is rather odd, but ok, we can do this.
Assignee | ||
Comment 3•12 years ago
|
||
Er, we're doing the right thing per spec, so the spec needs to be changed too.
Assignee | ||
Comment 4•12 years ago
|
||
(Spec just requires stable state, but that doesn't mean end of microtask or end of task, nor is there any special case for mutation observers.)
Reporter | ||
Comment 5•12 years ago
|
||
Yeah, sorry, I'm not sure what the spec requires here. Technically we definitely don't follow the spec right now since the spec calls for no notifications to be fired due to parsing. It simply seemed to me that the behavior in comment #0 made the most sense. My thinking was that running a script is very similar to a microtask. And generally when the outermost microtask starts we have flushed all mutationobserver notifications. The spec defines that notifications are flushed at the end of each outermost microtask, but the effect is that they are flushed by the time the next microtask starts. The advantage over current behavior is script can count on application logic being in a consistent state by the time the script runs. I.e. if you have a MutationObserver which implements a template library, you can know that all the template logic has been updated to the page's current state by the time the script runs. Right now you can't really know which part of the DOM has been notified about since that depends on when the parser last decided to return to the event loop. But I'm very open to other proposals. I mostly filed this because that's how I had assumed it would work. No deeper thinking behind it :)
Assignee | ||
Comment 6•12 years ago
|
||
Not tested properly yet. HTML5 parsing part should be ok (it is actually very tiny change with diff -w), but I need to think about the old content sink stuff still, and actually test them.
Assignee | ||
Comment 7•12 years ago
|
||
(and looks like the xmlcontensink stuff is wrong)
Comment 8•12 years ago
|
||
Spec fixed.
I've noticed that you can get the requested behaviour if you add a 'beforescriptexecute' handler. For example, if I add this line to the testcase: window.addEventListener("beforescriptexecute", function(){console.log("At beforescriptexecute")}, false); I get the output: [01:22:09.334] At beforescriptexecute [01:22:09.335] added #text [01:22:09.335] added B [01:22:09.335] added #text [01:22:09.335] added SCRIPT [01:22:09.335] I'm now in script tag [01:22:09.336] At beforescriptexecute [01:22:09.336] added #text [01:22:09.336] added A [01:22:09.337] added #text [01:22:09.337] added SCRIPT [01:22:09.338] I'm now in second script tag [01:22:09.338] added #text [01:22:09.339] added DIV [01:22:09.339] added #text Can that be relied on as a workaround?
Assignee | ||
Comment 10•12 years ago
|
||
Yes. If there are listeners for beforescriptexecute, the MutationObserver callbacks will be called at the end of microtask, which is end of event listener. But I'll try to get back to this bug ASAP, and then we'll need to change the specs a bit ...
Assignee | ||
Comment 12•9 years ago
|
||
I'll deal with this in a bit different way.
Assignee | ||
Comment 13•9 years ago
|
||
I'm sure khuey likes microtasks these days :) Anyhow, the spec effectively requires a checkpoint before executing a script. The spec is just super convoluted. https://treeherder.mozilla.org/#/jobs?repo=try&revision=e94862364160
Assignee: nobody → bugs
Attachment #663583 -
Attachment is obsolete: true
Attachment #8669869 -
Flags: review?(khuey)
Assignee | ||
Updated•9 years ago
|
Attachment #8669869 -
Flags: review?(amarchesini)
Comment 14•9 years ago
|
||
Comment on attachment 8669869 [details] [diff] [review] v1 Review of attachment 8669869 [details] [diff] [review]: ----------------------------------------------------------------- Sorry but I cannot review this patch. I don't know all the implications of performing a microtask checkpoint. ::: dom/base/test/test_bug789315.html @@ +25,5 @@ > + addedNode.mutationObserverHasNotified = true; > + } > + } > + } > + extra spaces.
Attachment #8669869 -
Flags: review?(amarchesini) → feedback+
Attachment #8669869 -
Flags: review?(khuey) → review+
Assignee | ||
Comment 15•8 years ago
|
||
Assignee | ||
Comment 16•8 years ago
|
||
Assignee | ||
Comment 17•8 years ago
|
||
Comment 18•8 years ago
|
||
Comment on attachment 8692627 [details] [diff] [review] fix for a buggy wpt test Review of attachment 8692627 [details] [diff] [review]: ----------------------------------------------------------------- ::: testing/web-platform/tests/dom/nodes/MutationObserver-document.html @@ +53,5 @@ > + }, > + target: function () { > + return document.getElementById("n00"); > + }}, > + {type: "childList", nit: unindent this by 1 space.
Attachment #8692627 -
Flags: review+
Assignee | ||
Comment 19•8 years ago
|
||
Attachment #8692595 -
Attachment is obsolete: true
Attachment #8692627 -
Attachment is obsolete: true
Comment 20•8 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/d5be1774b0ba https://hg.mozilla.org/integration/mozilla-inbound/rev/ff34a06cb439
Comment 21•8 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/d5be1774b0ba https://hg.mozilla.org/mozilla-central/rev/ff34a06cb439
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox45:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
Updated•5 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•