Skip to content

fix(compiler-vapor): let v-for and v-slot scope variables shadow known globals - #16006

Closed
meta-syntax wants to merge 1 commit into
vuejs:minorfrom
meta-syntax:fix/compiler-vapor-scope-variable-shadow-globals
Closed

meta-syntax wants to merge 1 commit into
vuejs:minorfrom
meta-syntax:fix/compiler-vapor-scope-variable-shadow-globals

Conversation

@meta-syntax

Copy link
Copy Markdown

Follow-up to #15813, which lets setup bindings shadow known globals.

In Vapor, a v-for alias / key or a v-slot prop named like a known global (Date, Number, ...) is treated as the global:

<span v-for="Date in list">{{ Date }}</span>
_setText(x2, _toDisplayString(Date)) // the global Date, with no render effect

In VDOM, Date in this template refers to the v-for alias.

This PR adds a scope argument to isConstantExpression and isConstantBinding, so that a known global is not treated as a constant when a v-for / v-slot scope variable has the same name.
The transform implements scope with isScopeVariable from #15810, and codegen implements it with its identifiers. isScopeVariable only checks whether a v-for / v-slot of the parent elements declares the name, which is not specific to v-model.
So this PR moves it from vModel.ts to utils.ts, together with hasScopeBinding (from transformElement.ts) that it calls, without changing them.

The compiler output changes only when a scope variable has the name of a known global. At compile time, the parent elements are searched only when the expression is a known global name.

The added tests check only the compiler output and fail without the fix.

@coderabbitai

coderabbitai Bot commented Oct 24, 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: 000a5414-930c-455b-87d6-f6b30083ff81

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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: b1816a9

@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 45.2 kB 40.4 kB
vue.global.prod.js 181 kB 65.4 kB 58.3 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 53.9 kB 21 kB 19.1 kB
createApp 62.9 kB 24.3 kB 22.1 kB
createApp + vaporInteropPlugin 117 kB 42.9 kB 38.7 kB
createVaporApp 34.2 kB 13.2 kB 12.2 kB
createSSRApp 67.8 kB 26.3 kB 23.9 kB
createVaporSSRApp 41.4 kB 15.8 kB 14.5 kB
defineCustomElement 69.5 kB 26.3 kB 23.9 kB
defineVaporCustomElement 49.1 kB 18 kB 16.5 kB
overall 78.4 kB 29.8 kB 27 kB

@edison1105

Copy link
Copy Markdown
Member

Thanks for the PR. #15813 addressed a concrete use case, including a setup component named Number. This follow-up covers much rarer naming patterns for v-for aliases and slot bindings, without a demonstrated real-world use case.

I don’t think we need to add more handling for these cases solely for completeness. Renaming the local binding is a straightforward workaround. Closing this for now; we can revisit it if a concrete user report shows a practical need.

@edison1105 edison1105 closed this Oct 24, 2026
@meta-syntax
meta-syntax deleted the fix/compiler-vapor-scope-variable-shadow-globals branch October 25, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants