Skip to content

fix(reactivity): release computeds created during SSR setup - #16013

Merged
edison1105 merged 1 commit into
vuejs:minorfrom
schneefux:fix/computed-scope-ownership
Nov 12, 2026
Merged

edison1105 merged 1 commit into
vuejs:minorfrom
schneefux:fix/computed-scope-ownership

Conversation

@schneefux

Copy link
Copy Markdown

Since 3.6.0-alpha.1, a computed only belongs to an effect scope if it is read while that scope is active. During SSR, a computed created in setup() but read later, e.g. in the render function or after an await, has no owner. If it reads long-lived state, it stays subscribed to it, together with everything its getter references, which leaks memory on every request.

Reproduction:

// node --expose-gc repro.mjs
// Vue 3.5: 0 of 100 computeds still in memory. Vue 3.6: 100 of 100, kept alive by the shared store.
import { computed, createSSRApp, h, reactive } from 'vue'
import { renderToString } from 'vue/server-renderer'

const store = reactive({ count: 1 }) // module-level state shared by all requests

const computeds = []
for (let i = 0; i < 100; i++) {
  const app = createSSRApp({
    setup() {
      const double = computed(() => store.count * 2)
      computeds.push(new WeakRef(double))
      return () => h('div', double.value)
    },
  })
  await renderToString(app)
}

await new Promise(resolve => setTimeout(resolve))
globalThis.gc()
console.log(`${computeds.filter(ref => ref.deref()).length} of 100 computeds still in memory`)

This PR links a computed created during SSR component setup to the active effect scope. The renderer already stops component scopes after rendering (#14548), which now also unsubscribes these computeds. Client-side behavior is unchanged. Computeds created outside setup() during SSR (e.g. in a render function) are not covered.

Cost: +12 bytes gzipped.

Note: This PR was authored using Claude Code with Opus 5.5.

Link a computed created during SSR component setup to the active effect
scope, so stopping the component scope after rendering also unsubscribes
it from long-lived state it read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eaa1352a-ea19-460f-b612-8c7b17d25203

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@edison1105 edison1105 added scope: ssr 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Oct 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 43994e9

@edison1105

Copy link
Copy Markdown
Member

/ecosystem-ci run

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 87.4 kB 30.7 kB 27 kB
runtime-dom.global.prod.js 120 kB (+31 B) 45.2 kB (+6 B) 40.4 kB (+9 B)
vue.global.prod.js 181 kB (+32 B) 65.5 kB (+11 B) 58.3 kB (-8 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 53.9 kB 21 kB 19.1 kB
createApp 62.9 kB (+31 B) 24.3 kB (+9 B) 22.1 kB (+14 B)
createApp + vaporInteropPlugin 117 kB (+10 B) 42.9 kB (+1 B) 38.7 kB (+36 B)
createVaporApp 34.2 kB 13.2 kB 12.2 kB
createSSRApp 67.8 kB (+31 B) 26.3 kB (+22 B) 23.8 kB (-26 B)
createVaporSSRApp 41.4 kB (-129 B) 15.8 kB (-55 B) 14.5 kB (-29 B)
defineCustomElement 69.5 kB (+31 B) 26.3 kB (+9 B) 23.9 kB (-2 B)
defineVaporCustomElement 49.1 kB 18 kB 16.5 kB
overall 78.5 kB (+27 B) 29.8 kB (+6 B) 27 kB (-15 B)

@vue-bot

vue-bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

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

@edison1105
edison1105 merged commit 0727aa0 into vuejs:minor Nov 12, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: ssr version: minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants