From: Evan You Date: Tue, 2 Nov 2021 03:45:28 +0000 (+0800) Subject: fix(devtools): avoid open handle in non-browser env X-Git-Tag: v3.2.21~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6916d725a06a57e92ff9d046ccf132c305cd0a51;p=thirdparty%2Fvuejs%2Fcore.git fix(devtools): avoid open handle in non-browser env fix #4815 --- diff --git a/packages/runtime-core/src/devtools.ts b/packages/runtime-core/src/devtools.ts index 2e09a2e24a..878bb68bfe 100644 --- a/packages/runtime-core/src/devtools.ts +++ b/packages/runtime-core/src/devtools.ts @@ -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) => { @@ -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 = [] } }