Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions packages/runtime-core/__tests__/components/Suspense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2395,4 +2395,67 @@ describe('Suspense', () => {
expect(unmounted).toHaveBeenCalledTimes(1)
})
})

// #14173
test('renders multiple async components in Suspense with v-for and updates list order with HOC', async () => {
const CompAsyncSetup = defineAsyncComponent({
props: ['item'],
render(ctx: any) {
return h('div', ctx.item.name)
},
})

const CompWrapper = {
props: ['item'],
render(ctx: any) {
return h(CompAsyncSetup, { item: ctx.item })
},
}

const items = ref([
{ id: 1, name: '111' },
{ id: 2, name: '222' },
{ id: 3, name: '333' },
])

const Comp = {
setup() {
return () =>
h(Suspense, null, {
default: () =>
h('div', [
h(
Fragment,
null,
items.value.map(item =>
h(CompWrapper, { item, key: item.id }),
),
),
]),
})
},
}

const root = nodeOps.createElement('div')
render(h(Comp), root)

await nextTick()
await Promise.all(deps)

expect(serializeInner(root)).toBe(
`<div><div>111</div><div>222</div><div>333</div></div>`,
)

items.value = [
{ id: 4, name: '444' },
{ id: 5, name: '555' },
{ id: 6, name: '666' },
]

await nextTick()
await Promise.all(deps)
expect(serializeInner(root)).toBe(
`<div><div>444</div><div>555</div><div>666</div></div>`,
)
})
})
12 changes: 11 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,9 @@ function baseCreateRenderer(
const anchor =
nextIndex + 1 < l2
? // #13559, fallback to el placeholder for unresolved async component
anchorVNode.el || anchorVNode.placeholder
anchorVNode.el ||
anchorVNode.placeholder ||
getSubTreeElement(anchorVNode)
: parentAnchor
if (newIndexToOldIndexMap[i] === 0) {
// mount new
Expand Down Expand Up @@ -2418,6 +2420,14 @@ function baseCreateRenderer(
)
}

const getSubTreeElement = (vnode: VNode): RendererNode | null => {
let current = vnode
while (current.component) {
current = current.component.subTree
}
return current.el || current.placeholder
}

return {
render,
hydrate,
Expand Down
Loading