Skip to content
Merged
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
52 changes: 52 additions & 0 deletions packages/runtime-core/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,58 @@ describe('hot module replacement', () => {
expect(serializeInner(root)).toBe('<div>bar</div>')
})

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(`<div>{{ count }}</div>`),
}
createRecord(id, Child)

const appId = 'test-app-id'
const App: ComponentOptions = {
__hmrId: appId,
components: { Child },
render: compileToFunction(`
<KeepAlive>
<Suspense>
<Child />
</Suspense>
</KeepAlive>
`),
}

const root = nodeOps.createElement('div')
render(h(App), root)
expect(serializeInner(root)).toBe('<div>0</div>')
await timeout()
reload(id, {
__hmrId: id,
setup() {
const count = ref(1)
return { count }
},
render: compileToFunction(`<div>{{ count }}</div>`),
})
await timeout()
expect(serializeInner(root)).toBe('<div>1</div>')

reload(id, {
__hmrId: id,
setup() {
const count = ref(2)
return { count }
},
render: compileToFunction(`<div>{{ count }}</div>`),
})
await timeout()
expect(serializeInner(root)).toBe('<div>2</div>')
})

test('rerender for nested component', () => {
const id = 'child-nested-rerender'
const Foo: ComponentOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/components/Suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading