Skip to content

Conversation

@linzhe141
Copy link
Contributor

@linzhe141 linzhe141 commented Dec 8, 2025

close #14173

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

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
    • Improved placeholder resolution for nested/wrapped async components so Suspense handles complex component hierarchies more reliably.
  • Tests
    • Added tests covering nested async components rendered via v-for with wrapper layers, validating initial render and subsequent updates.

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

Walkthrough

Replaces a direct fallback to an anchor vnode placeholder with an internal resolver that recursively inspects component wrapper VNodes to locate async component placeholders; adds tests exercising Suspense + v-for with nested 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) which returns anchorVnode.placeholder or recursively inspects wrapper component subTrees to locate a placeholder; replaced direct fallback (`anchorVNode.el
Tests: Suspense + async wrappers
packages/runtime-core/__tests__/components/Suspense.spec.ts
Added a new test (duplicated in a parallel location) that renders multiple asynchronously wrapped components inside <Suspense> with v-for and keys, then updates the list to assert correct DOM order and reactive updates through nested wrappers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • Correctness and termination of resolveAsyncComponentPlaceholder recursion (handling nested wrappers and null cases).
    • Ensure all renderer code paths using anchor resolution still behave correctly for different vnode shapes (plain anchors, placeholders, wrapped components).
    • Validate new tests for determinism and that they cover the regression described in linked issue #14173.

Possibly related PRs

Suggested labels

scope: suspense

Poem

🐇 I peeked behind wrappers, soft and deep,
Found placeholders where they used to sleep.
Keys kept their places, order stayed bright,
A tiny hop fixed async's flight. 🥕

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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: ensuring correct anchor element for deeper unresolved async components in v-for scenarios.
Linked Issues check ✅ Passed The code changes implement the fix for issue #14173 by adding resolveAsyncComponentPlaceholder() to correctly resolve anchor elements for nested async components, directly addressing the reverse rendering order issue.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the linked issue: the new helper function resolves placeholder anchors for nested async components, and tests validate the fix works correctly.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d186fd4 and 13995cb.

📒 Files selected for processing (1)
  • packages/runtime-core/src/renderer.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/runtime-core/src/renderer.ts
⏰ 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). (2)
  • GitHub Check: test / e2e-test
  • GitHub Check: test / unit-test-windows

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 (+87 B) 39 kB (+32 B) 35.1 kB (+11 B)
vue.global.prod.js 161 kB (+87 B) 59 kB (+35 B) 52.5 kB (-42 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47 kB (+87 B) 18.4 kB (+28 B) 16.8 kB (+25 B)
createApp 55.2 kB (+83 B) 21.4 kB (+27 B) 19.6 kB (+6 B)
createSSRApp 59.5 kB (+87 B) 23.2 kB (+29 B) 21.1 kB (+27 B)
defineCustomElement 60.8 kB (+87 B) 23.2 kB (+28 B) 21.1 kB (+27 B)
overall 69.5 kB (+87 B) 26.6 kB (+27 B) 24.3 kB (-23 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: 13995cb

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.

@edison1105 edison1105 added ready to merge The PR is ready to be merged. 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Dec 9, 2025
@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Dec 9, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
nuxt success success
language-tools failure success
pinia success success
router failure failure
vant success success
primevue success success
test-utils success success
vite-plugin-vue success success
quasar success success
radix-vue success success
vitepress success success
vue-i18n failure failure
vueuse success success
vue-macros failure failure
vue-simple-compiler success success
vuetify failure failure

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. ready to merge The PR is ready to be merged.

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

3 participants