-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't let a slot do anything special if it isn't in a shadow tree #459
Conversation
@surma is taking care of the PR for the tests: web-platform-tests/wpt#5705 |
DOM Standard chagne is whatwg/dom#459.
It looks we have to update existing tests in WPT too. |
This change LGTM. We only need bugs against Chrome and WebKit I suspect, since nobody else is far enough along thus far. |
Yeah, regarding Chrome, I'll take care of it. I'll also update WPT so that the test would fail if UA doesn't support this change. |
ff0fdaf
to
e943a7e
Compare
e943a7e
to
35064d2
Compare
35064d2
to
2bd8992
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dom.bs
Outdated
<var>slot</var>'s <a for=slot>assigned nodes</a> are not identical, then run | ||
<a>signal a slot change</a> for <var>slot</var>. | ||
<li><p>If <var>slotables</var> and <var>slot</var>'s <a for=slot>assigned | ||
nodes</a> are not identical, then run <a>signal a slot change</a> for <var>slot</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that this instance of "signal a slot change" has fewer checks before it than the other two. Is that correct? (I don't understand the algorithms that well so I am just pattern-matching in the hopes of finding something useful :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct and intentional.
- For assigned nodes' changes, the condition became relaxed.
- For other cases (aka fallback contents), the condition became more tight.
dom.bs
Outdated
<var>slot</var>'s <a for=slot>assigned nodes</a> are not identical, then run | ||
<a>signal a slot change</a> for <var>slot</var>. | ||
<li><p>If <var>slotables</var> and <var>slot</var>'s <a for=slot>assigned | ||
nodes</a> are not identical, then run <a>signal a slot change</a> for <var>slot</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: annevk prefers tags all on one line in his specs, so no linebreak in the middle of an <a>stuff stuff</a>
. So the whole <a for=slot>assigned nodes</a>
should get pushed to the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Let me put it in the same line.
2bd8992
to
2a0e664
Compare
@@ -1719,7 +1722,8 @@ for a given <a>slot</a> <var>slot</var>, run these steps:</p> | |||
|
|||
<ol> | |||
<li> | |||
<p>If <var>node</var> is a <a>slot</a>, then: | |||
<p>If <var>node</var> is a <a>slot</a> whose <a for=tree>root</a> is a <a for=/>shadow root</a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also updated this line, which I forgot to fix in the previous PR.
DOM Standard chagne is whatwg/dom#459.
This corresponds to the DOM Standard chagne: whatwg/dom#459. We might want to clean up tests further because this patch is the minimum effort to catch up the DOM Standard's change, but should be good enough.
This corresponds to the DOM Standard change: whatwg/dom#459. We might want to clean up tests further because this patch is rather the minimum effort to catch up the DOM Standard's change, but should be good enough.
@rniwa, could you have a chance to take a look? PR for WPT is here: web-platform-tests/wpt#5954 |
This corresponds to the DOM Standard change: whatwg/dom#459. We might want to clean up tests further because this patch is rather the minimum effort to catch up the DOM Standard's change, but should be good enough.
…nge concept Rewrite the core part of the Shadow DOM v1 distribution engine so that distribution recalculation happens *if and only if* a newly-defined concept of a slotchange actually happens. Benefits: - Performance improvement - Eliminated code complexity - Becomes spec-compliant (as a side effect, this is one of the motivations of rewriting) 1. Performance improvement: The result of PerformanceTests/ShadowDOM performance tests: v1-distribution-disconnected-and-reconnected Before CL: 201.4 ms After CL: 41.7 ms (5x times faster) 2. Eliminated code complexity: Though I have a plan to explain the detail about how the v1 distribution engine works in core/dom/shadow/README.md file, let me explain the benefits of the new design here other than the performance tests: - Eliminated false-positive for setting a dirty flag for distribution recalculation Before this CL, the engine sets a dirty flag for distribution conservatively. As a result, a false-positive can happen, which has been difficult to avoid because distribution is not a local effect. We don't have much budget of time in DOM mutation. After this CL, the engine sets a dirty flag if and only if a slotchange actually happens. No longer needs to set a dirty flag in other places. Note that the engine only detects the fact of "a slotchange happens", but it doesn't try to know an exact distributed nodes for each slot at the timing of DOM mutation so that DOM mutation should not be blocked more than necessary. Distributed nodes are lazily-calculated later. - Life cycle of slot's distribution nodes became more clear The engine no longer clears out each slot's distributed nodes in shadow-including descendant subtrees when the subtree is disconnected from the parent tree. e.g. We don't need to update distribution for a custom element which has deeply nested other custom elements inside of it at each insertion/removal from a tree. The performance test's improvement came mostly from this result. - Eliminated a lot of tricky code which is needed to support <slot> in non-shadow trees. I successfully stopped to support <slot> in non-shadow trees, and upstreamed the decision to WHATWG DOM Standard [1], getting agreement from other browser vendors [2]. I have already updated web platform tests [3] too. These tests no longer fail after this CL. The support of <slot> in non-shadow trees has been difficult to support, and has been the cause of crashes. We no longer have to fight with crashes. 3. Becomes spec-compliant (as a side effect, this is one of the motivations of rewriting) From the Web developers' perspective, this CL shouldn't have any practical impact, as long as a slot element is only used in shadow trees. The only practical visible change is: A slotchange event is always signaled as a microtask whenever a slot's distributed nodes are changed. For example, when a slot is inserted or removed from a tree, a slotchange event can be fired. Before this CL, a slotchange is never fired in this case. See DOM Standard issue [2] for details, which is rather a feature request from web developers. This CL satisfies this requirement, as an intended side effect. I am aware that it would be better to separate the engine rewriting from the user visible changes, but it would require unnecessary efforts to keep the old behavior in the new engine. Thus, I put all together. Supporting [2] is one of the reasons I decided to rewrite the engine. Note that only Shadow DOM v1 can get these benefits. Shadow DOM v0 is out of the scope of this CL. - [1] DOM Standard change: whatwg/dom#459 - [2] DOM Standard issue: whatwg/dom#447 - [3] Web platform tests change: web-platform-tests/wpt#5954 Links: Change-Id: I41f29e781185c46739377ab3939d20fa24fb69bf Reviewed-on: https://chromium-review.googlesource.com/532734 Commit-Queue: Hayato Ito <[email protected]> Reviewed-by: Takayoshi Kochi <[email protected]> Reviewed-by: Kent Tamura <[email protected]> Cr-Commit-Position: refs/heads/master@{#480013}
FYI. I implemented this new behavior in Chrome Canary. |
@rniwa, friendly ping. I am assuming that this change sounds good to all of us. |
The intention seems fine but did you check that we don't end up signaling the same slot multiple times per a single DOM change especially nested ones? I haven't gotten around to fix WebKit's implementation but I intend to do it in near future. |
That shouldn't happen, as far as my understanding is correct. A slotchange is signaled at most once per a slot per a single DOM change for any tree structures. |
I understand that's the intention but it's really hard for me to tell if that's what's gonna happen with this change or not. In general, I find it really hard to read these spec diffs and figure out what's actually happening. It would be ideal if we could look at the spec with the change applied. Is there a way to do that? |
It looks this DOM repository adds a Preview or Diff link automatically in the first comment in PR. Though Diff link looks ugly for unknown reasons (Hmm, I remember that it showed a clean diff when I updated this PR), I think Preview link still works. |
@hayatoito it looks like you need to rebase on master and force push. I suspect your change conflicts with 93db340. |
2a0e664
to
32e6669
Compare
@annevk Thanks. I have rebased on master and force push. |
Great! @rniwa you can review changes in a rendered way starting here (I think there's nothing before this point): https://s3.amazonaws.com/pr-preview/whatwg/dom/d9cd30d...hayatoito:32e6669.html#find-flattened-slotables. |
That diff link was very useful! The change looks good to me. r=me. |
dom.bs
Outdated
<var>slot</var>'s <a for=slot>assigned nodes</a> are not identical, then run | ||
<a>signal a slot change</a> for <var>slot</var>. | ||
<li><p>If <var>slotables</var> and <var>slot</var>'s <a for=slot>assigned nodes</a> are not | ||
identical, then run <a>signal a slot change</a> for <var>slot</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a space before identical? (I would do it, but I cannot modify this branch for reasons unclear.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. Done. I've updated the PR.
A slot's children are no longer considered as the slot's fallback contents if the slot is not in a shadow tree. Such a slot no longer signals a slot change even if its children are updated. This patch also removes a concept of suppress signaling flag for a slot change entirely. A slot change is always signaled when a slot's assigned nodes are changed. Fixes whatwg#447.
32e6669
to
e1db083
Compare
Due to jetlag I forgot to complete the usual checklist:
|
Thanks for merging. Regarding implementation, I could take care of Blink. I think @rniwa would take care of WebKit. |
Thanks, I'm going to assume all is in order then. |
Fixes #447.
Preview | Diff