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
feat: skip soft invalidation error when timestamp mismatch #15768
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Sounds good to me. I'll let @bluwy have the opportunity to check this one too as he was implementing the soft invalidation logic. Maybe we could remove these two lines after this PR: vite/packages/vite/src/node/server/transformRequest.ts Lines 397 to 398 in 8f5cdc8
That could save some invalidations when the result is not actually used:
|
Note: Windows is failing in every PR, ignore that |
I remember intentionally not resetting the Currently our code contains this: vite/packages/vite/src/node/server/transformRequest.ts Lines 466 to 469 in 734a9e3
Which implies that we only update the result if the module had not been invalidated. But if it hasn't invalidated, shouldn't Could the culprit here be the difference between
I can take a deeper look in the repro too later tonight. I can understand that this PR is probably the quicker fix, and we can do that if it's urgent though. |
Here is how UnoCSS invalidates itself: In Nuxt, I tried to patch Vite to log more, here is what I got (without this PR): |
Thanks! I guess my hunch is incorrect then, but the issue now looks even stranger.
Trying to think of the scenarios, but I still can't wrap my head around how this issue hits. I don't quite get the problem yet, but as another proposal fix, maybe we can skip the error if |
Honestly, to me, it's also a bit hard to debug as there are several moving parts together. In Nuxt we have SSR and two Vite servers, not entirely sure why this would occur. But from what I am logging, I see (oh by the way, in the unocss reproduction, the error only occurs on first hard-refresh, not sure if it help with the context). I wonder if we could just remove this hard throw? vite/packages/vite/src/node/server/transformRequest.ts Lines 403 to 407 in 8f5cdc8
I guess it was for defensive programming? But with our transform logics to be quite many segments of async chunks, I feel it's hard to guarantee the two states won't co-exist. |
I'm pretty sure there's no way the two states can co-exist from what I can try to think of. Unless something external is mutating Vite's module nodes, e.g. manually assigning The error is indeed defensive programming though (I mentioned the reason in the last paragraph here). If the error happens, then something unusual is going on, and it implies that "the module has existing I'm ok with skipping the error only if the (EDIT: Ah yeah I can see the issue now with a hard refresh, let me take a closer look 😄) |
I don't think either Nuxt or UnoCSS manipulates I tried to log it a bit more, if I put: The track trace suggest it's triggered by these lines: vite/packages/vite/src/node/server/transformRequest.ts Lines 364 to 367 in 734a9e3
I also tried skipping the error with |
invalidationState
on updateModuleTransformResult
Updated the PR implementation |
The current code seems to be calling the error if I checked the repro and understand the issue better now. On the request that was assigning vite/packages/vite/src/node/server/transformRequest.ts Lines 141 to 147 in 775bb50
vite/packages/vite/src/node/server/transformRequest.ts Lines 283 to 284 in 775bb50
The This is interesting because it revealed a potential path we can optimize. After we resolve the id here: vite/packages/vite/src/node/server/transformRequest.ts Lines 161 to 163 in 775bb50
The module may already exists in the module graph and had been soft invalidated, so we only need to handle the soft invalidation instead of going through the whole load+transform phase. Basically, we can copy the above "memory" handling but instead of I could try to implement this and see if it helps |
I'll close this for now since #15785 should fix it. Thanks for kicking this off! |
Description
This check will be hit on a racing condition that invalidates module
invalidateModule
being called while the project is still warming up:vite/packages/vite/src/node/server/transformRequest.ts
Lines 403 to 407 in 8f5cdc8
This happens on UnoCSS because UnoCSS has a virtual module,
uno.css
, that serves to generate CSS based on the scanned source code. Meaning that it will self-invalidate whenever a new module is scanned (via thetransform
hook). In that case, it could cause the entry module (that importsuno.css
into a soft invalidate state before its transforming process finishes).Linked Issue: fix unocss/unocss#3472
This PR fixes the racing condition by resetting the
InvalidationState
state on the newtransformResult
set.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).