Shadow DOM handled by document.l10n on mutation, but not on creation
Categories
(Core :: XUL, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox76 | --- | fixed |
People
(Reporter: Pike, Assigned: zbraniecki)
References
Details
Attachments
(1 file, 1 obsolete file)
When using Fluent in shadow DOM, we add shadowRoot
as explicit root to a DOMLocalization
, but when manipulating the shadow DOM, the mutation observers fire on document.l10n
.
This is sadly inconsistent.
We're looking at using shadow DOM to isolate remote settings l10n from the regular document.l10n
in bug 1616280, and that doesn't work out alright.
smaug, it seems that https://searchfox.org/mozilla-central/source/dom/l10n/L10nMutations.cpp is rather generous at listening to mutations, and doesn't care about the roots in the corresponding DOMLocalization
?
Would it be feasible to make that content check if the content is part of its roots?
Assignee | ||
Updated•5 years ago
|
Comment 1•5 years ago
|
||
What content check?
I feel like I'm missing some context here.
Updated•5 years ago
|
Assignee | ||
Comment 2•5 years ago
|
||
Andreio - can you provide a minimized testcase analogous to https://searchfox.org/mozilla-central/source/dom/l10n/tests/mochitest/dom_localization/test_connectRoot_webcomponent.html of the issue you're facing?
It'll make it easier for us to reproduce it and fix.
Comment 3•5 years ago
|
||
The component has been changed since the backlog priority was decided, so we're resetting it.
For more information, please visit auto_nag documentation.
Reporter | ||
Comment 4•5 years ago
|
||
In this test, I don't connectRoot the shadow dom, but the
localization from document.l10n is applied via a mutation observer
on setAttributes.
Also note that it's not the localization that we call setAttributes
on.
Reporter | ||
Comment 5•5 years ago
|
||
The observer methods check for elem->IsInComposedDoc()
, which is OK if there's only one document.l10n
involved, and everything with data-l10n-id
is hooked up.
These checks would need to be extended to walk up their parents and see if the hit a root in mDOMLocalization?
smaug, does this testcase help to see what we were trying to do?
Comment 6•5 years ago
|
||
But there is // document.domLoc.connectRoot(this.shadowRoot);
Why is that?
Reporter | ||
Comment 7•5 years ago
|
||
I left the commented-out connectRoot in just to hightlight where the original test connected the root to it's non-default DOMLocalization
object.
Just to clarify, I don't think this one test is an exhaustive test coverage, it's just one example. Which I understood to be what Zibi asked for in comment 2.
Comment 8•5 years ago
|
||
I'm still puzzled what this bug is about.
https://searchfox.org/mozilla-central/rev/96f1457323cc598a36f5701f8e67aedaf97acfcf/dom/l10n/DOMLocalization.cpp#85,105
observes mutations in the subtree under aNode. But I guess that works as expected? And initial translation doesn't happen? So do you mean that when ConnectRoot is called, some localization should happen? But isn't translateFragment for that case. or translateRoots.
I don't know what "Would it be feasible to make that content check if the content is part of its roots?" means.
Reporter | ||
Comment 9•5 years ago
|
||
The expected behavior is for this element to be not localized, w/out explicitly hooking it up to a DOMLocalization.
Once explicitly hooked up, the expectation is that it's handled by that DOMLocalization, and to not have different DOMLocalizations fight over what wins.
Comment 10•5 years ago
|
||
ok, still a bit unclear to me.
Do you perhaps mean that L10nMutations shouldn't do anything with nodes which aren't in its subtree?
(That happens because of https://searchfox.org/mozilla-central/rev/96f1457323cc598a36f5701f8e67aedaf97acfcf/dom/base/MutationObservers.cpp#84-88)
If so, the methods implementing nsIMutationObserver methods could check if modified node is contained within some root.
(that could be rather slow if there are lots of roots). One could of course be on L10nMutations per root, but that might be slow too if there are tons of them - but if we don't expect too many roots, that might be doable. Then L10nMutations could have a pointer to the relevant root.
Reporter | ||
Comment 11•5 years ago
|
||
Right.
Also, the root checker could drop if it crosses from shadow to non-shadow DOM?
As for the number of roots, I can see DOMLocalizations for things like panel objects to be quite extensive. OTH, shadow DOMs are probably pretty shallow, and you if you stop at the shadow-non-shadow bridge, you'd stop rather early.
Assignee | ||
Comment 12•5 years ago
|
||
I'll take a look at this. I'm concerned it'll lead to more code being increasingly broken when trying to fix it, so better now than later.
Assignee | ||
Comment 13•5 years ago
|
||
Assignee | ||
Comment 14•5 years ago
|
||
Olli - can you check if the patch looks reasonable? I'm going to work on improving the tests (need to add coverage of adding elements) and will check how the performance looks like, but wanted to run it through you first.
Overall, I feel like it should be mostly ok for smaller cases, but I'm a bit concerned that for big documents like browser.xhtml or preferences.xhtml, traversing nodes up for every element to check if it's in the document will cost.
In reality, I'd probably want to just check if the element is in <template/>
and only then verify if it is in roots, otherwise it must be since it got mutation observed called on it. Is that right?
Assignee | ||
Comment 15•5 years ago
|
||
Alternatively, maybe we could extend the internal MutationObserver to not report mutations on nodes that aren't in its subtree?
Comment 16•5 years ago
|
||
That might be useful for some other cases, but requires quite some changes, and might slow down DOM mutations in general, since the whole
nsIMutationObserver system would need to track which node is possible slotted in shadow DOM etc.
Assignee | ||
Comment 17•5 years ago
|
||
Does it mean you recommend it over the patch that I wrote? Or do you think the patch is a reasonable short term approach and we can investigate the feature for MutationObserver separately?
Assignee | ||
Comment 20•5 years ago
|
||
Assignee | ||
Comment 21•5 years ago
|
||
Comment 22•5 years ago
|
||
Comment 23•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Description
•