Skip to content

Commit cda50ea

Browse files
committed
refactor(runtime-core): move updateCompnent into separate function
1 parent 2fb0add commit cda50ea

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

packages/runtime-core/src/renderer.ts

+40-32
Original file line numberDiff line numberDiff line change
@@ -968,38 +968,7 @@ function baseCreateRenderer(
968968
)
969969
}
970970
} else {
971-
const instance = (n2.component = n1.component)!
972-
973-
if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
974-
if (
975-
__FEATURE_SUSPENSE__ &&
976-
instance.asyncDep &&
977-
!instance.asyncResolved
978-
) {
979-
// async & still pending - just update props and slots
980-
// since the component's reactive effect for render isn't set-up yet
981-
if (__DEV__) {
982-
pushWarningContext(n2)
983-
}
984-
updateComponentPreRender(instance, n2, optimized)
985-
if (__DEV__) {
986-
popWarningContext()
987-
}
988-
return
989-
} else {
990-
// normal update
991-
instance.next = n2
992-
// in case the child component is also queued, remove it to avoid
993-
// double updating the same child component in the same flush.
994-
invalidateJob(instance.update)
995-
// instance.update is the reactive effect runner.
996-
instance.update()
997-
}
998-
} else {
999-
// no update needed. just copy over properties
1000-
n2.component = n1.component
1001-
n2.el = n1.el
1002-
}
971+
updateComponent(n1, n2, parentComponent, optimized)
1003972
}
1004973
}
1005974

@@ -1077,6 +1046,45 @@ function baseCreateRenderer(
10771046
}
10781047
}
10791048

1049+
const updateComponent = (
1050+
n1: VNode,
1051+
n2: VNode,
1052+
parentComponent: ComponentInternalInstance | null,
1053+
optimized: boolean
1054+
) => {
1055+
const instance = (n2.component = n1.component)!
1056+
if (shouldUpdateComponent(n1, n2, parentComponent, optimized)) {
1057+
if (
1058+
__FEATURE_SUSPENSE__ &&
1059+
instance.asyncDep &&
1060+
!instance.asyncResolved
1061+
) {
1062+
// async & still pending - just update props and slots
1063+
// since the component's reactive effect for render isn't set-up yet
1064+
if (__DEV__) {
1065+
pushWarningContext(n2)
1066+
}
1067+
updateComponentPreRender(instance, n2, optimized)
1068+
if (__DEV__) {
1069+
popWarningContext()
1070+
}
1071+
return
1072+
} else {
1073+
// normal update
1074+
instance.next = n2
1075+
// in case the child component is also queued, remove it to avoid
1076+
// double updating the same child component in the same flush.
1077+
invalidateJob(instance.update)
1078+
// instance.update is the reactive effect runner.
1079+
instance.update()
1080+
}
1081+
} else {
1082+
// no update needed. just copy over properties
1083+
n2.component = n1.component
1084+
n2.el = n1.el
1085+
}
1086+
}
1087+
10801088
const setupRenderEffect: SetupRenderEffectFn = (
10811089
instance,
10821090
initialVNode,

0 commit comments

Comments
 (0)