You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: allow the use of a stylesheet as adoptedStylesheets in component libraries #1967
Current behaviour: Context: I'm working on a web component library.
Stencil allow the inclusion of globalStyles in the stencil.config.ts, which then is included in the dist after compilation. While this stylesheet is useful, a very common need in component libraries would be to be able to set some rules globally for all components (think fonts, reset.css, box-sizing: border-box, etc.).
Right now, the way to do it would be either to:
manually include the global stylesheet in all components of the library, which means that all components will now include the stylesheet itself which in turn can cause a very quick augmentation of the bundle size.
manually configure a Constructable Stylesheet system, in order to make all your components adopt the stylesheet.
The second option seems better, and I feel that Stencil could handle this at build time instead of letting the developers implement a custom solution 😄
Reacted by Lee, Chris Ramshaw, RickDangerous13, Lasse Rosenow, Ahmed Radjdi, Michael Romer, Neal Borelli, Arvind, Neal Borelli, Kazzix and 6 more
@christophsaile thanks for nudging on this issue. I've updated the label for it which slots it into our bucket of community features we consider to include in future roadmaps. Please subscribe to this issue to receive updates.
I changed company kinda recently and haven't seen your message until today 😅
Basically we haven't worked on it as there were other prios, and as we had decided to drop support for ShadowDOM for accessibility reasons this feature lost a bit of its purpose to us.
Still, I think being able to declare an adoptedStylesheet for a component library would be very useful 🙂
Reacted by Christian Bromann, Christoph Saile and michaelrgalloway
@JMDidon some good news: we are planning to add this to our 2025 roadmap. Can you help us understand your desired solution a bit better and be more clear about how applying this feature would look like? How would some enhance the e.g. Stencil config to apply this?
Are you suggesting that the contents of the css file that is set in the globalStyle configuration is beeing applied as adoptedStylesheet to the shadow DOM of each Stencil component?
Our team would also like this, we generate a set of classes using Tailwind which also initializes a set of css variables, currently this works but it is duplicated across components which makes them bloaty. If we could use a single stylesheet and adopt it to the shadowRoot of components, sharing the single constructable stylesheet, this would not only reduce the bloat and payload, but it will also allow us to modify/add/delete rules at runtime and have all component styles be reflected of such updates.
Activity
christophsaile commentedon Apr 3, 2024
Hey, are there any plans to include this feature? @JMDidon did you manage to implement a custom soltuion that you can share?:)
christian-bromann commentedon Apr 3, 2024
@christophsaile thanks for nudging on this issue. I've updated the label for it which slots it into our bucket of community features we consider to include in future roadmaps. Please subscribe to this issue to receive updates.
JMDidon commentedon Apr 30, 2024
Hey @christophsaile!
I changed company kinda recently and haven't seen your message until today 😅
Basically we haven't worked on it as there were other prios, and as we had decided to drop support for ShadowDOM for accessibility reasons this feature lost a bit of its purpose to us.
Still, I think being able to declare an
adoptedStylesheetfor a component library would be very useful 🙂christian-bromann commentedon Jan 21, 2025
@JMDidon some good news: we are planning to add this to our 2025 roadmap. Can you help us understand your desired solution a bit better and be more clear about how applying this feature would look like? How would some enhance the e.g. Stencil config to apply this?
Are you suggesting that the contents of the css file that is set in the
globalStyleconfiguration is beeing applied asadoptedStylesheetto the shadow DOM of each Stencil component?michaelrgalloway commentedon Mar 28, 2025
Our team would also like this, we generate a set of classes using Tailwind which also initializes a set of css variables, currently this works but it is duplicated across components which makes them bloaty. If we could use a single stylesheet and adopt it to the shadowRoot of components, sharing the single constructable stylesheet, this would not only reduce the bloat and payload, but it will also allow us to modify/add/delete rules at runtime and have all component styles be reflected of such updates.
christian-bromann commentedon May 30, 2025
@michaelrgalloway @christophsaile
A dev release was made: @stencil/[email protected]
Docs PR was raised: stenciljs/site#1526
A preview is available at: https://stencil-docs-git-cb-constructable-stylesheet-docs-ionic1.vercel.app/docs/next/styling#constructable-stylesheets
Please test the feature out and let us know what you think. We plan to publish it as new minor version next week.