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
I wanted to share a peculiar gotcha I've discovered: using styleVariants inside a recipe (or anywhere that's not the top level of a file) is totally possible, but can lead to unexpected results.
This might be counter-intuitive, but can be explained by the fact that vanilla-extract generates CSS in order of TypeScript evaluation, and styleVariants will actually be evaluated before recipe gets called.
Do you have any other similar examples you've faced where v-e didn't behave like you'd expect, due to its architectural constrains? Perhaps custom ESLint rules could help here.
Finally, I wonder whether it's possible to overcome this limitation within vanilla-extract (without having to parse TypeScript's AST).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I wanted to share a peculiar gotcha I've discovered: using
styleVariants
inside a recipe (or anywhere that's not the top level of a file) is totally possible, but can lead to unexpected results.Consider the following code:
The two recipes seem to be functionally equivalent: both provide a style with green background color, and and ability to override it.
However,
styleWithVariants
will produce unexpected results: using variants will not work, the color will always be green.See this Codesandbox.
This might be counter-intuitive, but can be explained by the fact that vanilla-extract generates CSS in order of TypeScript evaluation, and
styleVariants
will actually be evaluated beforerecipe
gets called.Do you have any other similar examples you've faced where v-e didn't behave like you'd expect, due to its architectural constrains? Perhaps custom ESLint rules could help here.
Finally, I wonder whether it's possible to overcome this limitation within vanilla-extract (without having to parse TypeScript's AST).
Beta Was this translation helpful? Give feedback.
All reactions