Skip to content

fix(suspense): In nested slots suspense should return to pending state #7151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
912306d
fix(suspense): In nested slots suspense should return to pending state
Nov 16, 2022
64f0f6e
fix(suspense): In nested slots suspense should return to pending state
baiwusanyu-c Nov 16, 2022
09fbf02
Merge branch 'vuejs:main' into bwsy/fix/suspense
baiwusanyu-c Dec 2, 2022
9639517
Merge branch 'vuejs:main' into bwsy/fix/suspense
baiwusanyu-c Dec 26, 2022
7d6cd02
Merge branch 'vuejs:main' into bwsy/fix/suspense
baiwusanyu-c Jan 2, 2023
870d897
Merge branch 'vuejs:main' into bwsy/fix/suspense
baiwusanyu-c Jan 9, 2023
9f978cc
Merge branch 'vuejs:main' into bwsy/fix/suspense
baiwusanyu-c Jan 14, 2023
bea06be
Merge remote-tracking branch 'origin/main' into bwsy/fix/suspense
baiwusanyu-c Feb 4, 2023
57bc360
update unit test
baiwusanyu-c Feb 4, 2023
91d6ff3
Merge branch 'vuejs:main' into bwsy/fix/suspense
baiwusanyu-c Feb 6, 2023
4f62e96
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Feb 14, 2023
7cf2c8d
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Feb 21, 2023
93980a0
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Feb 22, 2023
d3d3d96
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Mar 17, 2023
0ac86d2
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Mar 20, 2023
5daffdb
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Mar 23, 2023
d7a8964
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Mar 27, 2023
0c0c94c
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 6, 2023
8cc3956
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 6, 2023
7a9fa44
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 10, 2023
c1f0790
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 11, 2023
63363f0
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 14, 2023
3dc6f7c
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 17, 2023
503124c
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 19, 2023
6fb208f
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c Apr 20, 2023
5bb8b71
Merge remote-tracking branch 'upstream/main' into bwsy/fix/suspense
baiwusanyu-c Apr 21, 2023
8788b36
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c May 4, 2023
9bd8708
Merge remote-tracking branch 'origin/main' into bwsy/fix/suspense
baiwusanyu-c May 9, 2023
77c4653
Merge branch 'main' into bwsy/fix/suspense
baiwusanyu-c May 16, 2023
26cddff
Merge remote-tracking branch 'origin/main' into bwsy/fix/suspense
baiwusanyu-c Nov 13, 2023
852ed00
Merge remote-tracking branch 'origin/main' into bwsy/fix/suspense
baiwusanyu-c Jan 3, 2024
faaca0b
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 3, 2024
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
51 changes: 51 additions & 0 deletions packages/runtime-core/__tests__/components/Suspense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import {
type ComponentOptions,
type ComponentPublicInstance,
Fragment,
KeepAlive,
Suspense,
Expand All @@ -16,6 +17,7 @@ import {
onUnmounted,
ref,
render,
renderSlot,
resolveDynamicComponent,
serializeInner,
shallowRef,
Expand Down Expand Up @@ -1730,6 +1732,55 @@ describe('Suspense', () => {
await Promise.all(deps)
})

// #5247
test('In nested slots suspense should return to pending state', async () => {
const id = ref('1')
const Async = defineAsyncComponent({
render() {
return h('div', `async`)
},
})
const onPending = vi.fn()
const wrapper = {
setup() {
return (ctx: ComponentPublicInstance) =>
h(
Suspense,
{ onPending },
{
default: () => [renderSlot(ctx.$slots!, 'default')],
fallback: () => h('div', 'fallback'),
},
)
},
}

const Parent = {
setup() {
return () =>
h(wrapper, null, {
default: () => h(Async, { id: id.value }),
})
},
}

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

expect(serializeInner(root)).toBe(`<div>fallback</div>`)
await Promise.all(deps)
await nextTick()
expect(serializeInner(root)).toBe(`<div id="1">async</div>`)
expect(onPending).toHaveBeenCalledTimes(1)

id.value = '2'
await nextTick()
await Promise.all(deps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await Promise.all(deps)
await Promise.all(deps)
expect(serializeInner(root)).toBe(`<div id="1">async</div>`)

await nextTick()
expect(serializeInner(root)).toBe(`<div id="2">async</div>`)
expect(onPending).toHaveBeenCalledTimes(2)
})

describe('warnings', () => {
// base function to check if a combination of slots warns or not
function baseCheckWarn(
Expand Down
9 changes: 8 additions & 1 deletion packages/runtime-core/src/components/Suspense.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Comment,
Fragment,
type VNode,
type VNodeProps,
closeBlock,
Expand Down Expand Up @@ -333,7 +334,13 @@ function patchSuspense(
}
}
} else {
if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
if (
activeBranch &&
isSameVNodeType(newBranch, activeBranch) &&
// #5247 In the nested slot, the slot will be compiled into a fragment,
// and the suspense should return to the pending state at this time
!(newBranch.type === Fragment && activeBranch.type === Fragment)
) {
// root did not change, just normal patch
patch(
activeBranch,
Expand Down