-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: do not overwrite pendingReload promise (fix #5448) #5452
Conversation
fix vitejs#5448) In case of this call sequence 1. registerMissingImport 2. a new incoming request 3. registerMissingImport the request in step 2 will keep waiting indefinitely for a promise that will never resolve as step 3 overwrites the _pendingReload promise without resolving the previous one Fixes vitejs#5448
if (!server._pendingReload) { | ||
server._pendingReload = new Promise((r) => { | ||
pendingResolve = r | ||
}) | ||
} |
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.
This would fix the case where we have:
registerMissing
-> save pendingResolveAregisterMissing
rerun
... after rerun is completed -> pendingResolveA()registerMissing
-> save pendingResolveB- transformRequest waiting for pendingResolveB
If registerMissingImport
is called while rerun
is running, we would be resolving newly
registerMissing
-> save pendingResolveAregisterMissing
rerun
registerMissing
(... while rerun is completed)- transformRequest waiting for pendingResolveA
... after rerun is completed -> pendingResolveA()
Now there is a rerun
enqueued, but _pendingReload
is null. This wasn't happening before
Another thing is that if there are missing deps already, it may be better to make these requests wait for the next rerun directly. But that may be a bigger change.
Maybe on rerun
, we should save the current pendingResolve
that correspond to the currentMissing
for this run, and then nullify it. So, if there is a new registerMissing
call and we see that pendingResolve
is null, we can recreate _pendingReload
fixing the second series above
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.
Ah, I didn't realize rerun
was async so registerMissing
can be called while rerun
is being executed.
I made a new version that tries to wait for all rerun
operations to complete before resolving the promise. Not sure this is what you were looking for (or that it will work in all cases)
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.
LGTM 👍🏼
Thanks!
Description
In case of this call sequence
the request in step 2 will keep waiting indefinitely for a promise that will never resolve as step 3 overwrites the _pendingReload promise without resolving the previous one
Fixes #5448
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).