Skip to content

fix(runtime-vapor): properly set ref on dynamic component + vdom component#14496

Merged
edison1105 merged 2 commits intovuejs:minorfrom
jackma9604:fix/TemplateRef
Mar 2, 2026
Merged

fix(runtime-vapor): properly set ref on dynamic component + vdom component#14496
edison1105 merged 2 commits intovuejs:minorfrom
jackma9604:fix/TemplateRef

Conversation

@jackma9604
Copy link

@jackma9604 jackma9604 commented Feb 28, 2026

Problem Description

In vapor mode, dynamic components cannot obtain references to vdom components

Version

v3.6.0-beta.7

Link to minimal reproduction

Playground

What is expected?

Console prints "comp"

What is actually happening?

Console prints "undefined"

Summary by CodeRabbit

  • New Features

    • Added template ref setter API for enhanced component reference management.
  • Tests

    • New test coverage for dynamic components with nested component integration and template ref functionality.
  • Refactor

    • Improved template reference handling with centralized logic and optimized control flow for better performance.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 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:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 28, 2026

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: d5bc92d

@github-actions
Copy link

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.7 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.6 kB 30.7 kB 27.8 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.4 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

@edison1105 edison1105 changed the title fix(runtime-vapor): fix the issue where dynamic components cannot obt… fix(runtime-vapor): properly set ref on dynamic component + vdom component Mar 2, 2026
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.

🧹 Nitpick comments (1)
packages/runtime-vapor/__tests__/vdomInterop.spec.ts (1)

738-769: Consider scoping vdomRef inside the test for better isolation.

The test correctly validates the fix, but vdomRef is declared outside VaporChild (line 758) and referenced inside the component's render function (lines 748, 753). While this works, moving vdomRef declaration inside the test block before VaporChild definition would improve clarity about the data flow and prevent potential issues if tests are run in parallel or if another test accidentally references this variable.

♻️ Suggested refactor for better scoping
     it('dynamic component includes vdom component', async () => {
+      const vdomRef = ref<any>(null)
+
       const VdomChild = defineComponent({
         setup(_, { expose }) {
           expose({ name: 'vdomChild' })
           return () => h('div', 'vdom child')
         },
       })

       const VaporChild = defineVaporComponent({
         setup() {
           return { vdomRef }
         },
         render() {
           const setRef = createTemplateRefSetter()
           const n0 = createDynamicComponent(() => VdomChild)
           setRef(n0, vdomRef, false, 'vdomRef')
           return n0
         },
       })

-      const vdomRef = ref<any>(null)
-
       define({
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/__tests__/vdomInterop.spec.ts` around lines 738 - 769,
The vdomRef used by VaporChild and its render (symbols: vdomRef, VaporChild,
VdomChild) is declared after VaporChild which reduces test isolation; move the
const vdomRef = ref<any>(null) declaration to the top of this test block
immediately before defining VaporChild (and ensure VaporChild’s render and any
setRef calls still reference that local vdomRef) so the ref is scoped to the
test and not shared across tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/runtime-vapor/__tests__/vdomInterop.spec.ts`:
- Around line 738-769: The vdomRef used by VaporChild and its render (symbols:
vdomRef, VaporChild, VdomChild) is declared after VaporChild which reduces test
isolation; move the const vdomRef = ref<any>(null) declaration to the top of
this test block immediately before defining VaporChild (and ensure VaporChild’s
render and any setRef calls still reference that local vdomRef) so the ref is
scoped to the test and not shared across tests.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86d3b64 and 21d18bd.

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

@edison1105 edison1105 merged commit e05c850 into vuejs:minor Mar 2, 2026
24 of 26 checks passed
@jackma9604 jackma9604 deleted the fix/TemplateRef branch March 2, 2026 03:39
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.

2 participants