salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 392 forks source link

Insert global stylesheets into document.adoptedStyleSheets #2922

Open nolanlawson opened 2 years ago

nolanlawson commented 2 years ago

We currently cannot insert styles to document.adoptedStyleSheets, because for backwards compatibility we need to continue appending global stylesheets as <style>s to the document.head.

However, there is some data showing that document.adoptedStyleSheets is a performance win (#2683 #2460), and it's cleaner in our code to just use one system both at the global level and at the local (shadow root) level, so it would be beneficial to use document.adoptedStyleSheets.

nolanlawson commented 2 years ago

Well #2923 actually showed there's a slight perf improvement for using <style>s in Chrome anyway, so this may need to be re-evaluated in the future. It makes no sense to me that the ceremony of creating a DOM node just to add a style actually improves perf relative to constructable stylesheets, but maybe Chrome has optimized one case more than the other.

git2gus[bot] commented 2 months ago

This issue has been linked to a new work item: W-16535766