Skip to content

fix(compiler-ssr): allow keyed children in v-for slots without slot props - #15891

Merged
edison1105 merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/ssr-v-for-slot-key-placement
Dec 2, 2026
Merged

edison1105 merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/ssr-v-for-slot-key-placement

Conversation

@ValentinYoushkevich

@ValentinYoushkevich ValentinYoushkevich commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

A component whose dynamic slots are rendered with v-for fails to compile for SSR when the slot has no props and its child has a key:

<Comp>
  <template v-for="(text, name) in slots" #[name]>
    <span :key="name">{{ text }}</span>
  </template>
</Comp>

The client compiler accepts this template, and so does the SSR compiler once the slot declares props. Without props, SSR reports <template v-for> key should be placed on the <template> tag. To build the vnode fallback branch, the SSR compiler wraps the slot children in a <template> that gets v-slot only when the slot has props, so the v-for transform treats the wrapper as a <template v-for> fragment. Real example: vue3-ele-form EleFormInput.vue.

Playground

Summary by CodeRabbit

  • Bug Fixes
    • Fixed compilation of slots that use v-for without slot props, preventing keyed children from generating incorrect context references and ensuring valid compilation.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7f0ea71d-c853-4243-ae93-71419f7b5557
📥 Commits

Reviewing files that changed from the base of the PR and between bf5f0dd and fdde1df.

📒 Files selected for processing: 2
  • packages/compiler-ssr/__tests__/ssrComponent.spec.ts
  • packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The SSR component transform now adds a v-slot directive to fallback wrappers when slot props or v-for is present. A regression test checks that a keyed child in a repeated slot compiles without errors or an _ctx.key reference.

Changes: SSR v-for Slot Scope Handling

Layer / File(s) Summary
v-for slot wrapper and regression test
packages/compiler-ssr/src/transforms/ssrTransformComponent.ts, packages/compiler-ssr/__tests__/ssrComponent.spec.ts
The fallback wrapper receives a v-slot directive when slot props or v-for is present. The test checks that compilation reports no errors and generated code does not reference _ctx.key.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to fdde1

The change addresses SSR compilation of keyed dynamic slots inside v-for without slot props, with a regression test for the reported failure. No merge-blocking risk is identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: allowing keyed children in SSR-compiled v-for slots without slot props.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: fdde1df

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 111 kB 41.9 kB 37.7 kB
vue.global.prod.js 171 kB 62.3 kB 55.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 52 kB 20 kB 18.4 kB
createApp 60.1 kB 23.1 kB 21.1 kB
createSSRApp 64.9 kB 25.1 kB 22.9 kB
defineCustomElement 66.4 kB 25.1 kB 22.9 kB
overall 74.5 kB 28.3 kB 25.8 kB

@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. ready to merge The PR is ready to be merged. labels Oct 16, 2026
@edison1105

Copy link
Copy Markdown
Member

/ecosystem-ci run

@vue-bot

vue-bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

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

@edison1105
edison1105 merged commit 4b1181a into vuejs:main Dec 2, 2026
13 of 14 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. ready to merge The PR is ready to be merged. scope: ssr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants