Page MenuHomePhabricator

Use MutationObserver to detect when an OO.ui.Element is attached to a document
Closed, ResolvedPublic8 Estimated Story Points

Description

I3fd1e46459215773b0df137a603d788a81bbd8fb adds code which binds to a DOMNodeInsertedIntoDocument event. That event is deprecated, and will stop working at some point. Supposedly MutationObserver is being added as a part of DOM4 as a replacement. So far, it doesn't appear the DOMNodeInsertedIntoDocument was considered in the design of MutationObserver, but hopefully we can come up with a working solution we can integrate into OO.ui.Element for general use.


Version: unspecified
Severity: enhancement

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 2:54 AM
bzimport set Reference to bz62174.

Change 176681 had a related patch set uploaded (by Prtksxna):
[WIP] Use MutationObserver instead of DOMNodeInsertedIntoDocument

https://gerrit.wikimedia.org/r/176681

Patch-For-Review

Jdforrester-WMF moved this task from Backlog to Doing on the OOUI board.
Jdforrester-WMF set Security to None.
Jdforrester-WMF renamed this task from OOjs UI: Use MutationObserver to detect when an OO.ui.Element is attached to a document to Use MutationObserver to detect when an OO.ui.Element is attached to a document.Dec 2 2014, 12:36 AM

This only applies to OO.ui.TextInputWidget, right? I couldn't find any other instances of DOMNodeInsertedIntoDocument.

@TrevorParscal you had some thoughts you wanted to share on this. Looking at the review on the patch it seems that using MutationObserver isn't an option at all.

Our thoughts were to provide a central API through OO.ui.Element by which it emitted attach and detach events. In the case of MutationObserver that would've used one observer and list of OO.ui.Elements it was observing. However given that IE9/10 support neither MutationObserver or the DOMNodeInsertedIntoDocument mutation event it doesn't look like there's any reasonable way to detect attach/detach events.

Change 176681 abandoned by Prtksxna:
TextInputWidget: Use MutationObserver instead of DOMNodeInsertedIntoDocument

https://gerrit.wikimedia.org/r/176681

Thanks for the clarification @Esanders! I've abandoned the patch.

matmarex claimed this task.

So, this look pretty declined to me, then. I filed T89399 about replacing the current approach with something that would actually work.

Turns out we can actually do this, but it needs a different approach. https://phabricator.wikimedia.org/T89399#1084383

Change 194197 had a related patch set uploaded (by Bartosz Dziewoński):
TextInputWidget: Use MutationObserver for #onElementAttach support

https://gerrit.wikimedia.org/r/194197

Change 194197 merged by jenkins-bot:
TextInputWidget: Use MutationObserver for #onElementAttach support

https://gerrit.wikimedia.org/r/194197