Skip to content

Commit 31d1467

Browse files
authored
fix(client): protect against window being defined but addEv undefined (#20359)
1 parent 5ab25e7 commit 31d1467

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/vite/src/client/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const transport = normalizeModuleRunnerTransport(
105105

106106
let willUnload = false
107107
if (typeof window !== 'undefined') {
108-
window.addEventListener('beforeunload', () => {
108+
// window can be misleadingly defined in a worker if using define (see #19307)
109+
window.addEventListener?.('beforeunload', () => {
109110
willUnload = true
110111
})
111112
}

0 commit comments

Comments
 (0)