-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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: add a timeout to the res.sep when discovering new dependency #2548
fix: add a timeout to the res.sep when discovering new dependency #2548
Conversation
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Anything else you see that needs attention prior to merging this @yyx990803 or @antfu? |
// If the refresh has not happened after timeout, Vite considers | ||
// something unexpected has happened. In this case, Vite | ||
// returns an empty response that will error. | ||
setTimeout(() => { |
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.
question: I may be wrong here, but currently the code reads like it always waits statically 5000ms
and then respond with a 408
.
What makes that it could respond earlier?
Maybe I just misinterpret the issue and just reading the code here
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.
@Shinigami92 You are absolutely right to ask.
This branch of code is reached when a dependency needs a complete refresh of the page.
Even if the query never responds, the page is going to be refreshed and the query forgotten.
Chronologically:
- Browser asks for a dependency that is not yet optimized
- Server looks for it and starts optimization
- We reach line 57 of this file
- The server finishes optimizing the new dependency
- Server sends a WebSocket message to the browser to refresh
- Optimization process resolves the promise on line 57/58
- Here is the change in this PR:
- Before this PR, an empty response was given to the browser before it could refresh. This triggered the error mentioned in the ticket
- After this PR: If the browser has not refreshed the page after 5 seconds we just drop the request
I hope this chronology clarifies the situation.
To avoid returning an erroring file to import in the browser, I choose to wait 5 seconds before returning.
It gives the browser the time it needs to refresh, instead of responding so that request with an invalid empty MIME response.
If the page fails to reload, after 5s the empty invalid response is still sent.
closes #2525