feat(global-styles): add global styles support to shadow DOM components#6268
Merged
christian-bromann merged 9 commits intomainfrom May 30, 2025
Merged
Conversation
- Create new createShadowRoot utility function that applies global styles via adoptedStyleSheets - Update build system to handle @app-globals imports across all platforms (client, hydrate, testing) - Extend BuildCtx.stylesPromise to return compiled global styles string instead of void - Replace duplicate shadow root creation code with shared utility across runtime files - Add globalStyles export to app-globals module for CSS injection into shadow roots - Update app-data-plugin to include global styles in the bundle generation process This enables global styles to be automatically applied to all shadow DOM components while maintaining encapsulation and performance benefits of constructable stylesheets.
Member
Author
|
Docs PR was raised: stenciljs/site#1526 @dgonzalezr mind testing the dev release? |
2 tasks
2 tasks
3 tasks
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.
What is the current behavior?
Currently, Stencil has duplicate shadow root creation logic scattered across multiple runtime files (
bootstrap-lazy.ts,bootstrap-custom-element.ts, andproxy-host-element.ts). Each location manually callsattachShadow()with conditional logic fordelegatesFocussupport.Additionally, there is no mechanism to apply global styles to shadow DOM components. While Stencil supports global styles for non-shadow components, shadow DOM components remain isolated from these styles, creating inconsistencies in styling across component types.
The existing global styles infrastructure exists but is only used for generating output files - it's not integrated into the runtime for shadow DOM components.
fixes #1967
What is the new behavior?
This PR introduces comprehensive global styles support for shadow DOM components by:
🎨 Global Styles Integration
adoptedStyleSheets🔧 Code Consolidation
createShadowRoot()utility function insrc/utils/shadow-root.ts🏗️ Build System Enhancements
globalStylesalongside existingglobalScriptsBuildCtx.stylesPromisenow returns the compiled styles string📦 Bundle Generation
config.globalStyleis definedTechnical Implementation Details
New Utility Function
Build Process Integration
@app-globalsmodule@app-globalsDoes this introduce a breaking change?
This is a purely additive feature that enhances existing functionality without breaking current behavior:
globalStyleis configured in the Stencil config