Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit ae36b1a

Browse files
refactor(runtime-core): prevent users from manually calling lifecycle hook function (#8731)
1 parent a498b4e commit ae36b1a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/runtime-core/src/apiLifecycle.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ export function injectHook(
6868

6969
export const createHook =
7070
<T extends Function = () => any>(lifecycle: LifecycleHooks) =>
71-
(hook: T, target: ComponentInternalInstance | null = currentInstance) =>
71+
(hook: T, target: ComponentInternalInstance | null = currentInstance) => {
7272
// post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
73-
(!isInSSRComponentSetup || lifecycle === LifecycleHooks.SERVER_PREFETCH) &&
74-
injectHook(lifecycle, (...args: unknown[]) => hook(...args), target)
73+
if (
74+
!isInSSRComponentSetup ||
75+
lifecycle === LifecycleHooks.SERVER_PREFETCH
76+
) {
77+
injectHook(lifecycle, (...args: unknown[]) => hook(...args), target)
78+
}
79+
}
7580

7681
export const onBeforeMount = createHook(LifecycleHooks.BEFORE_MOUNT)
7782
export const onMounted = createHook(LifecycleHooks.MOUNTED)

0 commit comments

Comments
 (0)