Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hydrate): support style modes in hydrate modules #5953

Merged
merged 8 commits into from
Aug 30, 2024

Conversation

christian-bromann
Copy link
Member

What is the current behavior?

If a Stencil component uses Style Modes they currently aren't recognised in the hydrate module, e.g. calling renderToString would render the component without any styles. The problem is that Rollup generates a variable scope for the global runtime and the one for the hydrate module which causes modeResolutionChain to be defined twice in the bundle. When calling setMode, it would add a mode to the modeResolutionChain variables defined outside of the hydrate scope, leaving the one inside the hydrate module empty and hence not applying the styles to the component.

What is the new behavior?

I tweaked the rollup config to essentially remove all modeResolutionChain definitions in the bundle and inject on at the beginning of the bundle by uncommenting a statement within the HYDRATE_FACTORY_INTRO. Furthermore I added a mode option to the SerializeDocumentOptions interface to allow setting modes per e.g. renderToString call.

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

Added an e2e test for this.

Other information

n/a

Copy link
Member

@tanner-reits tanner-reits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to go once we get rid of the of the magic strings (i.e. const modeResolutionChain = []; and var modeResolutionChain = [];)

@christian-bromann
Copy link
Member Author

@tanner-reits thanks for the review, applied changes as suggested.

@christian-bromann christian-bromann merged commit 15f3b26 into main Aug 30, 2024
88 checks passed
@christian-bromann christian-bromann deleted the cb/mode-support-in-hydrate-module branch August 30, 2024 16:09
@christian-bromann
Copy link
Member Author

Released in Stencil v4.22.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants