From d2e2a192efe803d6f76d41ef5c77736e9a901a9a Mon Sep 17 00:00:00 2001 From: yangchangtao Date: Thu, 20 Mar 2025 20:09:21 +0800 Subject: [PATCH 1/2] fix(suspence): fix newBranch shapeFlag not reset under hmr --- packages/runtime-core/src/components/Suspense.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/components/Suspense.ts b/packages/runtime-core/src/components/Suspense.ts index 85001f500cf..0109d77c3f2 100644 --- a/packages/runtime-core/src/components/Suspense.ts +++ b/packages/runtime-core/src/components/Suspense.ts @@ -235,7 +235,7 @@ function patchSuspense( const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense if (pendingBranch) { suspense.pendingBranch = newBranch - if (isSameVNodeType(newBranch, pendingBranch)) { + if (isSameVNodeType(pendingBranch, newBranch)) { // same root type but content may have changed. patch( pendingBranch, @@ -321,7 +321,7 @@ function patchSuspense( ) setActiveBranch(suspense, newFallback) } - } else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) { + } else if (activeBranch && isSameVNodeType(activeBranch, newBranch)) { // toggled "back" to current active branch patch( activeBranch, @@ -355,7 +355,7 @@ function patchSuspense( } } } else { - if (activeBranch && isSameVNodeType(newBranch, activeBranch)) { + if (activeBranch && isSameVNodeType(activeBranch, newBranch)) { // root did not change, just normal patch patch( activeBranch, From 4e5e0b4d49b1699a85bd3caa21c7beae36b4dbc2 Mon Sep 17 00:00:00 2001 From: yangxiuxiu1115 <1974364190@qq.com> Date: Fri, 21 Mar 2025 00:24:20 +0800 Subject: [PATCH 2/2] chore: add test case --- packages/runtime-core/__tests__/hmr.spec.ts | 52 +++++++++++++++++++ .../src/components/BaseTransition.ts | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/hmr.spec.ts b/packages/runtime-core/__tests__/hmr.spec.ts index 3f157d009a9..2831293f557 100644 --- a/packages/runtime-core/__tests__/hmr.spec.ts +++ b/packages/runtime-core/__tests__/hmr.spec.ts @@ -894,4 +894,56 @@ describe('hot module replacement', () => { await timeout() expect(serializeInner(root)).toBe('
bar
') }) + + test('multi reload child wrapped in Suspense + KeepAlive', async () => { + const id = 'test-child-reload-3' + const Child: ComponentOptions = { + __hmrId: id, + setup() { + const count = ref(0) + return { count } + }, + render: compileToFunction(`
{{ count }}
`), + } + createRecord(id, Child) + + const appId = 'test-app-id' + const App: ComponentOptions = { + __hmrId: appId, + components: { Child }, + render: compileToFunction(` + + + + + + `), + } + + const root = nodeOps.createElement('div') + render(h(App), root) + expect(serializeInner(root)).toBe('
0
') + await timeout() + reload(id, { + __hmrId: id, + setup() { + const count = ref(1) + return { count } + }, + render: compileToFunction(`
{{ count }}
`), + }) + await timeout() + expect(serializeInner(root)).toBe('
1
') + + reload(id, { + __hmrId: id, + setup() { + const count = ref(2) + return { count } + }, + render: compileToFunction(`
{{ count }}
`), + }) + await timeout() + expect(serializeInner(root)).toBe('
2
') + }) }) diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index 2b58bc3fc43..03552a2b78d 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -204,7 +204,7 @@ const BaseTransitionImpl: ComponentOptions = { if ( oldInnerChild && oldInnerChild.type !== Comment && - !isSameVNodeType(innerChild, oldInnerChild) && + !isSameVNodeType(oldInnerChild, innerChild) && recursiveGetSubtree(instance).type !== Comment ) { let leavingHooks = resolveTransitionHooks(