Skip to content

Conversation

@linzhe141
Copy link
Contributor

@linzhe141 linzhe141 commented Dec 8, 2025

close #14173

This is a follow-up to this PR #13928.

The following issue examples are just a sufficiently complex case to describe the current issues with patchKeyedChildren + async component wrapper, this maby a edge case.

this pr playground

issue playground

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced handling of unresolved async components by improving placeholder resolution when components have wrapper layers, resulting in more reliable behavior in complex component hierarchies.

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

Walkthrough

Replaces direct anchor vnode access with a new internal resolver that recursively traverses component wrapper VNodes to locate async component placeholders; adds tests validating Suspense + v-for with multiple async wrappers and list updates.

Changes

Cohort / File(s) Summary
Runtime: async placeholder resolution
packages/runtime-core/src/renderer.ts
Added internal helper resolveAsyncComponentPlaceholder(anchorVnode: VNode) that returns placeholder or recursively inspects wrapper component subTrees to find a placeholder; replaced direct anchorVNode.el/anchorVNode.placeholder usage with resolver.
Tests: Suspense + async wrappers
packages/runtime-core/__tests__/components/Suspense.spec.ts
Added tests that render multiple asynchronously wrapped components inside Suspense with v-for and keyed items, then update the list to assert proper DOM order and reactive updates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • resolveAsyncComponentPlaceholder recursion correctness and termination conditions.
    • Integration points where anchor resolution is used in renderer.ts.
    • New tests for determinism and coverage of wrapper nesting / key reconciliation.

Possibly related PRs

Suggested labels

ready to merge, scope: suspense, :hammer: p3-minor-bug

Poem

🐰 I tunneled through wrappers, one hop, then two,
Found the tiny placeholder hidden from view,
Keys kept their order, lists danced in line,
The rabbit applauds — async renders align! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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
Title check ✅ Passed The title accurately describes the main fix: addressing anchor element resolution for deeply nested unresolved async components.
Linked Issues check ✅ Passed The code changes directly address the linked issue #14173 by implementing proper anchor element resolution for async component wrappers in v-for loops within Suspense.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the async component anchor element resolution issue; no unrelated modifications detected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 103 kB (+134 B) 39.1 kB (+47 B) 35.2 kB (+54 B)
vue.global.prod.js 161 kB (+134 B) 59 kB (+44 B) 52.5 kB (-48 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47.1 kB (+134 B) 18.4 kB (+35 B) 16.8 kB (+35 B)
createApp 55.3 kB (+130 B) 21.4 kB (+33 B) 19.6 kB (+21 B)
createSSRApp 59.5 kB (+134 B) 23.2 kB (+37 B) 21.2 kB (+42 B)
defineCustomElement 60.9 kB (+134 B) 23.2 kB (+31 B) 21.2 kB (+41 B)
overall 69.6 kB (+134 B) 26.7 kB (+34 B) 24.3 kB (-11 B)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 8, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: d368ab3

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)

2581-2602: Consider adding defensive safeguards for edge cases.

The recursive traversal logic correctly handles the wrapper component scenario described in issue #14173. However, consider adding safeguards:

  1. Null check for subTree: Line 2590 accesses asyncWrapper.subTree without verification. If a component exists but subTree is undefined (e.g., during initialization or edge cases), this could cause issues.

  2. Cycle detection or depth limit: While component trees should be acyclic, a depth limit or cycle detection would prevent potential infinite recursion if the component structure is unexpected.

Apply this diff to add defensive checks:

 function resolveAsyncComponentPlaceholder(anchorVnode: VNode) {
   // anchor vnode is a unresolved async component
   if (anchorVnode.placeholder) {
     return anchorVnode.placeholder
   }
 
   // anchor vnode maybe is a wrapper component has single unresolved async component
   const asyncWrapper = anchorVnode.component
   if (asyncWrapper) {
     const subTree = asyncWrapper.subTree
+    
+    // guard against missing subTree
+    if (!subTree) {
+      return null
+    }
 
     // wrapper that directly contains an unresolved async component
     if (subTree.placeholder) {
       return subTree.placeholder
     }
 
     // try to locate deeper nested async component placeholder
     return resolveAsyncComponentPlaceholder(subTree)
   }
 
   return null
 }

Alternatively, consider adding a depth parameter to prevent excessive recursion:

function resolveAsyncComponentPlaceholder(anchorVnode: VNode, depth: number = 0): HostNode | null {
  const MAX_DEPTH = 10 // reasonable limit for nested wrappers
  
  if (depth > MAX_DEPTH) {
    if (__DEV__) {
      warn('Maximum depth exceeded while resolving async component placeholder')
    }
    return null
  }
  
  if (anchorVnode.placeholder) {
    return anchorVnode.placeholder
  }
  
  const asyncWrapper = anchorVnode.component
  if (asyncWrapper?.subTree) {
    if (asyncWrapper.subTree.placeholder) {
      return asyncWrapper.subTree.placeholder
    }
    return resolveAsyncComponentPlaceholder(asyncWrapper.subTree, depth + 1)
  }
  
  return null
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f51d3e2 and d62aff8.

📒 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 (1)
packages/runtime-core/src/vnode.ts (1)
  • VNode (160-257)
⏰ 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). (1)
  • GitHub Check: test / e2e-test
🔇 Additional comments (1)
packages/runtime-core/src/renderer.ts (1)

1999-1999: LGTM! Correctly handles nested async component placeholders.

The fallback chain (anchorVNode.el || resolveAsyncComponentPlaceholder(anchorVNode)) appropriately addresses the edge case where wrapper components contain unresolved async components. This ensures the correct anchor is found even when there are intermediate wrapper elements.

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.

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

1 participant