Skip to content

Commit b07fa60

Browse files
authored
fix(runtime-vapor): prevent fragment updated hooks from running before the fragment is mounted. (#14123)
1 parent e0ac500 commit b07fa60

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

packages/runtime-vapor/src/apiCreateFor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ export const createFor = (
403403
oldBlocks = []
404404
}
405405

406-
if (frag.updated) frag.updated.forEach(m => m())
406+
if (isMounted && frag.updated) frag.updated.forEach(m => m())
407407
setActiveSub(prevSub)
408408
}
409409

packages/runtime-vapor/src/fragment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ export class DynamicFragment extends VaporFragment {
191191

192192
if (parent) {
193193
insert(this.nodes, parent, this.anchor)
194-
if (this.updated) {
194+
// anchor isConnected indicates the this render is updated
195+
if (this.anchor.isConnected && this.updated) {
195196
this.updated.forEach(hook => hook(this.nodes))
196197
}
197198
}

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ function createVDOMComponent(
383383
}
384384

385385
frag.nodes = vnode.el as any
386-
if (frag.updated) frag.updated.forEach(m => m())
386+
if (isMounted && frag.updated) frag.updated.forEach(m => m())
387387
}
388388

389389
frag.remove = unmount
@@ -450,7 +450,7 @@ function renderVDOMSlot(
450450
}
451451
}
452452

453-
if (frag.updated) frag.updated.forEach(m => m())
453+
if (isMounted && frag.updated) frag.updated.forEach(m => m())
454454
}
455455

456456
const render = (parentNode?: ParentNode, anchor?: Node | null) => {

0 commit comments

Comments
 (0)