-
-
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: resovedUrls is null after server restart #14890
Conversation
Run & review this pull request in StackBlitz Codeflow. |
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.
Nice fix. One small nit below, but otherwise I think this is also a better fix for now instead of this
. Seems like it'll only matter for properties that are re-assigned.
I found that this patch might be useful on fixing a buggy behavior long existed in Vite v4's dev server running in middleware mode, and hoped that this patch could be backported. Suppose that I create a server in middleware mode with However there is a catch: All new methods have By making the server object swappable, which this patch implements and is merged in v5, I may be able to workaround the above-mentioned issue. Would you mind backporting this patch to v4? I can help on making a separate issue. |
Description
Fixes a regression introduced by:
To reproduce, start a dev server, change the config, and see that server URLs are re-printed even if they haven't changed. This was reported at #14418 (comment)
newServer.resolvedUrls
was used here, but after the PR it was changed toserver.resolvedUrls
here.The problem is that when restarting, we keep the prev server instance and replace its guts with the new server here
The
newServer
functions still refer internally to the new instance. In thelisten
function, we doThis happens after the
Object.assign
so it only gets set innewServer
.This PR fixes the issue with a new internal function to swap the internal
server
variable in the new server so functions start to refer to it.An alternative could be to use
this
on functions. It will mean that server functions are no longer binded. I think this could be ok as we don't document this anywhere, but it is a big change.This PR may fix other issues, for example, at
close
we were settingresolvedUrls
tonull
, this never affected the proper server after a restart. There could be other similar cases for other server properties.What is the purpose of this pull request?