-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: keep track of ssr version of imported modules separately #11973
fix: keep track of ssr version of imported modules separately #11973
Conversation
4044f11
to
c299a3d
Compare
If you've had a chance to review, is there any feedback or blockers that should be addressed before landing this? @patak-dev @bluwy @sapphi-red |
Would be really nice to get your attention on this. Hopefully the issue description, and the test case provide enough context wrt the problem |
Thanks for the PR! |
c7dfd63
to
d11a3fa
Compare
@sapphi-red rebased 👍 |
d11a3fa
to
9821cb9
Compare
I noticed that changes introduced in #12599 render my test case invalid, so I had to "de-optimize" the browser module import by switching to dynamic import instead: https://github.com/vitejs/vite/compare/d11a3fa38cbf2372b42e23e48e055865c0205fbb..9821cb946a79b0d15fed3afd37468bf9a4380b0c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we should merge this one. It may affect some projects though. We can do now an ecosystem-ci run, but there are a few projects red on main right now: https://github.com/vitejs/vite-ecosystem-ci/actions/runs/4571757840
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Rakkas failing after this PR is new compared to main. @cyco130 would you check that splitting |
@patak-dev thanks for the heads up. I just pushed a fix, can you rerun the CI? |
/ecosystem-ci run rakkas |
Thanks @cyco130! Would you explain how this change affected you for refence? |
During dev, Vite normally loads an imported CSS file a bit late, causing FOUC until the JavaScript is evaluated. Rakkas scans the module graph to see what CSS files will be needed and injects the styles into the HTML in advance. After this PR, So I switched to |
Thanks for the explanation @cyco130. I realize many frameworks including SvelteKit and Astro does this too, and locally it has caused a failure for Astro for me. This seems a bit breaking than expected 🤔 We might still be able to write off as a bug fix, but we should probably ping the ecosystem first, or maybe find a workaround. |
Just an idea: Have all three: |
I think I'll fix this in Astro for now. It looks like SvelteKit and Nuxt are conscious that |
This discussion inspired this: #12678 |
I'm starting to lean towards waiting at least until the next minor to merge this PR. We should give some time to the ecosystem to react. It would also be good to have a bit more time to check the implications of this change. I think this is good given the current design, but it is starting to show that maybe mixing the two graphs under the same structure isn't the best long-term. |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Hey @shYkiSto! Sorry it is taking a bit long to merge this one. We discussed the PR in a team meeting and decided we would like to avoid the breaking change. So what we're thinking is to add two new sets:
And then keep the current For reference, we also discussed the possibility of splitting the current module graph into |
@patak-dev, sure thing! I'll try to get this updated sometime next week 👍 |
ea14ebf
724142a
to
ea14ebf
Compare
ea14ebf
to
a60bd7f
Compare
@patak-dev, this should be ready for review. I've also noticed that the regression test I added has been somewhat flaky in CI, not sure if we should merge it as-is, or perhaps we'll be better off without it? Let me know in case you have any recommendation on how to make it more reliable
Also, is this something you'd like to reconsider to include in the next minor release? I believe this change does not introduce any breaking changes anymore? |
@shYkiSto, yes, let's merge this in Vite 4.4. You could add |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
a60bd7f
to
18e5808
Compare
18e5808
to
6a1eac0
Compare
Description
Patch
moduleGraph
so it keeps separate lists of imported modules for browser (client) vs. server (SSR) version of a module. This fixes a scenario, where modules may use different sets of imports on browser vs. server (e.g., isomorphic modules, where Node.js (server) dependencies get stripped out from the browser version by running it trough some build-time transform). In which case Vite would fail to recognize and properly propagate the updates in server-only modules that always results in stale code running on the server (or, vice verse), because the module graph may get corrupted as a result of removing importers that are "no longer there", but in fact may still be imported in the counterpart version.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).