Skip to content
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

[annoyance] SPA development webserver starts twice when vite takes longer to start #770

Open
laingsimon opened this issue Feb 18, 2024 · 6 comments

Comments

@laingsimon
Copy link
Owner

laingsimon commented Feb 18, 2024

Not sure if this is caused by the SPA app within dotnet or npm start. It is also possible, with a slow start, that the browser - Chrome - refreshes the page causing the backend to relaunch the server.

Either way the npm or spa dotnet app should prevent a double launch of the dev server

If possible, it would be useful for the spa app to launch npm start in a background window

<SpaProxyServerUrl>https://localhost:44426</SpaProxyServerUrl>
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>

Nuget Package: Microsoft.AspNetCore.SpaProxy

image

image

@laingsimon laingsimon modified the milestones: v2.0.1, v2.0.2 Feb 18, 2024
@laingsimon laingsimon added the bug Something isn't working label Feb 19, 2024
@laingsimon
Copy link
Owner Author

This could be vitejs or the dotnet core spa app, difficult to tell. It doesn't happen all the time, so suspect it is related to a slower than normal launch after a fresh build or branch switch

@laingsimon laingsimon removed the bug Something isn't working label Feb 24, 2024
@laingsimon laingsimon changed the title Local webserver starts twice on occasion [annoyance] Local webserver starts twice on occasion Feb 24, 2024
@laingsimon
Copy link
Owner Author

A change to this line would allow the window to open in the background/minimised

https://github.com/dotnet/aspnetcore/blob/708f27145d0f0fbb2910e7645f9c545c36838c45/src/Middleware/Spa/SpaProxy/src/SpaProxyLaunchManager.cs#L196

@laingsimon laingsimon changed the title [annoyance] Local webserver starts twice on occasion [annoyance] Local webserver starts twice when vite slow to launch server Feb 27, 2024
@laingsimon
Copy link
Owner Author

There is some unnecessary duplication in the SPA proxy launch manager:
image

IsSpaProxyRunning can call directly onto the ProbeSpaDevelopmentServerUrl (after creating a HttpClient). The methods are identical otherwise.

@laingsimon
Copy link
Owner Author

laingsimon commented Feb 27, 2024

Suspected cause:


Note 1:
At this point the first process is orphaned, as the reference to it _spaProcess is rewritten to the details of the second process


Suggested changes:

  1. If _spaProcess is set to an instance, either:
    1. Terminate it before starting a new proxy back-end
    2. Wait for the process to exit before starting a new proxy back-end
    3. Defer to the existing process, i.e. dont create a new process
    4. Control this behaviour via a configuration switch (to retain existing behaviour if anyone requires it)
  2. Add new config settings:
    1. SubsequentStartMethod: ReLaunch (default, start another process) | Restart (kill and start another process) | WaitForFirst (trust the first process will get there eventually)
    2. WindowStyle: Normal (allow the os to position the window) | Minimized (minimize the process if the os allows it)
    3. Use this configuration to allow the proxy back-end console window to be minimised (hidden) by default

@laingsimon laingsimon changed the title [annoyance] Local webserver starts twice when vite slow to launch server [annoyance] SPA development webserver starts twice when vite takes longer to start Mar 1, 2024
@laingsimon laingsimon removed this from the v2.0.2 milestone Mar 1, 2024
@laingsimon
Copy link
Owner Author

laingsimon commented Apr 26, 2024

See changes here: dotnet/aspnetcore#55375

@laingsimon
Copy link
Owner Author

Suggestion rejected by aspnet core developers. Remaining options are to:

  • run a pre-start script
  • stop using the spaproxy (not sure what other options there are)

@laingsimon laingsimon removed the blocked label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant