Open Bug 1631432 Opened 4 years ago Updated 4 years ago

xhtml vs. html: MutationObserver handler skips added nodes in xhtml but not in html

Categories

(Core :: DOM: Core & HTML, defect, P3)

75 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: gauthierarun, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; rv:75.0) Gecko/20100101 Firefox/75.0

Steps to reproduce:

Compare the output of the following code in an .html file with the output of an .xhtml file:

<html
xmlns="http://www.w3.org/1999/xhtml">
<body>
<script>
var count = 0
var global_mutation_observer = new MutationObserver(function(mutation_record){
for (let mutation of mutation_record){
for (let node of mutation.addedNodes){
console.log("added node " + (count++) + ": " + node.nodeName + ", " + node.id)
}
}
})
global_mutation_observer.observe(document, {childList: true, subtree: true, attributes: true})
</script>
<x-custom_element>
<p id = "local_p">abc</p>
<div id="local_div">def</div>
</x-custom_element>
<div>
<p id = "local_p2">abc</p>
<div id="local_div2">def</div>
</div>
</body>
</html>

Actual results:

The outputs of both files are different. Xhtml is behaving badly: it skips many nodes in the MutationObserver handler.

Output of .xhtml:

added node 0: #text, undefined random_test3.xhtml:9:21
added node 1: script, random_test3.xhtml:9:21
added node 2: #text, undefined random_test3.xhtml:9:21
added node 3: x-custom_element, random_test3.xhtml:9:21
added node 4: #text, undefined random_test3.xhtml:9:21
added node 5: div, random_test3.xhtml:9:21
added node 6: #text, undefined random_test3.xhtml:9:21
added node 7: #text, undefined random_test3.xhtml:9:21

Expected results:

What should've happened is getting the same output as .html:

added node 0: #text, undefined random_test3.html:9:21
added node 1: X-CUSTOM_ELEMENT, random_test3.html:9:21
added node 2: #text, undefined random_test3.html:9:21
added node 3: P, local_p random_test3.html:9:21
added node 4: #text, undefined random_test3.html:9:21
added node 5: #text, undefined random_test3.html:9:21
added node 6: DIV, local_div random_test3.html:9:21
added node 7: #text, undefined random_test3.html:9:21
added node 8: #text, undefined random_test3.html:9:21
added node 9: #text, undefined random_test3.html:9:21
added node 10: DIV, random_test3.html:9:21
added node 11: #text, undefined random_test3.html:9:21
added node 12: P, local_p2 random_test3.html:9:21
added node 13: #text, undefined random_test3.html:9:21
added node 14: #text, undefined random_test3.html:9:21
added node 15: DIV, local_div2 random_test3.html:9:21
added node 16: #text, undefined random_test3.html:9:21
added node 17: #text, undefined random_test3.html:9:21
added node 18: #text, undefined random_test3.html:9:21

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Priority: -- → P3

Because this bug's Severity has not been changed from the default since it was filed, and it's Priority is P3 (Backlog,) indicating it has been triaged, the bug's Severity is being updated to S3 (normal.)

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.