fix(compiler-core): prefix dynamic keys on v-memo elements#14922
fix(compiler-core): prefix dynamic keys on v-memo elements#14922edison1105 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdd a WeakSet on TransformContext to track v-for memo-keyed nodes, record memo-keyed nodes in transformFor, restrict skipping of Changesv-memo + v-for key handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/compiler-core/src/transforms/transformExpression.ts`:
- Around line 72-74: The condition that currently uses context.scopes.vFor > 0
to skip :key processing is too broad; change the logic to rely on a
node-specific ownership flag set by transformFor (e.g., transformFor should mark
the element/node with a boolean like node.__vForKeyed or node.vForKeyProcessed
when it actually handled the key), and then in transformExpression (the branch
that checks memo && context.scopes.vFor > 0 && arg) replace the
context.scopes.vFor check with a test against that node-specific flag (skip only
if node.__vForKeyed is true), and ensure transformFor sets that flag on the
exact node it pre-handles so nested non-owner v-memo elements still get their
keys prefixed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7027883a-83d0-437e-bf9f-1d5b2293d4e6
📒 Files selected for processing (2)
packages/compiler-core/__tests__/transforms/vMemo.spec.tspackages/compiler-core/src/transforms/transformExpression.ts
431c27a to
2c46a65
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/compiler-core/__tests__/transforms/vMemo.spec.ts (1)
24-43: ⚡ Quick winConsider adding snapshot tests or negative assertions for additional coverage.
The current string-matching assertions effectively verify the bug fix, but you could strengthen these tests by:
- Adding negative assertions to confirm unprefixed identifiers are absent (e.g.,
expect(code).not.toContain('key: updateKey')).- Using
.toMatchSnapshot()for full output validation, similar to other tests in this file (lines 17, 21, 46, 55, 65, 75, 85, 95).Both approaches would provide additional confidence that the generated code is fully correct and prevent subtle regressions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/compiler-core/__tests__/transforms/vMemo.spec.ts` around lines 24 - 43, Add stronger assertions to the two tests using the existing compile(...) helper: in each test ('on normal element with dynamic key' and 'on normal element with dynamic key nested in v-for') add negative assertions like expect(code).not.toContain('key: updateKey') and expect(code).not.toContain('key: item.id') (or other unprefixed forms) to ensure identifiers are properly prefixed, and also call expect(code).toMatchSnapshot() to capture the full generated output for regression safety; update references to the expected prefixed strings (_withMemo, _ctx.updateKey, _ctx.get(...)) remain unchanged so the new assertions complement the existing checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/compiler-core/__tests__/transforms/vMemo.spec.ts`:
- Around line 24-43: Add stronger assertions to the two tests using the existing
compile(...) helper: in each test ('on normal element with dynamic key' and 'on
normal element with dynamic key nested in v-for') add negative assertions like
expect(code).not.toContain('key: updateKey') and
expect(code).not.toContain('key: item.id') (or other unprefixed forms) to ensure
identifiers are properly prefixed, and also call expect(code).toMatchSnapshot()
to capture the full generated output for regression safety; update references to
the expected prefixed strings (_withMemo, _ctx.updateKey, _ctx.get(...)) remain
unchanged so the new assertions complement the existing checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bdb2d2c0-66d5-4d25-a904-47423a4a8355
📒 Files selected for processing (4)
packages/compiler-core/__tests__/transforms/vMemo.spec.tspackages/compiler-core/src/transform.tspackages/compiler-core/src/transforms/transformExpression.tspackages/compiler-core/src/transforms/vFor.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/compiler-core/src/transforms/transformExpression.ts
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
close #14920
Summary by CodeRabbit
Bug Fixes
Tests