-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(compiler-core): avoid v-if branch autogen key conflicts #13936
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughIntroduces cross-branch key awareness in v-if transforms by computing and storing anyBranchesHaveUserDefinedKey on IfNode, adjusting codegen to respect user-defined keys across v-if/v-else(-if) branches. Tests are reorganized and expanded to cover key handling scenarios, with helper updates and new snapshots. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Compiler
participant T as v-if Transform
participant B as Branch Analyzer
participant G as Codegen Builder
C->>T: processIf(node, siblings)
T->>B: Collect branches (if/else-if/else)
B->>B: Scan props for user-defined :key
B->>B: Set anyBranchesHaveUserDefinedKey = true if any found
B-->>T: Branch list + cross-branch key flag
rect rgba(230,245,255,0.5)
note right of T: New behavior
T->>G: createCodegenNodeForBranch(branch, hasAnyUserDefinedKeys)
G->>G: Generate keys<br/>- use user key if present<br/>- else generate non-conflicting key (index/hoisted Symbol)
end
G-->>C: If/Else codegen nodes with keys
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 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. Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/compiler-core/src/transforms/vIf.ts (1)
214-215
: KeepanyBranchesHaveUserDefinedKey
in sync when appending branches.Once we push a new branch, we should fold its
userKey
back intosibling.anyBranchesHaveUserDefinedKey
(e.g.sibling.anyBranchesHaveUserDefinedKey ||= !!branch.userKey;
). Right now the flag relies entirely on the initial lookahead performed in thev-if
arm; if a later transform ever injects anelse(-if)
branch with a user key after that scan, the metadata would go stale and downstream codegen would miss that fact. Updating it here is cheap and keeps the flag truthful regardless of transform ordering.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snap
is excluded by!**/*.snap
📒 Files selected for processing (3)
packages/compiler-core/__tests__/transforms/vIf.spec.ts
(4 hunks)packages/compiler-core/src/ast.ts
(1 hunks)packages/compiler-core/src/transforms/vIf.ts
(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-core/__tests__/transforms/vIf.spec.ts (4)
packages/compiler-core/src/runtimeHelpers.ts (1)
MERGE_PROPS
(47-47)packages/compiler-core/__tests__/testUtils.ts (1)
createObjectMatcher
(27-49)packages/compiler-core/src/index.ts (2)
generate
(25-25)transformBind
(47-47)packages/compiler-core/src/transforms/vBind.ts (1)
transformBind
(15-73)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
close #13881
Use hoisted
Symbol()
as the auto-generatedv-if
branch key in the event that any branches of the if block have custom user-defined keys to guarantee uniqueness across the branches with keys specified by the user vs branches with auto-generated keys.Example use case fixed:
Summary by CodeRabbit