Skip to content

Conversation

@rzzf
Copy link
Contributor

@rzzf rzzf commented Dec 6, 2025

fix #14173

Summary by CodeRabbit

  • Tests

    • Added test case for rendering multiple async components inside Suspense with dynamic lists.
  • Bug Fixes

    • Improved element anchoring for unresolved async components during rendering.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 6, 2025

Walkthrough

Fixes Suspense element ordering issue when using v-for with wrapper components around async components. Introduces a helper function to resolve actual elements from unresolved async component sub-trees during anchor calculation in patch operations, extending the fallback chain for proper element positioning.

Changes

Cohort / File(s) Summary
Test for async component list rendering
packages/runtime-core/__tests__/components/Suspense.spec.ts
Adds test case validating v-for with async components wrapped by an HOC inside Suspense; mutates items array and asserts correct render order and content.
Anchor resolution for unresolved async components
packages/runtime-core/src/renderer.ts
Introduces getSubTreeElement(vnode) helper to traverse unresolved async component sub-trees and retrieve host elements; extends anchor fallback chain in patchBlockChildren to use this helper when standard anchors are unavailable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • New helper function is straightforward with minimal logic
  • Targeted bug fix extending an existing fallback chain
  • Test validates the fix with clear assertions

Possibly related PRs

Suggested labels

ready to merge

Poem

🐰 A hop, a skip, a vnode's fix,
The async dance no longer breaks,
With getSubTreeElement's gentle mix,
The render order now partakes,
In perfect v-for harmony!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: correcting placeholder propagation for async components in Suspense contexts, which is the core issue addressed.
Linked Issues check ✅ Passed The PR implements the fix for issue #14173 by introducing a getSubTreeElement helper to properly resolve async component elements, enabling correct anchor calculation and preserving render order in Suspense + v-for scenarios.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the async component placeholder propagation issue: test case validates the fix, renderer modification implements the anchor logic improvement, with no unrelated changes present.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@github-actions
Copy link

github-actions bot commented Dec 6, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 103 kB (+93 B) 39 kB (+31 B) 35.2 kB (+43 B)
vue.global.prod.js 161 kB (+93 B) 59 kB (+36 B) 52.4 kB (-124 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47 kB (+90 B) 18.4 kB (+32 B) 16.8 kB (+27 B)
createApp 55.2 kB (+86 B) 21.4 kB (+30 B) 19.6 kB (+13 B)
createSSRApp 59.5 kB (+93 B) 23.2 kB (+34 B) 21.2 kB (+37 B)
defineCustomElement 60.8 kB (+90 B) 23.2 kB (+35 B) 21.1 kB (+29 B)
overall 69.5 kB (+90 B) 26.6 kB (+29 B) 24.3 kB (+11 B)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 6, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: ac75959

if (root === vnode) {
;(vnode = parent.vnode).el = el
if (root.placeholder) {
vnode.placeholder = root.placeholder
Copy link
Member

Choose a reason for hiding this comment

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

This should cause a memory leak, leading to the placeholder referencing a detached DOM node. Because when Suspense resolves, we only clear the placeholder of the async component. see

vnode.placeholder = null

Copy link
Member

Choose a reason for hiding this comment

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

The correct approach should be to attempt to locate the placeholder on anchorVNode.component.subTree here

anchorVNode.el || anchorVNode.placeholder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your guidance. I’ve made the changes accordingly.

@edison1105 edison1105 added scope: suspense 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. wait changes labels Dec 8, 2025
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: 0

🧹 Nitpick comments (1)
packages/runtime-core/src/renderer.ts (1)

2423-2429: Add defensive null check for subTree.

While subTree should always be set after setupComponent, consider adding a defensive check to prevent potential runtime errors in edge cases (e.g., error handling, invalid component states):

Apply this diff to make the function more robust:

 const getSubTreeElement = (vnode: VNode): RendererNode | null => {
   let current = vnode
-  while (current.component) {
+  while (current.component && current.component.subTree) {
     current = current.component.subTree
   }
   return current.el || current.placeholder
 }

This ensures we won't attempt to traverse into components with uninitialized subtrees.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea03d8e and ac75959.

📒 Files selected for processing (1)
  • packages/runtime-core/src/renderer.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/runtime-core/src/renderer.ts (2)
packages/runtime-core/src/vnode.ts (1)
  • VNode (160-257)
packages/runtime-core/src/index.ts (2)
  • VNode (250-250)
  • RendererNode (306-306)
🔇 Additional comments (1)
packages/runtime-core/src/renderer.ts (1)

1999-2001: LGTM! Anchor fallback chain correctly handles wrapper components.

The extended fallback chain properly resolves the anchor element when async components are wrapped by other components. The progression from elplaceholdergetSubTreeElement() ensures correct element ordering in Suspense scenarios with v-for.

while (current.component) {
current = current.component.subTree
}
return current.el || current.placeholder
Copy link
Member

@edison1105 edison1105 Dec 9, 2025

Choose a reason for hiding this comment

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

There's no need to get current.el here; if el has a value, then anchorVNode.el must also have a value.
Just need to get current.placeholder.

This implementation isn't quite right either; we shouldn't keep searching down the subTree but should early return as soon as we find the placeholder.

Copy link
Member

@edison1105 edison1105 Dec 9, 2025

Choose a reason for hiding this comment

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

Thanks for the PR, but I perfer https://github.com/vuejs/core/pull/14182/files

@edison1105 edison1105 closed this Dec 9, 2025
@rzzf rzzf deleted the fix/14173 branch December 9, 2025 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: suspense wait changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<Suspense> changes the order of elements when using v-for with a given key and a wrapper component

2 participants