fix: resovedUrls is null after server restart#14890
Conversation
|
|
bluwy
left a comment
There was a problem hiding this comment.
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.resolvedUrlswas used here, but after the PR it was changed toserver.resolvedUrlshere.The problem is that when restarting, we keep the prev server instance and replace its guts with the new server here
The
newServerfunctions still refer internally to the new instance. In thelistenfunction, we doThis happens after the
Object.assignso it only gets set innewServer.This PR fixes the issue with a new internal function to swap the internal
servervariable in the new server so functions start to refer to it.An alternative could be to use
thison 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
closewe were settingresolvedUrlstonull, 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?