Skip to content

Commit 6916d72

Browse files
committed
fix(devtools): avoid open handle in non-browser env
fix #4815
1 parent 6b32f0d commit 6916d72

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/runtime-core/src/devtools.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
4949
devtools.enabled = true
5050
buffer.forEach(({ event, args }) => devtools.emit(event, ...args))
5151
buffer = []
52-
} else {
52+
} else if (
53+
// handle late devtools injection - only do this if we are in an actual
54+
// browser environment to avoid the timer handle stalling test runner exit
55+
// (#4815)
56+
// eslint-disable-next-line no-restricted-globals
57+
typeof window !== 'undefined' &&
58+
!navigator.userAgent.includes('jsdom')
59+
) {
5360
const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
5461
target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [])
5562
replay.push((newHook: DevtoolsHook) => {
@@ -59,10 +66,15 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
5966
// at all, and keeping the buffer will cause memory leaks (#4738)
6067
setTimeout(() => {
6168
if (!devtools) {
69+
target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null
6270
devtoolsNotInstalled = true
6371
buffer = []
6472
}
6573
}, 3000)
74+
} else {
75+
// non-browser env, assume not installed
76+
devtoolsNotInstalled = true
77+
buffer = []
6678
}
6779
}
6880

0 commit comments

Comments
 (0)