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
Vanilla Extract adds an additional Identifier to classes to ensure it's safe for use in selectors. This gets stripped when unused.
In some cases this is only stripped from client code and remains in server code, resulting in a mismatch between server and client, also known as a hydration error.
When composed styles are used in selectors, they are assigned an additional class if required so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors. - v1.4.0
Details
When creating a style composed of other styles, (either by passing an array to style or calling a Sprinkles function in a css file) Vanilla Extract will create an additional identifier class.
If the class is unused, the class will appear in the server render, but will be stripped for the client render, resulting in a mismatch between renders known as a hydration error.
This only occurs when:
emitCssInSsr is not true
A style is defined as a composition of other styles. (Or, a Sprinkles function called in a css.ts file)
The resulting value must be exported, and NOT used in another selector
Though Sprinkles has been mentioned here, the demonstration below reveals this occurs without Sprinkles. It's just that your more likely to be in this scenario if you are using atomic styles.
Attempted Workarounds / Solutions
As mentioned setting emitCssInSsr to true did solve my issue, and may be a more preferable configuration anyway.
Perhaps it would make sense to default emitCssInSsr to true?
This is not isolated to emitCssInSsr=false and can be recreate with emitCssInSsr=true, though it's more difficult.
This can happen in both directions: Either the additional style being stripped from the client and not the server, or being stripped from the server and not the client.
I can, very inconsistently, recreate the behaviour in both directions when I queue a request the server render immediately after starting the server.
When I wait for the dev server to start up it doesn't occur.
This leads me to believe:
When the server and client are trying to create the styles there is a race condition as to whether the styles will be stripped before they are used.
I've not added the above update into the simplified solution. I believe this is due to the small size of the project makes it hard to trigger the race condition before it's ready.
Describe the bug
Vanilla Extract adds an additional Identifier to classes to ensure it's safe for use in selectors. This gets stripped when unused.
In some cases this is only stripped from client code and remains in server code, resulting in a mismatch between server and client, also known as a hydration error.
Details
When creating a style composed of other styles, (either by passing an array to style or calling a Sprinkles function in a css file) Vanilla Extract will create an additional identifier class.
If the class is unused, the class will appear in the server render, but will be stripped for the client render, resulting in a mismatch between renders known as a hydration error.
This only occurs when:
emitCssInSsr
is not trueThough Sprinkles has been mentioned here, the demonstration below reveals this occurs without Sprinkles. It's just that your more likely to be in this scenario if you are using atomic styles.
Attempted Workarounds / Solutions
As mentioned setting
emitCssInSsr
to true did solve my issue, and may be a more preferable configuration anyway.emitCssInSsr
totrue
?If not, I suspect the result of this code path:
https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts#L163 calling
@vanilla-extract/integration
'sprocessVanillaFile
is the key differentiator.This may be related to #654 which has a similar error, but has quite a different scenario.
Reproduction
https://github.com/jahredhope/ve-sprinkles-in-styles-bug
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: