Comments (9)
An alternative to this might be to be able to observe the composed tree, because in some cases we might want to know the nodes that will participate in the final output:
I've had to implement composed tree tracking so that webgl-rendered custom elements would render correct results when composed via slots into shadow roots. I'd like to release some of these tools separate libs, maybe it'll help ideate.
Even without custom rendering, it might be beneficial to react to composed nodes, avoiding extra work for trees that are not active. F.e. suppose a client-side route switcher modifies slot attributes to show/hide content, and we want to observe only content in the active tree.
from dom.
As author of all polyfills from v0 to current state, I fully support this proposal. My workaround is not super slow but it requires me patching the global attachShadow
method on native classes which is a practice I usually avoid at all costs and something I've been advocating against for just about forever ... yet polyfill gotta polyfill, so that if this new proposal is the only thing that might need a greedy polyfill around until everyone is onboard, it's definitively worth the effort to me.
On a side note: the closed shadow might still be addressed somehow and I feel like the elephant in the room here is that we don't have a way for Websites authors to decide what is trusted as script that could patch natives, and what isn't ... CSP is not a great answer to this disambiguation, but maybe this discussion should be done in other venues.
from dom.
Over in
@ox-harris implements options.subtree = 'cross-roots'
in the realdom
lib for synchronously observing added/removed elements across shadow root boundaries, and gets us a little closer to synchronous observation of the composed tree (f.e. detect composed children, composed parent, etc).
Not only is the usage simpler than with MutationObserver
(because MO events fire out of order) and lead to simpler code, but composed tree tracking code will also be as simple when that's ready (ComposedChildrenObserver
, ComposedParentObserver
, ComposedMutationObserver
, etc).
from dom.
@LeaVerou could you explain a bit more what is the use case here?
from dom.
@LeaVerou could you explain a bit more what is the use case here?
Sure, what is unclear in my examples?
from dom.
"to implement polyfills of certain features that affect HTML syntax across both light and shadow DOM because it requires observing mutations in shadow trees as well" ... "Any new HTML element or attribute"
So what issue there exactly are you trying to solve?
from dom.
"to implement polyfills of certain features that affect HTML syntax across both light and shadow DOM because it requires observing mutations in shadow trees as well" ... "Any new HTML element or attribute"
So what issue there exactly are you trying to solve?
To implement polyfills of new HTML syntax, you need to be able to react to relevant changes in the DOM. E.g. for a new attribute foobar
, you need to be able to react when someone adds a foobar
attribute anywhere, including deeply nested Shadow DOM. Doing this with the current MutationObserver API is a hack (I listed how in the OP). Does that make sense? If not, it would help to try and formulate an actual question on what part you find confusing.
from dom.
I see, you want to polyfill new global attributes basically.
from dom.
I see, you want to polyfill new global attributes basically.
That's one use case. Or new native elements. Or new attributes on native elements.
from dom.
Related Issues (20)
- Steps of removing a node definition about live range do not match with browsers if the range is in a shadow DOM and the shadow itself is removed HOT 2
- Node Tree Element potential child: Attr ? HOT 5
- Proposal: AbortSignal.none() HOT 4
- I can't find where inserting DocumentType nodes into Element nodes is disallowed HOT 1
- Proposal AbortSignal.prototype.filter(compare) HOT 4
- `mutationObserver.disconnect({ flush: true })` HOT 1
- Proposal: SelectorObserver HOT 2
- Proposal: elementsFromRect() HOT 2
- Request for mechanism to determine if children changed steps are called as a result of script or parser HOT 7
- Add a method like .addTeardown to AbortSignal
- Closed Shadow DOM blocks accessibility testing HOT 1
- Should post-connected steps be able to run multiple times during insertion?
- AbortSignal.any() assertion failure HOT 4
- Proposal: getCornerPoints() HOT 5
- Proposal: rate limiting event listeners (debounce / throttle) HOT 11
- Missing "queue a global task" to resolve Promise in abort example HOT 1
- Missing arguments for “locate a namespace prefix” in `lookupPrefix` steps HOT 1
- Proposal: asynchronous event listeners HOT 7
- Suggestion to Add Translated Link for dom (Simplified Chinese 简体中文)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dom.