Eptagone / Vite.AspNetCore

Small library to integrate Vite into ASP.NET projects
MIT License
243 stars 34 forks source link

Middleware always waits for 5 seconds for the first request even though Vite dev server is already ready #78

Closed fh-yuxiao-zeng closed 8 months ago

fh-yuxiao-zeng commented 9 months ago

Describe the bug I noticed that the middleware has a bug that it always waits for 5 seconds for the first request, even though the Vite dev server is already ready.

To Reproduce Steps to reproduce the behavior:

  1. Start the dev server manually in a separate terminal and keep it running
  2. Start the asp.net core app
  3. Fire a request and look at logs

Expected behavior The request should be handled immediately because the dev server is already running.

Actual behavior The log says this:

info: Vite.AspNetCore.Services.ViteServerLaunchManager[0]
      Looks like the Vite development server is already running at http://localhost:44436.
warn: Vite.AspNetCore.Services.ViteDevMiddleware[0]
      The Vite development server did not start within 5 seconds

And the request is delayed for 5 seconds until the warning log is shown.

Additional context The implementation is here: https://github.com/Eptagone/Vite.AspNetCore/blob/main/src/Vite.AspNetCore/Services/ViteDevMiddleware.cs#L100

Looking at the implementation, it tries to check if _waitForDevServer becomes false. However, there is no code changing the value (until timeout), so the first request is always delayed for the full timeout.

Eptagone commented 8 months ago

Hi, it's fixed now with 4a2a47a31e6cdf471ab25f4f442ece3dca277941

fh-yuxiao-zeng commented 8 months ago

Thank you!