wip(ssr): reduce reactivity overhead during ssr

This commit is contained in:
Evan You
2020-01-24 11:39:52 -05:00
parent cee36ad028
commit 25a0d4a65f
7 changed files with 50 additions and 21 deletions

View File

@@ -65,7 +65,8 @@ export function injectHook(
export const createHook = <T extends Function = () => any>(
lifecycle: LifecycleHooks
) => (hook: T, target: ComponentInternalInstance | null = currentInstance) =>
injectHook(lifecycle, hook, target)
// post-create lifecycle registrations are noops during SSR
!__SSR__ && injectHook(lifecycle, hook, target)
export const onBeforeMount = createHook(LifecycleHooks.BEFORE_MOUNT)
export const onMounted = createHook(LifecycleHooks.MOUNTED)
@@ -87,6 +88,10 @@ export type ErrorCapturedHook = (
instance: ComponentPublicInstance | null,
info: string
) => boolean | void
export const onErrorCaptured = createHook<ErrorCapturedHook>(
LifecycleHooks.ERROR_CAPTURED
)
export const onErrorCaptured = (
hook: ErrorCapturedHook,
target: ComponentInternalInstance | null = currentInstance
) => {
injectHook(LifecycleHooks.ERROR_CAPTURED, hook, target)
}