Skip to content

fix(runtime-vapor): support render vapor async wrapper in vdom suspense - #14633

Merged
edison1105 merged 5 commits into
minorfrom
edison/fix/async-comp-bugs
Mar 30, 2026
Merged

edison1105 merged 5 commits into
minorfrom
edison/fix/async-comp-bugs

Conversation

@edison1105

@edison1105 edison1105 commented Mar 26, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed async component caching behavior with KeepAlive to properly preserve state across activation cycles and respect include/exclude rules
    • Improved error handling for async components with fallback and error component support
    • Fixed ref handling during component deactivation in KeepAlive scenarios
  • Tests

    • Added comprehensive test coverage for async component lifecycle behavior with KeepAlive
    • Added Suspense interop tests for async components with error and fallback handling

@edison1105 edison1105 added the scope: vapor related to vapor mode label Mar 26, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown

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: 2c1f2fd6-05e6-4f58-8cc1-adb9bc5588be

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
  • Commit unit tests in branch edison/fix/async-comp-bugs

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

@github-actions

github-actions Bot commented Mar 26, 2026 •

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.4 kB 30.3 kB 26.6 kB
runtime-dom.global.prod.js 112 kB 42.1 kB 37.7 kB
vue.global.prod.js 171 kB 61.9 kB 55.2 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 50.8 kB 19.8 kB 18.1 kB
createApp 59.8 kB 23.2 kB 21.1 kB
createApp + vaporInteropPlugin 86.1 kB (+1 B) 31.8 kB (+1 B) 28.8 kB (-7 B)
createVaporApp 28.9 kB 11.2 kB 10.3 kB
createSSRApp 64 kB 24.9 kB 22.6 kB
createVaporSSRApp 32.2 kB 12.5 kB 11.4 kB
defineCustomElement 66.4 kB 25.1 kB 22.9 kB
defineVaporCustomElement 39.5 kB 14.7 kB 13.4 kB
overall 74.8 kB 28.5 kB 25.9 kB

@pkg-pr-new

pkg-pr-new Bot commented Mar 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14633
npm i https://pkg.pr.new/@vue/compiler-core@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14633
npm i https://pkg.pr.new/@vue/compiler-dom@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14633
npm i https://pkg.pr.new/@vue/compiler-sfc@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14633
npm i https://pkg.pr.new/@vue/compiler-ssr@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@14633
npm i https://pkg.pr.new/@vue/compiler-vapor@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14633
npm i https://pkg.pr.new/@vue/reactivity@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14633
npm i https://pkg.pr.new/@vue/runtime-core@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14633
npm i https://pkg.pr.new/@vue/runtime-dom@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@14633
npm i https://pkg.pr.new/@vue/runtime-vapor@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14633
npm i https://pkg.pr.new/@vue/server-renderer@14633
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14633
npm i https://pkg.pr.new/@vue/shared@14633
yarn add https://pkg.pr.new/@vue/[email protected]

vue

pnpm add https://pkg.pr.new/vue@14633
npm i https://pkg.pr.new/vue@14633
yarn add https://pkg.pr.new/[email protected]

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14633
npm i https://pkg.pr.new/@vue/compat@14633
yarn add https://pkg.pr.new/@vue/[email protected]

commit: 3cb4219

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/runtime-vapor/src/components/KeepAlive.ts (1)

181-201: ⚠️ Potential issue | 🟠 Major

Late async cache updates still treat the passed block as the live branch.

cacheBlock(block) is now used for offscreen/deactivated async branches, but innerCacheBlock() still does current = block, and this late-cache path never reapplies the keep-alive shape flags that processShapeFlag() would have set during render. A background resolve can therefore replace the pointer to the real active branch, confuse later max/include/exclude pruning, and still leave a newly cacheable async wrapper on the unmount path on the next switch.

🔧 Suggested direction
-    const innerCacheBlock = (
-      key: CacheKey,
-      block: VaporComponentInstance | VaporFragment,
-    ) => {
+    const innerCacheBlock = (
+      key: CacheKey,
+      block: VaporComponentInstance | VaporFragment,
+      isCurrent: boolean,
+    ) => {
       const { max } = props

       if (cache.has(key)) {
         // make this key the freshest
         keys.delete(key)
@@
       }

       cache.set(key, block)
-      current = block
+      if (isCurrent) current = block
     }
@@
       if (!shouldCache(innerBlock, props, interop)) {
         if (cache.has(cacheKey)) pruneCacheEntry(cacheKey)
         return
       }

-      innerCacheBlock(cacheKey, innerBlock)
+      if (interop && isInteropEnabled) {
+        innerBlock.vnode!.shapeFlag! |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
+        if (cache.has(cacheKey)) {
+          innerBlock.vnode!.shapeFlag! |= ShapeFlags.COMPONENT_KEPT_ALIVE
+        }
+      } else {
+        ;(innerBlock as VaporComponentInstance).shapeFlag! |=
+          ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
+        if (cache.has(cacheKey)) {
+          ;(innerBlock as VaporComponentInstance).shapeFlag! |=
+            ShapeFlags.COMPONENT_KEPT_ALIVE
+        }
+      }
+
+      innerCacheBlock(
+        cacheKey,
+        innerBlock,
+        block === keepAliveInstance.block,
+      )

Also applies to: 203-233

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

In `@packages/runtime-vapor/src/components/KeepAlive.ts` around lines 181 - 201,
innerCacheBlock currently sets current = block unconditionally, which lets late
async/offscreen cache updates overwrite the active pointer and skip shape-flag
processing; update innerCacheBlock (and the similar code in the other block) to:
1) call processShapeFlag(block) before inserting into cache so the keep-alive
shape flags are reapplied for late/offscreen branches, and 2) avoid assigning
current = block for offscreen/deactivated async wrappers (only set current when
the block is the actual active branch). Use the existing symbols cache, keys,
cacheBlock, processShapeFlag and pruneCacheEntry to implement the conditional
current assignment and flag reappliance so pruning and unmount paths behave
correctly.
🤖 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/apiDefineAsyncComponent.ts`:
- Around line 180-188: The Suspense error path is unintentionally forwarding the
wrapper's slots into the errorComponent due to defaulting rawSlots to
parent.rawSlots; update the createInnerComp(...) call inside frag.update (the
one that constructs errorComponent) to explicitly pass an empty/new slots object
(or the same slot shape used in the non-Suspense error branch) so the
errorComponent does not receive slot fallthrough; adjust the other similar
createInnerComp(...) invocation(s) that build errorComponent in the suspensible
path to do the same (referencing createInnerComp, errorComponent, frag.update
and rawSlots/parent.rawSlots).

---

Outside diff comments:
In `@packages/runtime-vapor/src/components/KeepAlive.ts`:
- Around line 181-201: innerCacheBlock currently sets current = block
unconditionally, which lets late async/offscreen cache updates overwrite the
active pointer and skip shape-flag processing; update innerCacheBlock (and the
similar code in the other block) to: 1) call processShapeFlag(block) before
inserting into cache so the keep-alive shape flags are reapplied for
late/offscreen branches, and 2) avoid assigning current = block for
offscreen/deactivated async wrappers (only set current when the block is the
actual active branch). Use the existing symbols cache, keys, cacheBlock,
processShapeFlag and pruneCacheEntry to implement the conditional current
assignment and flag reappliance so pruning and unmount paths behave correctly.
🪄 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: 7c32f175-6c9a-46df-91ae-416747fcfff3

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5ad60 and 3acd77d.

📒 Files selected for processing (6)
  • packages/runtime-vapor/__tests__/components/KeepAlive.spec.ts
  • packages/runtime-vapor/__tests__/vdomInterop.spec.ts
  • packages/runtime-vapor/src/apiDefineAsyncComponent.ts
  • packages/runtime-vapor/src/apiTemplateRef.ts
  • packages/runtime-vapor/src/components/KeepAlive.ts
  • packages/runtime-vapor/src/vdomInterop.ts

@edison1105
edison1105 force-pushed the edison/fix/async-comp-bugs branch from 3f2c211 to fb5d72c Compare March 30, 2026 07:43
@edison1105
edison1105 marked this pull request as ready for review March 30, 2026 07:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/runtime-vapor/src/components/KeepAlive.ts (1)

471-484: ⚠️ Potential issue | 🟠 Major

Also reset the resolved interop child here.

defineVaporAsyncComponent() can resolve to a VDOM child, but this helper only clears the inner block when it is vapor. If the wrapper is pruned after resolving to an interop fragment, inner.vnode.shapeFlag still carries the keep-alive bits into teardown.

Suggested fix
 const unsetShapeFlag = (cached: VaporComponentInstance | VaporFragment) => {
   if (isVaporComponent(cached)) {
     resetShapeFlag(cached)
     // for async components, also reset the inner resolved component's
     // shapeFlag.
     if (isAsyncWrapper(cached)) {
       const [inner] = getInnerBlock(cached.block)
-      if (inner && isVaporComponent(inner)) {
-        resetShapeFlag(inner)
+      if (inner) {
+        if (isVaporComponent(inner)) {
+          resetShapeFlag(inner)
+        } else if (isInteropEnabled) {
+          resetShapeFlag(inner.vnode)
+        }
       }
     }
   } else if (isInteropEnabled) {
     resetShapeFlag(cached.vnode)
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/src/components/KeepAlive.ts` around lines 471 - 484,
The unsetShapeFlag helper must also clear shape flags on resolved interop
children when an async wrapper resolves to a non-vapor (interop) fragment:
inside unsetShapeFlag, after obtaining inner via getInnerBlock(cached.block), if
inner exists and is not a vapor component but interop is enabled
(isInteropEnabled), call resetShapeFlag(inner.vnode) so the vnode's shapeFlag
doesn't retain keep-alive bits; keep existing branches for
isVaporComponent(inner) and add this additional conditional to handle the
interop case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/runtime-vapor/src/components/KeepAlive.ts`:
- Around line 471-484: The unsetShapeFlag helper must also clear shape flags on
resolved interop children when an async wrapper resolves to a non-vapor
(interop) fragment: inside unsetShapeFlag, after obtaining inner via
getInnerBlock(cached.block), if inner exists and is not a vapor component but
interop is enabled (isInteropEnabled), call resetShapeFlag(inner.vnode) so the
vnode's shapeFlag doesn't retain keep-alive bits; keep existing branches for
isVaporComponent(inner) and add this additional conditional to handle the
interop case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 76d964c6-f9fe-4c22-9e75-f9e8cf2267c4

📥 Commits

Reviewing files that changed from the base of the PR and between 3acd77d and 3cb4219.

📒 Files selected for processing (4)
  • packages/runtime-vapor/__tests__/components/KeepAlive.spec.ts
  • packages/runtime-vapor/__tests__/vdomInterop.spec.ts
  • packages/runtime-vapor/src/apiDefineAsyncComponent.ts
  • packages/runtime-vapor/src/components/KeepAlive.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/runtime-vapor/src/apiDefineAsyncComponent.ts

@edison1105
edison1105 merged commit fc1dd74 into minor Mar 30, 2026
13 of 14 checks passed
@edison1105
edison1105 deleted the edison/fix/async-comp-bugs branch March 30, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant