perf(engine-core): render separate style tags #2870
Merged
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
This is a stop-gap solution to #2851.
When we render components with shared stylesheets, the browser can optimize those stylesheets under the hood if the
<style>s are byte-for-byte identical. (I don't have a benchmark handy, but just trust me that browsers do this. 🙂)Right now we concatenate a component's styles into a single
<style>, including any shared stylesheets. So the browser cannot optimize, because the duplicated styles are embedded inside of separate<style>s that are not byte-for-byte identical.This PR optimizes the engine so that it emits separate
<style>s instead. The ordering is maintained, so that effectively you end up with the same styles being applied.Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
A component may have more than one
<style>node now. If component authors are trying to detect this (e.g. by usingthis.template.firstChildto get the<style>, or doing[...this.template.children].slice(1)to get everything but the first<style>element), then this PR will break them.In practice though, developers already have to worry about the case of browsers that support constructable stylesheets versus those that don't. And on-platform, native shadow has not reached widespread adoption yet. So ideally this will not break anyone.
If developers really need to separate
<style>from non-<style>tags, their best bet is:Gus WI
W-11256353