Describe the bug
I run my vite app in dev mode, close the vite server and then my app enters an infinite loop that crash the navigator tab.
This is caused by vite forward console plugin. Sending an error produces another error, as the transport can't be successfully made. Hence the infinite loop.
Technical details
setupForwardConsoleHandler registers window.addEventListener("unhandledrejection", ...) which calls sendError() → transport.send(). When the WebSocket disconnects (e.g. server restart), transport.send() rejects with "send was called before connect" (thrown by normalizeModuleRunnerTransport). That unhandled rejection is immediately caught by the same unhandledrejection listener, which calls sendError() again, creating an infinite loop of errors that floods the browser console.
The root cause is in packages/vite/src/shared/forwardConsole.ts:
function sendError(type: 'error' | 'unhandled-rejection', error: any) {
transport.send({ // ← rejects when disconnected, no .catch()
type: 'custom',
event: 'vite:forward-console',
data: { type, data: { name: error?.name, message: error?.message, stack: error?.stack } },
})
}
window.addEventListener('unhandledrejection', (event) => {
sendError('unhandled-rejection', event.reason) // ← catches its own rejection → infinite loop
})
Possible fix
Add a .catch(() => {}) to transport.send() inside sendError (and optionally sendLog) to silently drop forwarding failures when the transport is disconnected:
function sendError(type: 'error' | 'unhandled-rejection', error: any) {
transport.send({
type: 'custom',
event: 'vite:forward-console',
data: {
type,
data: {
name: error?.name || 'Unknown Error',
message: error?.message || String(error),
stack: error?.stack,
},
},
}).catch(() => {
// Silently ignore send failures (e.g. WebSocket disconnected).
// Throwing here would re-trigger the unhandledrejection listener
// and cause an infinite loop.
})
}
Reproduction
https://stackblitz.com/edit/vitejs-vite-vuqsmzfx
Steps to reproduce
npm install && npm run dev
- Open the browser, open DevTools console
- Close vite server
- Any error that fires during the disconnection window triggers the infinite loop. Click the button
- The browser console floods with repeated:
Uncaught (in promise) Error: send was called before connect
at Object.send (client:384:15)
at sendError (client:480:13)
at client:519:4
System Info
System:
OS: macOS 26.2
CPU: (10) arm64 Apple M5
Memory: 111.39 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.11.1 - /Users/jgonzalez.alvarez/.asdf/installs/ivm-node/24.11.1/bin/node
npm: 11.6.2 - /Users/jgonzalez.alvarez/.asdf/installs/ivm-node/24.11.1/bin/npm
pnpm: 10.33.0 - /Users/jgonzalez.alvarez/Library/pnpm/pnpm
bun: 1.3.10 - /Users/jgonzalez.alvarez/.bun/bin/bun
Browsers:
Chrome: 147.0.7727.139
Firefox: 147.0.4
Safari: 26.2
Used Package Manager
pnpm
Logs
No response
Validations
Describe the bug
I run my vite app in dev mode, close the vite server and then my app enters an infinite loop that crash the navigator tab.
This is caused by vite forward console plugin. Sending an error produces another error, as the transport can't be successfully made. Hence the infinite loop.
Technical details
setupForwardConsoleHandlerregisterswindow.addEventListener("unhandledrejection", ...)which callssendError()→transport.send(). When the WebSocket disconnects (e.g. server restart),transport.send()rejects with"send was called before connect"(thrown bynormalizeModuleRunnerTransport). That unhandled rejection is immediately caught by the sameunhandledrejectionlistener, which callssendError()again, creating an infinite loop of errors that floods the browser console.The root cause is in
packages/vite/src/shared/forwardConsole.ts:Possible fix
Add a
.catch(() => {})totransport.send()insidesendError(and optionallysendLog) to silently drop forwarding failures when the transport is disconnected:Reproduction
https://stackblitz.com/edit/vitejs-vite-vuqsmzfx
Steps to reproduce
npm install && npm run devSystem Info
System: OS: macOS 26.2 CPU: (10) arm64 Apple M5 Memory: 111.39 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.11.1 - /Users/jgonzalez.alvarez/.asdf/installs/ivm-node/24.11.1/bin/node npm: 11.6.2 - /Users/jgonzalez.alvarez/.asdf/installs/ivm-node/24.11.1/bin/npm pnpm: 10.33.0 - /Users/jgonzalez.alvarez/Library/pnpm/pnpm bun: 1.3.10 - /Users/jgonzalez.alvarez/.bun/bin/bun Browsers: Chrome: 147.0.7727.139 Firefox: 147.0.4 Safari: 26.2Used Package Manager
pnpm
Logs
No response
Validations