[WICG/webcomponents] [Scoped Registries] Disconnected elements can retain their "origin" by utilising the dangling TreeScope ptr (Issue #1078)

In https://github.com/w3c/tpac2024-breakouts/issues/26 we discussed the idea of how we could store the shadowroot of an element created with `shadowroot.createElement`. Storing the originating shadowroot of calls to this would make this APIs much more ergonomic, as calls to for e.g. `innerHTML` on that node could retain the scoped registry in order to correctly assign definitions to custom elements during that call. Without this these APIs take an ergonomic hit.

It was raised after the meeting (and therefore not in the minutes) that one way to do this without introducing overhead would be to utilise the dangling pointer for the "TreeRoot", which is a `nullptr` for disconnected nodes. In Chromium this pointer is to [`Node`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/dom/node.h), [`nsINode`](https://searchfox.org/mozilla-central/source/dom/base/nsINode.h#330) in Gecko and [`EventTarget`](https://searchfox.org/wubkat/source/Source/WebCore/dom/EventTarget.h#83) in WebKit. Each of these classes has a set of bitflags with what looks like 1 flag remaining ([Chromium's `NodeFlags`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/dom/node.h;drc=0fba000db58b7966ef2b2e9202dabba44f13d62a;l=1063), and [WebKit's `EventTargetFlag`](https://searchfox.org/wubkat/source/Source/WebCore/dom/EventTarget.h#189-209) explicitly mention 1-bit free, and while [Gecko's `BooleanFlag`](https://searchfox.org/mozilla-central/source/dom/base/nsINode.h#1911-1993) uses 32 bits, the last bit is a guard value which could potentially be repurposed).

So - just to check in with implementers (and specifically @emilio, @mfreed7, @rniwa who were in the meeting and may recall the discussion) - could we always populate the `TreeScope` with a Node subtype or Node instance which has a new bit set to say "this is a dummy proxy Node that points to a parent but shouldn't be given to script, and is just for keeping the shadowroot reference alive so that createElement & co work seamlessly" (the variable name could use some bikeshedding).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1078
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/1078@github.com>

Received on Tuesday, 15 October 2024 17:19:27 UTC