matthewp/custom-attributes

Support Shadow DOM registries

Closed this issue · 6 comments

Given the MutationObserver targets the main document, it won't observe mutations inside any Shadow Tree. It's a bit of a niche, but be interested to see whether it's worthwhile supporting.

As far as I can tell, it would take just changing this line to be var root = document; rather than document.documentElement

I don't believe there's any repercussions, given the MO target just needs to be a Node? Then you can pass a Shadow Tree or any document fragment to the CustomAttributeRegistry constructor.

That would also mean having to make the CustomAttributeRegistry class public to define your own registries.

Thoughts?

Hey @bedeoverend sorry I missed this. I think you're definitely right.

I'm not at a computer right now but plan to try this later.

@matthewp no worries - see the PR I've made, I'm using it in something I'm working on, and works so far. Though haven't added any tests for it yet.

Hello guys, I have the shadow boundary problem. I want to register some attributes, and I want them to work on all elements in the app (even if they are in a shadow root).

What's the recommended pattern to make this happen? Do I have to create the registry on each root and re-define the attribute for that root?

I haven't attempted this personally. Is there not a way to make MutationObservers subtree work within a shadow element? If not, I guess customAttributes could be changed to traverse through .shadowRoot itself. Mind making another issue about this specific problem?

Is there not a way to make MutationObservers subtree work within a shadow element?

Unfortunately MO subtree observation stops at the boundary and doesn't traverse into the shadow roots.

Mind making another issue about this specific problem?

Sure! #3