From: 远方os Date: Mon, 27 May 2024 09:07:38 +0000 (+0800) Subject: refactor(runtime-core): prevent users from manually calling lifecycle hook function... X-Git-Tag: v3.4.28~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae36b1a6642f59a218311c902d82c9c18eb3061d;p=thirdparty%2Fvuejs%2Fcore.git refactor(runtime-core): prevent users from manually calling lifecycle hook function (#8731) --- diff --git a/packages/runtime-core/src/apiLifecycle.ts b/packages/runtime-core/src/apiLifecycle.ts index 741d43ec45..cfaf7636e9 100644 --- a/packages/runtime-core/src/apiLifecycle.ts +++ b/packages/runtime-core/src/apiLifecycle.ts @@ -68,10 +68,15 @@ export function injectHook( export const createHook = any>(lifecycle: LifecycleHooks) => - (hook: T, target: ComponentInternalInstance | null = currentInstance) => + (hook: T, target: ComponentInternalInstance | null = currentInstance) => { // post-create lifecycle registrations are noops during SSR (except for serverPrefetch) - (!isInSSRComponentSetup || lifecycle === LifecycleHooks.SERVER_PREFETCH) && - injectHook(lifecycle, (...args: unknown[]) => hook(...args), target) + if ( + !isInSSRComponentSetup || + lifecycle === LifecycleHooks.SERVER_PREFETCH + ) { + injectHook(lifecycle, (...args: unknown[]) => hook(...args), target) + } + } export const onBeforeMount = createHook(LifecycleHooks.BEFORE_MOUNT) export const onMounted = createHook(LifecycleHooks.MOUNTED)