Skip to content

Commit c8cd0e9

Browse files
committed
chore: improve code
1 parent 695a02f commit c8cd0e9

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

packages/runtime-core/src/hydration.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ComponentInternalInstance } from './component'
1515
import { invokeDirectiveHook } from './directives'
1616
import { warn } from './warning'
1717
import { PatchFlags, ShapeFlags, isReservedProp, isOn } from '@vue/shared'
18-
import { RendererInternals } from './renderer'
18+
import { needTransition, RendererInternals } from './renderer'
1919
import { setRef } from './rendererTemplateRef'
2020
import {
2121
SuspenseImpl,
@@ -374,11 +374,10 @@ export function createHydrationFunctions(
374374
let needCallTransitionHooks = false
375375
if (isTemplateNode(el)) {
376376
needCallTransitionHooks =
377-
(!parentSuspense ||
378-
(parentSuspense && !parentSuspense.pendingBranch)) &&
379-
transition &&
380-
!transition.persisted &&
381-
parentComponent?.vnode.props?.appear
377+
needTransition(parentSuspense, transition) &&
378+
parentComponent &&
379+
parentComponent.vnode.props &&
380+
parentComponent.vnode.props.appear
382381

383382
const content = (el as HTMLTemplateElement).content
384383
.firstChild as Element

packages/runtime-core/src/renderer.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { initFeatureFlags } from './featureFlags'
7272
import { isAsyncWrapper } from './apiAsyncComponent'
7373
import { isCompatEnabled } from './compat/compatConfig'
7474
import { DeprecationTypes } from './compat/compatConfig'
75+
import { TransitionHooks } from './components/BaseTransition'
7576

7677
export interface Renderer<HostElement = RendererElement> {
7778
render: RootRenderFunction<HostElement>
@@ -701,10 +702,7 @@ function baseCreateRenderer(
701702
}
702703
// #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
703704
// #1689 For inside suspense + suspense resolved case, just call it
704-
const needCallTransitionHooks =
705-
(!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
706-
transition &&
707-
!transition.persisted
705+
const needCallTransitionHooks = needTransition(parentSuspense, transition)
708706
if (needCallTransitionHooks) {
709707
transition!.beforeEnter(el)
710708
}
@@ -2365,6 +2363,17 @@ function toggleRecurse(
23652363
effect.allowRecurse = update.allowRecurse = allowed
23662364
}
23672365

2366+
export function needTransition(
2367+
parentSuspense: SuspenseBoundary | null,
2368+
transition: TransitionHooks | null
2369+
) {
2370+
return (
2371+
(!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
2372+
transition &&
2373+
!transition.persisted
2374+
)
2375+
}
2376+
23682377
/**
23692378
* #1156
23702379
* When a component is HMR-enabled, we need to make sure that all static nodes

0 commit comments

Comments
 (0)