Replies: 1 comment 13 replies
-
Little update on this one; I discovered my solution (processing the file) solved my function serialization issue, but introduced another issue (which may be the original reason the team didn't do this). When the files are processed, the css is extracted during the eval step, (I'm assuming this is a Jest order-of-operations problem), and doesn't hit the test DOM. I tried adding a custom runtime adapter but no avail - it appears the JSDOM I've worked around this (kinda) for now by Edit: I've "fixed" my issues by adding a css adapter and then injecting the css in the returned code from the transform. I'd love to see if there is any feedback from the maintenance team - I'd be happy to open a PR for a solution if there is appetite for it. |
Beta Was this translation helpful? Give feedback.
-
Hey all 👋
I've been using vanilla-extract to build an isomorphic styling library. The library exposes a theming API which has 2 adapters, 1 to vanilla-extract for static styles, and 1 to emotion for runtime styles.
I've been leveraging the function serializer (from
@vanilla-extract/css/functionSerializer
) to switch between adapters, and it works nicely! I've recently run into an issue where a project using my library and testing via Jest hits the "styles were unable to be assigned to file" issue when part of the application tries to generate (what it expects to be) runtime styles. Because the Jest transformer hasn't runprocessVanillaFile
, as far as the library knows we're still in "static mode", and vanilla-extract has a fit because the calling file isn't a.css.ts
file (fair enough).I notice that the Vite (Vitest) transformer does call
processVanillaFile
.Solving this problem is of course complicated because
processVanillaFile
is async and Jest (except for in ESM mode) needs toprocess
synchronously.Anyway, wondering if there's a reason for this, or maybe it's just an oversight? It's probably an incredibly niche, isolated problem 😅 - although I do wonder if it's related at all to some of the other issues I can see regarding Jest issues with Next?
FWIW I have implemented a rough synchronous transformer that does process vanilla files which solves my problem (but its a fair bit of copy-pasted code from VE...)
Thanks folks!
Beta Was this translation helpful? Give feedback.
All reactions