Skip to content

Commit 0fb2278

Browse files
committed
refactor: simplify fragment update logic by removing isUpdate variable and directly using parent for conditional checks.
1 parent bfeb2d9 commit 0fb2278

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/runtime-vapor/src/fragment.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ export class DynamicFragment extends VaporFragment {
175175
transition: VaporTransitionHooks | undefined,
176176
parent: ParentNode | null,
177177
) {
178-
// anchor isConnected indicates the this is an update render
179-
const isUpdate = !!(this.anchor && this.anchor.isConnected)
180178
if (render) {
181179
// try to reuse the kept-alive scope
182180
const scope = this.getScope && this.getScope(this.current)
@@ -188,16 +186,17 @@ export class DynamicFragment extends VaporFragment {
188186

189187
// switch current instance to parent instance during update
190188
let prev
191-
if (this.parentComponent && isUpdate)
189+
if (this.parentComponent && parent)
192190
prev = setCurrentInstance(this.parentComponent)
193191
this.nodes = this.scope.run(render) || []
194-
if (this.parentComponent && isUpdate) setCurrentInstance(...prev!)
192+
if (this.parentComponent && parent) setCurrentInstance(...prev!)
195193

196194
if (transition) {
197195
this.$transition = applyTransitionHooks(this.nodes, transition)
198196
}
199197

200198
// fallthrough attrs
199+
// TODO: check if component root
201200
if (
202201
this.parentComponent &&
203202
(this.parentComponent as VaporComponentInstance)!.hasFallthrough &&
@@ -220,7 +219,7 @@ export class DynamicFragment extends VaporFragment {
220219

221220
if (parent) {
222221
insert(this.nodes, parent, this.anchor)
223-
if (isUpdate && this.updated) {
222+
if (this.updated) {
224223
this.updated.forEach(hook => hook(this.nodes))
225224
}
226225
}

0 commit comments

Comments
 (0)