Skip to content

fix(runtime-vapor): refresh same v-for item refs#14788

Draft
edison1105 wants to merge 1 commit into
vuejs:minorfrom
edison1105:edison/fix/14787
Draft

fix(runtime-vapor): refresh same v-for item refs#14788
edison1105 wants to merge 1 commit into
vuejs:minorfrom
edison1105:edison/fix/14787

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented May 7, 2026

Close #14787

Summary by CodeRabbit

  • Bug Fixes

    • Improved list rendering behavior when source data is refreshed or replaced, with proper preservation of unchanged item references.
    • Enhanced list update handling for both keyed and unkeyed list scenarios.
    • Fixed deep mutation tracking for shallow reference list sources.
  • Tests

    • Expanded test coverage for list operations including refresh, replace, and change scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 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: 8f497735-8292-43ef-9293-15b1f32bf1ed

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:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: c287c97

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.5 kB 30.3 kB 26.6 kB
runtime-dom.global.prod.js 113 kB 42.6 kB 38.1 kB
vue.global.prod.js 172 kB 62.4 kB 55.6 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 51.5 kB 20.1 kB 18.3 kB
createApp 60.5 kB 23.4 kB 21.3 kB
createApp + vaporInteropPlugin 101 kB 36.4 kB 32.9 kB
createVaporApp 27.4 kB 10.7 kB 9.77 kB
createSSRApp 65 kB 25.2 kB 22.9 kB
createVaporSSRApp 33.7 kB 12.8 kB 11.8 kB
defineCustomElement 67.1 kB 25.4 kB 23.1 kB
defineVaporCustomElement 40.2 kB 14.3 kB 13.1 kB
overall 75.8 kB 28.9 kB 26.2 kB

Copy link
Copy Markdown

@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: 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/runtime-vapor/src/apiCreateFor.ts`:
- Around line 168-182: The code uses a single boolean (shouldTriggerSameItems)
to decide whether to call triggerSameItemObjectRefs(newBlocks), which skips
triggering refs for individually reused blocks when length/order changes;
instead, change the logic in the unkeyed update loop to collect each reused
block whose update(...) returned false (e.g., push references from newBlocks[i]
/ oldBlocks[i] into a local array) and after all mount/unmount work call
triggerSameItemObjectRefs on that collected array; apply the same pattern
wherever triggerSameItemObjectRefs is invoked for reused items (the other reuse
sites / keyed paths referenced in the review) so each reused block that returned
false from update() is triggered individually regardless of
inserts/removes/moves.
🪄 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: ebd21eda-0504-4c35-8ed8-845e07ee3690

📥 Commits

Reviewing files that changed from the base of the PR and between cf96e99 and c287c97.

📒 Files selected for processing (2)
  • packages/runtime-vapor/__tests__/for.spec.ts
  • packages/runtime-vapor/src/apiCreateFor.ts

Comment on lines +168 to +182
let shouldTriggerSameItems = oldLength === newLength
for (let i = 0; i < commonLength; i++) {
update((newBlocks[i] = oldBlocks[i]), getItem(source, i)[0])
if (update((newBlocks[i] = oldBlocks[i]), getItem(source, i)[0])) {
shouldTriggerSameItems = false
}
}
for (let i = oldLength; i < newLength; i++) {
mount(source, i)
}
for (let i = newLength; i < oldLength; i++) {
unmount(oldBlocks[i])
}
if (shouldTriggerSameItems) {
triggerSameItemObjectRefs(newBlocks)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Track unchanged reused blocks individually, not with a single global flag.

This only retriggers item refs when the whole shared span keeps the same length/order. Mixed updates still miss stale rows. For example, with a shallowRef([a, b]), mutating a, then refreshing to [a, b, c] leaves a unchanged by identity, but Line 168 sets the gate false because the length changed, so triggerRef(aRef) never runs and its DOM stays stale. The same gap exists for replace/move cases in the keyed path once any other block changes.

A safer fix is to collect each reused block whose update() returned false and trigger only those after patching, regardless of whether other rows were inserted, removed, moved, or replaced.

Possible direction
- let shouldTriggerSameItems = oldLength === newLength
+ const sameItemBlocks: ForBlock[] = []

  // whenever a block is reused
- if (update(block, newItem)) {
-   shouldTriggerSameItems = false
- }
+ if (!update(block, newItem)) {
+   sameItemBlocks.push(block)
+ }

- if (shouldTriggerSameItems) {
-   triggerSameItemObjectRefs(newBlocks)
- }
+ triggerSameItemObjectRefs(sameItemBlocks)

You'd need to apply that consistently across the unkeyed path and every keyed reuse site.

Also applies to: 213-227, 371-373, 528-545

🤖 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/runtime-vapor/src/apiCreateFor.ts` around lines 168 - 182, The code
uses a single boolean (shouldTriggerSameItems) to decide whether to call
triggerSameItemObjectRefs(newBlocks), which skips triggering refs for
individually reused blocks when length/order changes; instead, change the logic
in the unkeyed update loop to collect each reused block whose update(...)
returned false (e.g., push references from newBlocks[i] / oldBlocks[i] into a
local array) and after all mount/unmount work call triggerSameItemObjectRefs on
that collected array; apply the same pattern wherever triggerSameItemObjectRefs
is invoked for reused items (the other reuse sites / keyed paths referenced in
the review) so each reused block that returned false from update() is triggered
individually regardless of inserts/removes/moves.

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.

[runtime-vapor] UI does not update correctly when reactive data changes

1 participant