Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

[ShadowDOM]: Filtered insertion points inside nested roots fail to distribute based on dom changes #316

Closed
sorvell opened this issue May 23, 2015 · 11 comments
Assignees

Comments

@sorvell
Copy link
Contributor

sorvell commented May 23, 2015

Here's a repro: http://jsbin.com/naboya/1/edit.

Clicking the Test button toggles an attribute on the #test node and should cause it to toggle between the insertion points contained in its parent's shadowRoot. This fails.

Clicking the Test2 button removes/adds the #test node. This appears to function correctly.

There's a clue in the fact that an incorrect distribution caused by clicking Test can be corrected by clicking Test2 2x to remove and re-add the node.

After some debugging, it appears that the renderer found for the x-host element does not properly report that it should invalidate based on the foo and bar attributes changing on children. Strangely, the x-outer element renderer does report that it should invalidate on foo and bar which is also incorrect .

@jmesserly
Copy link
Contributor

fascinating. taking a look at it ... seems very mysterious

@jmesserly
Copy link
Contributor

well, that was easy with your notes to start from! I think this is the fix:

diff --git a/src/ShadowDOM/ShadowRenderer.js b/src/ShadowDOM/ShadowRenderer.js
index cd3d22e..ace0b82 100644
--- a/src/ShadowDOM/ShadowRenderer.js
+++ b/src/ShadowDOM/ShadowRenderer.js
@@ -340,9 +340,10 @@
         var shadowTrees = getShadowTrees(shadowHost);

         // 1.2
+        var renderer = getRendererForHost(shadowHost);
         for (var i = 0; i < shadowTrees.length; i++) {
           // 1.2.1
-          this.poolDistribution(shadowTrees[i], pool);
+          renderer.poolDistribution(shadowTrees[i], pool);
         }

         // 1.3

tellingly, the one other place we check isShadowHost and mutate a field on renderer:

      if (isShadowHost(node)) {
        var renderer = getRendererForHost(node);
        renderer.dirty = false;
      }

In contrast, attributes were breaking the invariant that the current ShadowRenderer matches the host.

working on a test case, but that's probably the fix.

@jmesserly
Copy link
Contributor

oops, and I should've noticed this was assigned. Sorry @garlicnation !

if you want to take this up and land it, feel free. Otherwise I was going to adapt @sorvell 's test case to be standalone (just setting up the shadow roots and such) so we can add to tests/ShadowDOM/...

@jmesserly
Copy link
Contributor

But the fix above does seem to fix the problem without breaking any of the existing SD tests (tried chrome/safari/firefox).

@sorvell sorvell assigned jmesserly and unassigned garlicnation May 28, 2015
@sorvell
Copy link
Contributor Author

sorvell commented May 28, 2015

Pretty sure @garlicnation hasn't had a chance to look. Re-assigned so @jmesserly can get full credit!

@jmesserly
Copy link
Contributor

update: either something's wrong with my test or I seem to have found another problem (not sure if related). Digging ...

@jmesserly
Copy link
Contributor

It seems unrelated, even rolling back my fix shows some really busted behavior in the test. After setting things up like your jsbin, ShadowDOM's innerHTML reports (newlines mine):

<x-host id="host">
<child foo="">~Foo~</child>
<child foo="" bar="">~Foo+Bar~</child>
<child id="test" bar="">~Bar~</child>
</x-host>
<br>

Looks good right? Now after rendering (with or without a fix for the attribute issue):

<x-host id="host">
<child foo="">~Foo~</child>
<child foo="" bar="">~Foo+Bar~</child>
] Bar: [
<content select="[bar]"></content>
]
</x-host>
<br>

that's like totally busted. Strangely, the visual HTML tree is correct, but SD's internal tracking seems sufficiently off it can't re-render properly. It looks like the (virtual) nextSibling pointer from the Foo+Bar got set incorrectly (well, didn't get set, therefore falls back to the visual HTML nextSibling which is wrong). Going to need to dig more. I didn't see any of this in my manual HTML testing. Then again, the test environment uses detached DOM trees and forces rendering, so it can sometimes be a bit different.

@jmesserly
Copy link
Contributor

Wow, figured it out. On a hunch, I added whitespace nodes where they would usually be inside the <template> (after each <child> tag) and the second bug goes away. So, we might have some obscure breakage with ShadowDOM polyfill if the HTML is missing whitespace between distributed elements. Anyway, other than tripping on that unrelated issue, the fix and test works. I'll file another bug for that issue, and send out a pull request that fixes this one

jmesserly pushed a commit that referenced this issue May 29, 2015
@sorvell
Copy link
Contributor Author

sorvell commented May 29, 2015

u rox... thx!

jmesserly pushed a commit that referenced this issue Jun 22, 2015
…ateAttrs

fixes #316, attribute deps were not recorded on the correct ShadowRenderer
sorvell pushed a commit that referenced this issue Jul 8, 2015
…n the correct ShadowRenderer"

This reverts commit 1be8240.
@sorvell
Copy link
Contributor Author

sorvell commented Jul 8, 2015

Reverted via f94ca5e.

This change broke some Polymer tests (https://github.com/Polymer/polymer/blob/master/test/unit/polymer-dom.js#L101 which can be run via https://github.com/Polymer/polymer/blob/master/test/unit/polymer-dom-shadow.html). It's not clear why this change broke these tests, but they also make changes to attributes to affect distribution.

@jmesserly would you mind taking a look?

@sorvell sorvell reopened this Jul 8, 2015
@TimvdLippe
Copy link
Contributor

I don't think this is an issue any longer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants