Skip to content

Commit f0f6f7c

Browse files
committed
fix(Suspense): fix edge case of Suspense being patched during async HOC child remount
1 parent ebd78d2 commit f0f6f7c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

packages/runtime-core/__tests__/components/Suspense.spec.ts

+40
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,46 @@ describe('Suspense', () => {
16901690
expect(serializeInner(root)).toBe(`<div>sync</div>`)
16911691
})
16921692

1693+
// #6416 follow up
1694+
test('Suspense patched during HOC async component re-mount', async () => {
1695+
const key = ref('k')
1696+
const data = ref('data')
1697+
1698+
const Async = defineAsyncComponent({
1699+
render() {
1700+
return h('div', 'async')
1701+
}
1702+
})
1703+
1704+
const Comp = {
1705+
render() {
1706+
return h(Async, { key: key.value })
1707+
}
1708+
}
1709+
1710+
const root = nodeOps.createElement('div')
1711+
const App = {
1712+
render() {
1713+
return h(Suspense, null, {
1714+
default: h(Comp, { data: data.value })
1715+
})
1716+
}
1717+
}
1718+
render(h(App), root)
1719+
expect(serializeInner(root)).toBe(`<!---->`)
1720+
1721+
await Promise.all(deps)
1722+
1723+
// async mounted, but key change causing a new async comp to be loaded
1724+
key.value = 'k1'
1725+
await nextTick()
1726+
1727+
// patch the Suspense
1728+
// should not throw error due to Suspense vnode.el being null
1729+
data.value = 'data2'
1730+
await Promise.all(deps)
1731+
})
1732+
16931733
describe('warnings', () => {
16941734
// base function to check if a combination of slots warns or not
16951735
function baseCheckWarn(

packages/runtime-core/src/componentRenderUtils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ export function updateHOCHostEl(
428428
{ vnode, parent }: ComponentInternalInstance,
429429
el: typeof vnode.el // HostNode
430430
) {
431+
if (!el) return
431432
while (parent) {
432433
const root = parent.subTree
433434
if (root.suspense && root.suspense.activeBranch === vnode) {

0 commit comments

Comments
 (0)