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

Inconvenient typing of 'server' in 'middlewareMode' and 'hmr' #17627

Closed
7 tasks done
emilefokkema opened this issue Jul 7, 2024 · 1 comment · Fixed by #17628
Closed
7 tasks done

Inconvenient typing of 'server' in 'middlewareMode' and 'hmr' #17627

emilefokkema opened this issue Jul 7, 2024 · 1 comment · Fixed by #17628

Comments

@emilefokkema
Copy link
Contributor

Describe the bug

server in the user config option called middlewareMode and server in the hmr options are typed as http.Server. But because the httpServer belonging to the ViteDevServer is typed as something less restrictive, ViteDevServer's own httpServer cannot be used as server in the middlewareMode or hmr options for another vite config. This seems unnecessary, especially since doing so anyway (despite TypeScript's protests) still results in a working config.

I intend to submit a PR for this issue.

Reproduction

https://github.com/emilefokkema/vite-server-type-reproduction

Steps to reproduce

Run npm install followed by npm run typecheck

System Info

System:
    OS: macOS 13.5.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.43 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
    pnpm: 9.4.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 16.6
  npmPackages:
    vite: ^5.3.3 => 5.3.3

Used Package Manager

npm

Logs

No response

Validations

@busticated
Copy link

busticated commented Jul 11, 2024

found my way here while trying to disable hmr entirely1 b/c whenever i stop the local server, my app sits there polling [vite] server connection lost. Polling for restart... which yields a whole pile of net::ERR_CONNECTION_REFUSED that eventually renders my browser unresponsive 💀👎

i'm currently importing the CommonServerOptions (source) and using that to placate typescript:

const server: CommonServerOptions = {
    host,
    port,
    strictPort: true,
    open: true,
};

...but of course the CommonServerOptions type somehow doesn't include the hmr field 🤦

so, yeah, having a clear and easy way to type server options would be very much appreciated 🙏

Footnotes

  1. Ultimately hmr: false didn't help, the described polling behavior remained unchanged. setting watch: null also didn't help 😭

@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants