Skip to content

fix: When the app is unmounted, the onMounted of suspense in Transition should not be called #11059

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 7 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions packages/runtime-core/src/components/Suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ function createSuspenseBoundary(
)
queuePostFlushCb(effects)
}
activeBranch!.transition!.afterLeave = undefined
}
}
// unmount current active tree
Expand Down
61 changes: 60 additions & 1 deletion packages/runtime-dom/__tests__/createApp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createApp, h } from '../src'
import { createApp, h, ref } from '../src'
import { defineComponent, onMounted, shallowRef } from 'vue'

describe('createApp for dom', () => {
// #2926
Expand Down Expand Up @@ -39,4 +40,62 @@ describe('createApp for dom', () => {
// ensure no mutation happened to Root object
expect(originalObj).toMatchObject(Root)
})

test('When the app is unmounted, the onMounted of suspense in Transition should not be called', async () => {
const onPage2Mounted = vi.fn()
let page1Comp: any
const Page1 = defineComponent({
name: 'Page1',
setup() {
return () => h('div', null, 'page1')
},
})
const Page2 = defineComponent({
name: 'Page2',
setup() {
onMounted(onPage2Mounted)
return () => h('div', null, 'page2')
},
})
const Component = shallowRef(Page1)
const page = ref<any>(null)
const App = defineComponent({
setup() {
return {
Component,
page,
}
},
template: `
<div>
<template v-if="Component">
<transition :duration="300" mode="out-in" appear>
<keep-alive :include="['Page1', 'Page2']">
<suspense>
<component ref="page" :is="Component" :key="Component.name"></component>
</suspense>
</keep-alive>
</transition>
</template>
</div>
`,
})
const app = createApp(App)
app.mount(document.createElement('div'))
await new Promise(resolve => {
setTimeout(resolve, 500)
})
page1Comp = page.value
Component.value = Page2
await new Promise(resolve => {
setTimeout(resolve, 500)
})
expect(onPage2Mounted).toHaveBeenCalledTimes(1)
app.unmount()
await new Promise(resolve => {
setTimeout(resolve, 500)
})
expect(onPage2Mounted).toHaveBeenCalledTimes(1)
expect(page1Comp._.vnode.transition.afterLeave).toBe(undefined)
})
})