Closed Bug 1138368 Opened 9 years ago Closed 9 years ago

Setting span.textContent or span.innerHTML does not fire characterData for MutationObserver on span

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: l1aqus, Unassigned)

Details

(Keywords: testcase)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; rv:36.0) Gecko/20100101 Firefox/36.0
Build ID: 20150222232811

Steps to reproduce:

I created two MutationObserver on a span element with characterData option (one with subtree option and other without) and changed text in that element in various ways (see attached test case).


Actual results:

Only cases #3 and #4 fired charactedData event on the MutationObserver with subtree.


Expected results:

I expected cases #1 or #2 to fire characterData event.

The main reason I expected that behavior is because I think that characterData is supposed to be used to track text change of elements, but no one ever changes an element text by changing a text of it's textNode. Everyone just changes textContent or innerHTML of an element itself. I may be wrong though. And if I wrong, then there's no an effective way to track elements text?
Thanks for the testcase!

I can reproduce (current nightly), and no obvious duplicates, but didn't check against the spec.

CCing smaug, who seems to be working on this.
Component: Untriaged → DOM
Keywords: testcase
OS: Windows 7 → All
Product: Firefox → Core
Hardware: x86 → All
Summary: None of the relevant cases fires characterData in MutationObserver → Setting span.textContent or span.innerHTML does not fire characterData for MutationObserver on span
Version: 36 Branch → Trunk
I think per spec you're wrong, and the only way to track text is to track both characterData and insert/remove of textnodes.

Per spec, mutations records with characterData are only queued in the "replace data" algorithm <https://dom.spec.whatwg.org/#concept-cd-replace>.  This algorithm is invoked from the following places:

1)  The "data" setter on the CharacterData interface.
2)  The appendData/insertData/deleteData/replaceData methods on that interface.
3)  The various things that can "split" a text node (splitText, and some range
    operations).
4)  The nodeValue setters on Text, Comment, and ProcessingInstruction nodes.
5)  The textContent setters on Text, Comment, and ProcessingInstruction nodes.
6)  normalize().
7)  Some other range operations (extracting, etc).
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → INVALID
Yeah, in cases #1 and #2 textContent and innerHTML is used, and those first remove all the child
nodes the span has, and then adds new child node(s). No characterData changes here.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: