wpt icon indicating copy to clipboard operation
wpt copied to clipboard

Trick(?) to force MutationObserver records may not be cross-compatible

Open Kaiido opened this issue 3 years ago • 1 comments

In /shadow-dom/declarative/innerhtml-on-ordinary-template.tentative.html and /shadow-dom/declarative/innerhtml-before-closing-tag.tentative.html a surprising

  <script></script> <!-- Ensure observer runs -->

line is found. This triggered this StackOverflow question where I developed the hypothesis that this line is supposed to force the MutationObserver's notifications to be dispatched before the <script></script>'s parent element is closed.

However, if this hypothesis is indeed the correct one, then it should be noted that it doesn't work in Firefox, where scripts are apparently ran only if the <script> tag actually has a text value.
One solution would be to add the comment as a JS comment inside the <script> instead and maybe change this comment to make it clear it relies on this side-effect.

And if my hypothesis is wrong and that this <script></script> serves an entirely different purpose, I guess a better comment explaining what it is really doing may be a good idea.

cc @mfreed7

Kaiido avatar Aug 09 '22 01:08 Kaiido

Thanks for raising this issue! Also thanks for your analysis on SO, which I agree with.

Per spec, the clean up after running script algorithm, step 3, says:

  1. If the JavaScript execution context stack is now empty, perform a microtask checkpoint. (If this runs scripts, these algorithms will be invoked reentrantly.)

That's called by run a classic script in all cases, and that algorithm makes no mention of exceptions for, e.g. empty scripts.

I might be missing a mention somewhere about empty scripts, but I couldn't find one. If not, this seems like a bug in Gecko, rather than a problem with the test. If so, the likely best course of action would be to raise a bug on Bugzilla.

mfreed7 avatar Aug 10 '22 16:08 mfreed7

Fair enough, I opened https://bugzil.la/1784187 however I still believe this "Ensure observer runs" is quite obscure as to "how" it's supposed to do this, and "when" it does this. Maybe replacing with "Ensure observer runs now" would be enough?

Kaiido avatar Aug 11 '22 02:08 Kaiido

Fair enough, I opened https://bugzil.la/1784187 however I still believe this "Ensure observer runs" is quite obscure as to "how" it's supposed to do this, and "when" it does this. Maybe replacing with "Ensure observer runs now" would be enough?

Thanks for the suggestion - done! Hopefully the new version is more clear. I also added some content to the <script> tag to hopefully make it more compatible with Gecko in the meantime.

mfreed7 avatar Aug 22 '22 16:08 mfreed7