]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-core): prevent users from manually calling lifecycle hook function...
author远方os <yangpanteng@gmail.com>
Mon, 27 May 2024 09:07:38 +0000 (17:07 +0800)
committerGitHub <noreply@github.com>
Mon, 27 May 2024 09:07:38 +0000 (17:07 +0800)
packages/runtime-core/src/apiLifecycle.ts

index 741d43ec45c5d2c2d1ad08a2cc244608ded2878e..cfaf7636e9a223f08320fa441229d5f1f584f1d8 100644 (file)
@@ -68,10 +68,15 @@ export function injectHook(
 
 export const createHook =
   <T extends Function = () => 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)