Skip to content

feat(vapor): preserve static keys#14607

Draft
edison1105 wants to merge 12 commits intominorfrom
edison/feat/setKey
Draft

feat(vapor): preserve static keys#14607
edison1105 wants to merge 12 commits intominorfrom
edison/feat/setKey

Conversation

@edison1105
Copy link
Member

@edison1105 edison1105 commented Mar 20, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added comprehensive support for transitions with statically keyed elements and components in transition-group and transition contexts
    • Introduced setBlockKey public API for explicit key management in components
    • Enhanced vDOM interop to properly propagate keys across framework boundaries
  • Tests

    • Added extensive end-to-end and unit tests for transition-group/transition behavior with static keying
    • Added tests for KeepAlive cache key resolution and vDOM interop key propagation

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Important

Review skipped

Draft detected.

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

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78a8d16d-7336-479e-96aa-0c574ff75a46

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/feat/setKey
📝 Coding Plan
  • Generate coding plan for human review comments

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: d5131e0

@github-actions
Copy link

github-actions bot commented Mar 20, 2026

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.4 kB 30.2 kB 26.6 kB
runtime-dom.global.prod.js 111 kB 41.9 kB 37.5 kB
vue.global.prod.js 170 kB 61.7 kB 55 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 50.6 kB 19.8 kB 18 kB
createApp 59.6 kB 23.1 kB 21 kB
createApp + vaporInteropPlugin 85.9 kB (+919 B) 31.8 kB (+379 B) 28.7 kB (+302 B)
createVaporApp 28.7 kB (+51 B) 11.1 kB (+43 B) 10.2 kB (+37 B)
createSSRApp 63.9 kB 24.8 kB 22.5 kB
createVaporSSRApp 32 kB (+51 B) 12.4 kB (+41 B) 11.4 kB (+39 B)
defineCustomElement 66.2 kB 25.1 kB 22.8 kB
defineVaporCustomElement 39.3 kB (+51 B) 14.6 kB (+38 B) 13.4 kB (+57 B)
overall 74.5 kB 28.4 kB 25.8 kB

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/components/Transition.spec.ts (1)

13-76: Add one async-wrapper regression case here.

These assertions only hit the normal component branch. resolveTransitionBlock() now has the same key fallback duplicated under the resolved isAsyncWrapper(block) path, so that branch can still drift without tripping this suite.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/__tests__/components/Transition.spec.ts` around lines
13 - 76, Add a test that exercises the isAsyncWrapper path of
resolveTransitionBlock by wrapping the Child in an async-wrapper component and
asserting the same key-fallback behavior: create a Child via
defineVaporComponent, create an async wrapper component (so the child's block is
wrapped as an async wrapper), call createComponent/define to render the wrapper,
set an explicit key with setBlockKey on the inner child, clear child.block.$key
and then call resolveTransitionBlock(wrapperInstance) and assert the
resolved.$key prefers the explicit key (and add similar assertions for fallback
to uid and preserving falsy keys if desired); this ensures the duplicated
key-fallback logic inside the isAsyncWrapper branch is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/runtime-vapor/src/components/Transition.ts`:
- Around line 371-378: The code currently only falls back when child.$key ===
undefined, which preserves a literal null key; change the checks to use nullish
semantics (child.$key == null) so both null and undefined are treated as “no
key” and then assign child.$key = block.$key ?? block.uid; update both
occurrences (the branch that assigns child.$key and the similar block at the
later occurrence) and ensure transitionTypeMap.set(child, block.type) remains
unchanged.

In `@packages/runtime-vapor/src/helpers/setKey.ts`:
- Around line 16-19: The array branch in setKey (in
packages/runtime-vapor/src/helpers/setKey.ts) ignores multi-root blocks causing
keys not to propagate; update the isArray(block) branch to call setBlockKey for
every element when block.length > 1 (i.e., iterate over block and call
setBlockKey(item, key) for each child) instead of only handling length === 1 so
all elements receive the key; ensure any existing early-return logic or
surrounding control flow in setKey and the setBlockKey helper remains consistent
after adding the loop.

---

Nitpick comments:
In `@packages/runtime-vapor/__tests__/components/Transition.spec.ts`:
- Around line 13-76: Add a test that exercises the isAsyncWrapper path of
resolveTransitionBlock by wrapping the Child in an async-wrapper component and
asserting the same key-fallback behavior: create a Child via
defineVaporComponent, create an async wrapper component (so the child's block is
wrapped as an async wrapper), call createComponent/define to render the wrapper,
set an explicit key with setBlockKey on the inner child, clear child.block.$key
and then call resolveTransitionBlock(wrapperInstance) and assert the
resolved.$key prefers the explicit key (and add similar assertions for fallback
to uid and preserving falsy keys if desired); this ensures the duplicated
key-fallback logic inside the isAsyncWrapper branch is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cae63d7f-938a-44d9-9c5a-bde1a2e77d59

📥 Commits

Reviewing files that changed from the base of the PR and between cc0d96f and 7a7e671.

⛔ Files ignored due to path filters (1)
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/transformKey.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (37)
  • packages-private/vapor-e2e-test/__tests__/transition-group.spec.ts
  • packages-private/vapor-e2e-test/__tests__/transition.spec.ts
  • packages-private/vapor-e2e-test/transition-group/cases/interop/avoid-set-transition-hooks-for-comment-node.vue
  • packages-private/vapor-e2e-test/transition-group/cases/interop/static-keyed-vdom-component-enter.vue
  • packages-private/vapor-e2e-test/transition-group/cases/interop/unkeyed-vdom-component-update.vue
  • packages-private/vapor-e2e-test/transition-group/cases/vapor-transition-group/static-keyed-component-enter.vue
  • packages-private/vapor-e2e-test/transition-group/cases/vapor-transition-group/static-keyed-enter.vue
  • packages-private/vapor-e2e-test/transition-group/components/StaticKeyItem.vue
  • packages-private/vapor-e2e-test/transition-group/components/VdomCommentToggle.vue
  • packages-private/vapor-e2e-test/transition-group/components/VdomKeyItem.vue
  • packages-private/vapor-e2e-test/transition/cases/interop/should-work-with-static-keyed-vdom-component.vue
  • packages-private/vapor-e2e-test/transition/cases/keyed/should-work-with-static-keyed-component.vue
  • packages-private/vapor-e2e-test/transition/cases/keyed/should-work-with-static-keyed-element.vue
  • packages-private/vapor-e2e-test/transition/components/StaticKeyItem.vue
  • packages-private/vapor-e2e-test/transition/components/VdomKeyItem.vue
  • packages/compiler-vapor/__tests__/transforms/transformKey.spec.ts
  • packages/compiler-vapor/__tests__/transforms/vIf.spec.ts
  • packages/compiler-vapor/src/generators/key.ts
  • packages/compiler-vapor/src/generators/operation.ts
  • packages/compiler-vapor/src/ir/index.ts
  • packages/compiler-vapor/src/transforms/transformElement.ts
  • packages/compiler-vapor/src/utils.ts
  • packages/runtime-vapor/__tests__/apiCreateDynamicComponent.spec.ts
  • packages/runtime-vapor/__tests__/components/KeepAlive.spec.ts
  • packages/runtime-vapor/__tests__/components/Transition.spec.ts
  • packages/runtime-vapor/__tests__/components/TransitionGroup.spec.ts
  • packages/runtime-vapor/__tests__/helpers/setKey.spec.ts
  • packages/runtime-vapor/__tests__/vdomInterop.spec.ts
  • packages/runtime-vapor/src/block.ts
  • packages/runtime-vapor/src/component.ts
  • packages/runtime-vapor/src/components/KeepAlive.ts
  • packages/runtime-vapor/src/components/Transition.ts
  • packages/runtime-vapor/src/components/TransitionGroup.ts
  • packages/runtime-vapor/src/fragment.ts
  • packages/runtime-vapor/src/helpers/setKey.ts
  • packages/runtime-vapor/src/index.ts
  • packages/runtime-vapor/src/vdomInterop.ts

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.

1 participant