Skip to content

Commit

Permalink
fix(devtools): avoid open handle in non-browser env
Browse files Browse the repository at this point in the history
fix #4815
  • Loading branch information
yyx990803 committed Nov 2, 2021
1 parent 6b32f0d commit 6916d72
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/runtime-core/src/devtools.ts
Expand Up @@ -49,7 +49,14 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
devtools.enabled = true
buffer.forEach(({ event, args }) => devtools.emit(event, ...args))
buffer = []
} else {
} else if (
// handle late devtools injection - only do this if we are in an actual
// browser environment to avoid the timer handle stalling test runner exit
// (#4815)
// eslint-disable-next-line no-restricted-globals
typeof window !== 'undefined' &&
!navigator.userAgent.includes('jsdom')
) {
const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [])
replay.push((newHook: DevtoolsHook) => {
Expand All @@ -59,10 +66,15 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
// at all, and keeping the buffer will cause memory leaks (#4738)
setTimeout(() => {
if (!devtools) {
target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null
devtoolsNotInstalled = true
buffer = []
}
}, 3000)
} else {
// non-browser env, assume not installed
devtoolsNotInstalled = true
buffer = []
}
}

Expand Down

0 comments on commit 6916d72

Please sign in to comment.