Skip to content

fix(runtime-vapor): preserve slot owner rendering context in resolveDynamicComponent#14475

Merged
edison1105 merged 1 commit intominorfrom
edison/fix/14474
Feb 26, 2026
Merged

fix(runtime-vapor): preserve slot owner rendering context in resolveDynamicComponent#14475
edison1105 merged 1 commit intominorfrom
edison/fix/14474

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented Feb 25, 2026

close #14474

Summary by CodeRabbit

Release Notes

  • Refactor

    • Improved internal rendering context management for more reliable component instance handling and enhanced compatibility mode support.
  • Tests

    • Added test coverage for slot resolution in dynamic components.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 25, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

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:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch edison/fix/14474

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.4 kB 30.2 kB 26.6 kB
runtime-dom.global.prod.js 110 kB 41.6 kB 37.3 kB
vue.global.prod.js 169 kB 61.4 kB 54.8 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 50.3 kB 19.7 kB 17.9 kB
createApp 59.3 kB 23 kB 20.9 kB
createApp + vaporInteropPlugin 82.3 kB 30.5 kB 27.7 kB
createVaporApp 28.6 kB 11.1 kB 10.2 kB
createSSRApp 63.5 kB 24.7 kB 22.5 kB
createVaporSSRApp 32 kB 12.4 kB 11.3 kB
defineCustomElement 65.3 kB 24.8 kB 22.5 kB
defineVaporCustomElement 38.9 kB 14.4 kB 13.2 kB
overall 74.2 kB 28.3 kB 25.7 kB

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: cd23d73

@edison1105 edison1105 linked an issue Feb 25, 2026 that may be closed by this pull request
@edison1105 edison1105 added the scope: vapor related to vapor mode label Feb 25, 2026
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

Caution

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

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

177-405: ⚠️ Potential issue | 🟠 Major

Use try/finally for setCurrentRenderingInstance restoration in renderList.

The current flow can leave currentRenderingInstance stuck if an error happens during patch/mount work.

🔧 Proposed hardening
-      const prevOwner = setCurrentRenderingInstance(scopeOwner)
-      parent = parent || parentAnchor!.parentNode
-      if (!oldLength) {
+      const prevOwner = setCurrentRenderingInstance(scopeOwner)
+      try {
+        parent = parent || parentAnchor!.parentNode
+        if (!oldLength) {
           // ...
-      }
-      setCurrentRenderingInstance(prevOwner)
+        }
+      } finally {
+        setCurrentRenderingInstance(prevOwner)
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/src/apiCreateFor.ts` around lines 177 - 405, The code
sets prevOwner via setCurrentRenderingInstance(scopeOwner) but only restores it
at the end with setCurrentRenderingInstance(prevOwner), which can be skipped if
an exception occurs during the list patch/mount/unmount work; wrap the large
body between the prevOwner assignment and the final setCurrentRenderingInstance
call in a try/finally and move setCurrentRenderingInstance(prevOwner) into the
finally block so that restoration always happens even if mount/update/unmount
(e.g., mount, unmount, update, insert, moveLink) throws; keep the same scope and
ensure any early returns (if present) still restore by returning inside the try
while the finally restores prevOwner.
packages/runtime-vapor/src/fragment.ts (1)

197-213: ⚠️ Potential issue | 🟠 Major

Protect rendering-context restoration with try/finally.

If render (or code after it) throws, currentRenderingInstance/KeepAlive context restoration is skipped, which can leak context across updates.

🔧 Proposed hardening
-      const prevOwner = setCurrentRenderingInstance(this.slotOwner)
-      // set currentKeepAliveCtx so nested DynamicFragments and components can capture it
-      const prevCtx = setCurrentKeepAliveCtx(keepAliveCtx)
+      const prevOwner = setCurrentRenderingInstance(this.slotOwner)
+      // set currentKeepAliveCtx so nested DynamicFragments and components can capture it
+      const prevCtx = setCurrentKeepAliveCtx(keepAliveCtx)
+      let prev:
+        | [GenericComponentInstance | null, EffectScope | undefined]
+        | undefined
       let prevBranchKey: any
-      if (keepAliveCtx && this.keyed) {
-        prevBranchKey = keepAliveCtx.setCurrentBranchKey(this.current)
-      }
-      // switch current instance to parent instance during update
-      // ensure that the parent instance is correct for nested components
-      const prev = parent && instance ? setCurrentInstance(instance) : undefined
-      this.nodes = this.scope.run(render) || []
-      if (prev !== undefined) setCurrentInstance(...prev)
-      if (keepAliveCtx && this.keyed) {
-        keepAliveCtx.setCurrentBranchKey(prevBranchKey)
-      }
-      setCurrentKeepAliveCtx(prevCtx)
-      setCurrentRenderingInstance(prevOwner)
+      try {
+        if (keepAliveCtx && this.keyed) {
+          prevBranchKey = keepAliveCtx.setCurrentBranchKey(this.current)
+        }
+        // switch current instance to parent instance during update
+        // ensure that the parent instance is correct for nested components
+        prev = parent && instance ? setCurrentInstance(instance) : undefined
+        this.nodes = this.scope.run(render) || []
+      } finally {
+        if (prev !== undefined) setCurrentInstance(...prev)
+        if (keepAliveCtx && this.keyed) {
+          keepAliveCtx.setCurrentBranchKey(prevBranchKey)
+        }
+        setCurrentKeepAliveCtx(prevCtx)
+        setCurrentRenderingInstance(prevOwner)
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/src/fragment.ts` around lines 197 - 213, Wrap the call
to this.scope.run(render) and the subsequent context-restoration in a
try/finally: capture prevOwner (from setCurrentRenderingInstance), prevCtx (from
setCurrentKeepAliveCtx), prevBranchKey (from keepAliveCtx.setCurrentBranchKey)
and prev (from setCurrentInstance(instance)) before calling
this.scope.run(render), then in a finally block always restore those contexts by
calling setCurrentInstance(prev),
keepAliveCtx.setCurrentBranchKey(prevBranchKey) (if used),
setCurrentKeepAliveCtx(prevCtx), and setCurrentRenderingInstance(prevOwner) so
context cannot leak if render throws.
🤖 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/component.ts`:
- Around line 348-350: The code sets prevSlotOwner via
setCurrentRenderingInstance(null) but restores it only after potentially
throwing work; wrap the initialization/child rendering block in a try...finally
so setCurrentRenderingInstance(prevSlotOwner) is always called, and apply the
same try/finally pattern to the other restore site around lines handling
prevSlotOwner (the other setCurrentRenderingInstance call at the secondary
location). Ensure you keep the assignment const prevSlotOwner =
setCurrentRenderingInstance(null) and call
setCurrentRenderingInstance(prevSlotOwner) inside finally to guarantee
restoration of currentRenderingInstance even on exceptions.

---

Outside diff comments:
In `@packages/runtime-vapor/src/apiCreateFor.ts`:
- Around line 177-405: The code sets prevOwner via
setCurrentRenderingInstance(scopeOwner) but only restores it at the end with
setCurrentRenderingInstance(prevOwner), which can be skipped if an exception
occurs during the list patch/mount/unmount work; wrap the large body between the
prevOwner assignment and the final setCurrentRenderingInstance call in a
try/finally and move setCurrentRenderingInstance(prevOwner) into the finally
block so that restoration always happens even if mount/update/unmount (e.g.,
mount, unmount, update, insert, moveLink) throws; keep the same scope and ensure
any early returns (if present) still restore by returning inside the try while
the finally restores prevOwner.

In `@packages/runtime-vapor/src/fragment.ts`:
- Around line 197-213: Wrap the call to this.scope.run(render) and the
subsequent context-restoration in a try/finally: capture prevOwner (from
setCurrentRenderingInstance), prevCtx (from setCurrentKeepAliveCtx),
prevBranchKey (from keepAliveCtx.setCurrentBranchKey) and prev (from
setCurrentInstance(instance)) before calling this.scope.run(render), then in a
finally block always restore those contexts by calling setCurrentInstance(prev),
keepAliveCtx.setCurrentBranchKey(prevBranchKey) (if used),
setCurrentKeepAliveCtx(prevCtx), and setCurrentRenderingInstance(prevOwner) so
context cannot leak if render throws.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57e6da1 and 1e9a133.

📒 Files selected for processing (10)
  • packages/runtime-core/src/compat/renderFn.ts
  • packages/runtime-core/src/componentCurrentInstance.ts
  • packages/runtime-core/src/componentRenderContext.ts
  • packages/runtime-core/src/index.ts
  • packages/runtime-core/src/vnode.ts
  • packages/runtime-vapor/__tests__/apiCreateDynamicComponent.spec.ts
  • packages/runtime-vapor/src/apiCreateFor.ts
  • packages/runtime-vapor/src/component.ts
  • packages/runtime-vapor/src/componentSlots.ts
  • packages/runtime-vapor/src/fragment.ts

@edison1105 edison1105 merged commit a779531 into minor Feb 26, 2026
36 of 41 checks passed
@edison1105 edison1105 deleted the edison/fix/14474 branch February 26, 2026 01:42
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.

Can't resolveDynamicComponent in component slots

1 participant