Skip to content

fix(runtime-core): prevent instance leak in withAsyncContext#14445

Merged
edison1105 merged 2 commits intomainfrom
edison/fix/effectScopeMemoryLeak
Feb 24, 2026
Merged

fix(runtime-core): prevent instance leak in withAsyncContext#14445
edison1105 merged 2 commits intomainfrom
edison/fix/effectScopeMemoryLeak

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented Feb 11, 2026

fix nuxt/nuxt#33644 (comment)
schedule withAsyncContext reset after restore to prevent scope leaks

Summary by CodeRabbit

  • Bug Fixes

    • Prevented component instance exposure during asynchronous setup flows, ensuring instance state is cleaned up promptly after async operations.
  • Tests

    • Added tests verifying instance scope is properly restored/cleared across concurrent and asynchronous restore scenarios.

schedule withAsyncContext reset after restore to prevent scope leaks
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Defers component-instance restoration and adds cleanup scheduling in withAsyncContext to prevent instance leakage during async restores; adds tests that assert no instance leakage in microtasks and concurrent restores.

Changes

Cohort / File(s) Summary
Test Additions
packages/runtime-core/__tests__/apiSetupHelpers.spec.ts
Adds tests: "should not leak instance to user microtasks after restore" and "should not leak sibling instance in concurrent restores"; strengthens existing error-handling test to assert instance scope cleanup after async ticks.
Instance Context Restoration
packages/runtime-core/src/apiSetupHelpers.ts
Introduces a dedicated cleanup() routine and defers restoration/cleanup to the next microtask (scheduling via Promise) instead of immediate restoration; catch paths now schedule cleanup for the continuation to avoid restoring a captured instance during concurrent async flows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hop through promises, tidy and spry,

I nudge the restore to the next micro-sky,
No stray instance left where it shouldn't be,
Concurrent restores now safe as can be — hooray for me! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The code changes address the memory leak reported in issue #33644 by implementing proper cleanup in withAsyncContext to prevent scope leaks during async operations.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the async setup instance scope leak; test additions and implementation changes directly target the identified memory leak issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title 'fix(runtime-core): prevent instance leak in withAsyncContext' directly and clearly summarizes the main change - fixing a memory leak in the withAsyncContext function by preventing instance leaks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch edison/fix/effectScopeMemoryLeak

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 11, 2026

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 104 kB (+123 B) 39.3 kB (+33 B) 35.4 kB (+49 B)
vue.global.prod.js 162 kB (+123 B) 59.4 kB (+38 B) 52.8 kB (+74 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47.8 kB 18.6 kB 17.1 kB
createApp 56 kB 21.7 kB 19.8 kB
createSSRApp 60.2 kB 23.4 kB 21.4 kB
defineCustomElement 61.6 kB 23.4 kB 21.4 kB
overall 70.4 kB 27 kB 24.6 kB

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 11, 2026

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14445
npm i https://pkg.pr.new/@vue/compiler-core@14445
yarn add https://pkg.pr.new/@vue/compiler-core@14445.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14445
npm i https://pkg.pr.new/@vue/compiler-dom@14445
yarn add https://pkg.pr.new/@vue/compiler-dom@14445.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14445
npm i https://pkg.pr.new/@vue/compiler-sfc@14445
yarn add https://pkg.pr.new/@vue/compiler-sfc@14445.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14445
npm i https://pkg.pr.new/@vue/compiler-ssr@14445
yarn add https://pkg.pr.new/@vue/compiler-ssr@14445.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14445
npm i https://pkg.pr.new/@vue/reactivity@14445
yarn add https://pkg.pr.new/@vue/reactivity@14445.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14445
npm i https://pkg.pr.new/@vue/runtime-core@14445
yarn add https://pkg.pr.new/@vue/runtime-core@14445.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14445
npm i https://pkg.pr.new/@vue/runtime-dom@14445
yarn add https://pkg.pr.new/@vue/runtime-dom@14445.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14445
npm i https://pkg.pr.new/@vue/server-renderer@14445
yarn add https://pkg.pr.new/@vue/server-renderer@14445.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14445
npm i https://pkg.pr.new/@vue/shared@14445
yarn add https://pkg.pr.new/@vue/shared@14445.tgz

vue

pnpm add https://pkg.pr.new/vue@14445
npm i https://pkg.pr.new/vue@14445
yarn add https://pkg.pr.new/vue@14445.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14445
npm i https://pkg.pr.new/@vue/compat@14445
yarn add https://pkg.pr.new/@vue/compat@14445.tgz

commit: 62fa082

@edison1105 edison1105 added the ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. label Feb 11, 2026
@edison1105
Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@edison1105 edison1105 changed the title fix(runtime-core): balance async setup instance scope restore/reset fix(runtime-core): prevent instance leak in withAsyncContext Feb 12, 2026
@vue-bot
Copy link
Copy Markdown
Contributor

vue-bot commented Feb 12, 2026

📝 Ran ecosystem CI: Open

suite result latest scheduled
pinia success success
radix-vue success success
quasar success success
vitepress success success
vite-plugin-vue success success
primevue success success
nuxt success success
language-tools success success
vant success success
vue-i18n success success
router failure failure
vueuse success success
vue-macros success success
vuetify success success
vue-simple-compiler success success
test-utils success success

@vuejs vuejs deleted a comment from edison1105 Feb 12, 2026
@SebbeJohansson
Copy link
Copy Markdown

@edison1105 when do you think this could be included in a release? Waiting for this to be included upstream in nuxt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in Vue

3 participants