Skip to content

Commit

Permalink
FIX an issue when re-rendering lit-html elements after rendering a no…
Browse files Browse the repository at this point in the history
…n-lit-html element

It seems the mountNode becomes stateful after a render has occurred in lit-html.
Since storybook is changing the dom beyond lit-html, it gets "confused" and throws an error because it's unable to remove
some nodes. I guess it's trying to do reconciliation or cleanup, and it's missing state or it's state is inconsistent
with the actual dom.

By adding a extra inner root node that gets reset when switching stories we make lit-html mount correctly
  • Loading branch information
ndelangen committed Mar 5, 2019
1 parent 3176058 commit 661481a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/polymer/src/client/preview/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { document } from 'global';
import { stripIndents } from 'common-tags';
import { html, render, TemplateResult } from 'lit-html';
import { render, TemplateResult } from 'lit-html';

const rootElement = document.getElementById('root');

Expand Down Expand Up @@ -33,9 +33,13 @@ export default function renderMain({
// Since we reuse `rootElement` for all stories, remove the stored instance first.
// But forceRender means that it's the same story, so we want too keep the state in that case.
if (!forceRender) {
render(html``, rootElement);
rootElement.innerHTML = '<div id="root-inner"></div>';
} else if (!rootElement.querySelector('[id="root-inner"]')) {
rootElement.innerHTML = '<div id="root-inner"></div>';
}
render(element, rootElement);
const renderTo = rootElement.querySelector('[id="root-inner"]');

render(element, renderTo);
} else {
rootElement.innerHTML = '';
rootElement.appendChild(element);
Expand Down

1 comment on commit 661481a

@vercel
Copy link

@vercel vercel bot commented on 661481a Mar 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

Builds rate limit exceeded (0 of 100 remaining). Try again in 23h

Please sign in to comment.