-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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(remix-dev/vite): instantiate plugins independently for child vite compiler #7990
fix(remix-dev/vite): instantiate plugins independently for child vite compiler #7990
Conversation
|
Thanks for the PR! Just a heads up that I've updated your PR since I've migrated the dev branch to the Vite 5 beta, along with a couple of small tweaks. |
This change makes a lot of sense to me. I can see that our current approach to passing plugins to the child compiler is likely to cause issues with random plugins that close over state, and those issues will surface in different ways that make it hard to diagnose or even fix. The tradeoff here is that the Remix plugin won't be usable if it's passed via inline config to the Vite JS API, but I think that's okay for now. I've added an explicit error message to communicate this limitation. Even if there's a way around this limitation, I'd rather ship your PR now as it leaves us in a better state overall. I'm happy to merge this PR as-is as long as the current test suite is passing, but feel free to add a Playwright test as a follow-up PR. |
Thanks for the review!
Good point, I haven't thought about that. It might be cool if that works, but as you say, I assume making that work is not an immediate concern. I'll think about if this can be also mitigated later.
Sounds good. I'll put this PR ready for review and will create a separate PR to add test cases with vanilla extract plugin. |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Closes: #7989
The same issue is already indicated in #7911 (comment) but this time,
@vanilla-extract/vite-plugin
is affected by the issue since it makes use ofconfig.command = "server" or "build"
to switch plugin behavior.Specifically, the plugin uses this pattern:
During
vite build
, child compiler callsconfigResolved
2nd time withconfig.command: "serve"
, so it forces parent compiler to also behave in the same way.This PR fixes this issue by loading user vite config file independently for child compiler (via
loadConfigFromFile
), which will ensure that plugin states won't be mixed between parent and child even though they still have differentconfg.command
.One issue with this approach is that it also "doubles" remix's own plugin as well, which might cause some issues (or at least negative perf impact). For example, the child compiler is going to have independent
resolvePluginConfig
cache etc... as it's used for"remix-remove-server-exports"
and"remix-react-refresh-babel"
plugins which are not removed for child compiler.Testing Strategy
This PR is tested on reproduction repository mrm007/remix-vite-vanilla-repro#1.
I'll also add a playwright test here.