Skip to content
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

Ensure template given to ShadyCSS is the one rendered by lit-html #502

Merged
merged 4 commits into from
Sep 13, 2018

Conversation

sorvell
Copy link
Member

@sorvell sorvell commented Sep 13, 2018

This ensures ShadyCSS can update the style in the template that will be rendered by lit-html. ShadyCSS needs to do this, for example, when the set of properties needed in any @apply changes.

Fixes lit/lit-element#117

Steven Orvell added 2 commits September 13, 2018 10:07
This ensures ShadyCSS can update the style in the template that will be rendered by lit-html. ShadyCSS needs to do this, for example, when the set of properties changes in any `@apply`'s.

Fixes lit/lit-element#117
shadyRenderSet.add(scopeName);
// Move styles out of rendered DOM and store.
const styleFragment = document.createDocumentFragment();
Array.from(fragment.querySelectorAll('style')).forEach((s: Element) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd use a for loop... not a lot of reason to allocate the array.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

});
// Remove styles from nested templates in this scope and put them
// into the "root" template passed in as `template`.
removeStylesFromLitTemplates(scopeName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this be renamed to be more clear that it's moving styles?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is named correctly, but the comment is for the next two lines. Moved the comments to make more clear.

// Remove styles from nested templates in this scope and put them
// into the "root" template passed in as `template`.
removeStylesFromLitTemplates(scopeName);
insertNodeIntoTemplate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the big change here? I'm having a little bit of a hard time seeing the change in behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment. Yes, the key bit is that we hand ShadyCSS a template that will actually be rendered by lit-html. This way it can update the style inside it and affect subsequent lit-html renderings.

@sorvell
Copy link
Member Author

sorvell commented Sep 13, 2018

@justinfagnani PTAL

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

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

Thanks for the updated comments!

@justinfagnani justinfagnani merged commit 18deb6b into master Sep 13, 2018
@justinfagnani justinfagnani deleted the fix-apply branch September 13, 2018 19:31
neuronetio pushed a commit to neuronetio/lit-html that referenced this pull request Dec 2, 2019
…t#502)

This ensures ShadyCSS can update the style in the template that will be rendered by lit-html. ShadyCSS needs to do this, for example, when the set of properties changes in any `@apply`'s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants