Skip to content

test(transition): memory leaks #12190

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

Closed
Closed
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
120 changes: 120 additions & 0 deletions packages/vue/__tests__/e2e/Transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,126 @@ describe('e2e: Transition', () => {
)
})

// https://github.com/vuejs/core/issues/12181#issuecomment-2414380955
describe('not leaking', async () => {
test('switching VNodes', async () => {
const client = await page().createCDPSession()
await page().evaluate(async () => {
const { createApp, ref, nextTick } = (window as any).Vue
const empty = ref(true)

createApp({
components: {
Child: {
setup: () => {
// Big arrays kick GC earlier
const test = ref([...Array(30_000_000)].map((_, i) => ({ i })))
// TODO: Use a diferent TypeScript env for testing
// @ts-expect-error - Custom property and same lib as runtime is used
window.__REF__ = new WeakRef(test)

return { test }
},
template: `
<p>{{ test.length }}</p>
`,
},
Empty: {
template: '<div></div>',
},
},
template: `
<transition>
<component :is="empty ? 'Empty' : 'Child'" />
</transition>
`,
setup() {
return { empty }
},
}).mount('#app')

await nextTick()
empty.value = false
await nextTick()
empty.value = true
await nextTick()
})

const isCollected = async () =>
// @ts-expect-error - Custom property
await page().evaluate(() => window.__REF__.deref() === undefined)

while ((await isCollected()) === false) {
await client.send('HeapProfiler.collectGarbage')
}

expect(await isCollected()).toBe(true)
})

// https://github.com/vuejs/core/issues/12181#issue-2588232334
test('switching deep vnodes edge case', async () => {
const client = await page().createCDPSession()
await page().evaluate(async () => {
const { createApp, ref, nextTick } = (window as any).Vue
const shown = ref(false)

createApp({
components: {
Child: {
setup: () => {
// Big arrays kick GC earlier
const test = ref([...Array(30_000_000)].map((_, i) => ({ i })))
// TODO: Use a diferent TypeScript env for testing
// @ts-expect-error - Custom property and same lib as runtime is used
window.__REF__ = new WeakRef(test)

return { test }
},
template: `
<p>{{ test.length }}</p>
`,
},
Wrapper: {
template: `
<transition>
<div v-if="true">
<slot />
</div>
</transition>
`,
},
},
template: `
<button id="toggleBtn" @click="shown = !shown">{{ shown ? 'Hide' : 'Show' }}</button>
<Wrapper>
<Child v-if="shown" />
<div v-else></div>
</Wrapper>
`,
setup() {
return { shown }
},
}).mount('#app')

await nextTick()
shown.value = true
await nextTick()
shown.value = false
await nextTick()
})

const isCollected = async () =>
// @ts-expect-error - Custom property
await page().evaluate(() => window.__REF__.deref() === undefined)

while ((await isCollected()) === false) {
await client.send('HeapProfiler.collectGarbage')
}

expect(await isCollected()).toBe(true)
})
})

test('warn when used on multiple elements', async () => {
createApp({
render() {
Expand Down