Repository navigation
perf: use constructable stylesheets in native shadow - #2290
Closed
nolanlawson wants to merge 2 commits into
Closed
nolanlawson wants to merge 2 commits into
nolanlawson wants to merge 2 commits into
Conversation
This PR migrates some tests to use [Jest snapshots](https://jestjs.io/docs/snapshot-testing). This makes it easier to update these tests, as you can just run `yarn test -u` and the snapshot files update automatically. The downside of this PR is that the "expected" output files are now in Jest snapshot format rather than plaintext format. This may make it a bit harder to edit or inspect manually.
pmdartus
suggested changes
Apr 12, 2021
| return ${serializedStyle}; | ||
| } | ||
|
|
||
| function stylesheet(${HOST_SELECTOR_IDENTIFIER}, ${SHADOW_SELECTOR_IDENTIFIER}, ${SHADOW_DOM_ENABLED_IDENTIFIER}, ${HAS_ADOPTED_STYLESHEETS_IDENTIFIER}) { |
Contributor
There was a problem hiding this comment.
It would be interesting to move this into a helper in @lwc/engine-core to avoid code duplication.
Contributor
Author
There was a problem hiding this comment.
I'm not quite sure how to do that; it seems the import I add is left unmodified in the final code output. 86cd065
If you have some advice about how to do this, that would help me a lot. :)
| if (expectedSource) { | ||
| expect(result).toBe(expectedSource); | ||
|
|
||
| if (error) { |
Contributor
There was a problem hiding this comment.
Let remove this change from this PR as it is discussed in #2289.
| @@ -0,0 +1,30 @@ | |||
| import { createElement } from 'lwc'; | |||
Contributor
There was a problem hiding this comment.
This should be covered by: lwc/packages/integration-karma/test/shadow-dom/stylesheet/index.spec.js
Contributor
Author
|
Will close with a version based on #2292 |
Contributor
Author
|
Closed in favor of a new PR that's not from a fork ^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
Background:
This PR requires #2289 because the snapshots need to be updated. The relevant changes are just: 0a6dfb7
Based on a small benchmark of rendering the same element 1,000 times, with that element containing a 1,000-line CSS file (a somewhat extreme example, but good for a benchmark), the end-to-end rendering time was improved from ~380ms to ~180ms (on my MacBook Pro).
The main savings come from not needing to create a
<style>element for each component. Instead, we just append aCSSStyleSheetobject tocmp.shadowRoot.adoptedStyleSheets.I also went ahead and added an optimization for the
stylesheet()function to cache the output (which never changes in the case of native shadow), but this is less of a huge improvement unless the CSS file for the component is large (in which case the string concatenation takes a long time). But it seems sensible to do this anyway so we don't need to createCSSStyleSheetobjects over and over again, or have some kind of system for de-duping them.Does this PR introduce breaking changes?
No, it does not introduce breaking changes.The PR fulfills these requirements:
GUS work item
@W-9125079