Skip to content

fix(runtime-core): normalize function children for elements and Teleport#9108

Merged
edison1105 merged 15 commits into
vuejs:mainfrom
Alfred-Skyblue:fix-vnode-children
Jun 25, 2026
Merged

fix(runtime-core): normalize function children for elements and Teleport#9108
edison1105 merged 15 commits into
vuejs:mainfrom
Alfred-Skyblue:fix-vnode-children

Conversation

@Alfred-Skyblue

@Alfred-Skyblue Alfred-Skyblue commented Sep 1, 2023

Copy link
Copy Markdown
Member

fixed #9107

When the children of the Element or Teleport component are a function, we should execute this function and use its return value as the children.

Palyground

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of function children for elements and Teleport, so they now render consistently instead of being treated as slot content.
    • Expanded type and runtime coverage for function-based children to better validate expected behavior across common usage patterns.

@github-actions

github-actions Bot commented Sep 1, 2023

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 106 kB (+43 B) 40.2 kB (+5 B) 36.1 kB (+33 B)
vue.global.prod.js 165 kB (+43 B) 60.2 kB (+7 B) 53.5 kB (+31 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.8 kB (+43 B) 19 kB (+14 B) 17.4 kB (+12 B)
createApp 56.9 kB (+41 B) 22 kB (+14 B) 20.1 kB (+3 B)
createSSRApp 61.2 kB (+43 B) 23.8 kB (+10 B) 21.7 kB (+8 B)
defineCustomElement 63.1 kB (+43 B) 23.9 kB (+12 B) 21.8 kB (+17 B)
overall 71.7 kB (+43 B) 27.4 kB (+13 B) 25 kB (+54 B)

@Alfred-Skyblue Alfred-Skyblue marked this pull request as ready for review September 1, 2023 04:57
@Alfred-Skyblue Alfred-Skyblue changed the title fix(h): fix rendering error when children is a function fix(runtime-core): fix rendering error when children is a function Sep 1, 2023
@Alfred-Skyblue Alfred-Skyblue changed the title fix(runtime-core): fix rendering error when children is a function fix(runtime-core): fix rendering error when Element and Teleport children are function Sep 1, 2023

@baiwusanyu-c baiwusanyu-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM
cc/ @sxzz

@sxzz sxzz added ready for review This PR requires more reviews scope: slots labels Sep 1, 2023
@pikax

pikax commented Oct 13, 2023

Copy link
Copy Markdown
Member

Based on the comment on h.ts

/*
// type only
h('div')

// type + props
h('div', {})

// type + omit props + children
// Omit props does NOT support named slots
h('div', []) // array
h('div', 'foo') // text
h('div', h('br')) // vnode
h(Component, () => {}) // default slot

// type + props + children
h('div', {}, []) // array
h('div', {}, 'foo') // text
h('div', {}, h('br')) // vnode
h(Component, {}, () => {}) // default slot
h(Component, {}, {}) // named slots

// named slots without props requires explicit `null` to avoid ambiguity
h(Component, null, {})
**/

This is working as intended, this PR is requesting to change the API.

The only case where we could argue otherwise would be Teleport not supporting the function.

If the intention is for functions to be supported across the board h.ts needs to be updated

@Alfred-Skyblue

Copy link
Copy Markdown
Member Author

@pikax
I believe we should offer comprehensive support for this, so that we can pass a function in situations where it's uncertain whether tag represents a component or an HTMLElement:

let tag: string | Component = 'div'

h(tag, {}, () => 'hello world')

If we only support Component, the above use case would result in the loss of child elements when dealing with HTMLElement or Teleport

@pikax

pikax commented Oct 16, 2023

Copy link
Copy Markdown
Member

I believe we should offer comprehensive support for this, so that we can pass a function in situations where it's uncertain whether tag represents a component or an HTMLElement:

I'm not saying otherwise, just saying this is a change of the current API, changing API is more cumbersome, there's typescript that needs to be updated which this PR hasn't done it, there's RFC.

I would argue logically it makes sense why Element to not support functions, the reason I say that is because functions are a sugar for default slot, but Element doesn't have slots per se, is just children, because slots implies a vue component.

@Alfred-Skyblue

Copy link
Copy Markdown
Member Author

export function h(
type: typeof Teleport,
props: RawProps & TeleportProps,
children: RawChildren | RawSlots
): VNode

@pikax I see there are overloads for Teleport here.

@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Sep 12, 2024
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Function children for element and Teleport vnodes now follow the slot-object normalization path, and the vnode and h() tests were updated to cover component, element, and Teleport cases.

Changes

Function children normalization

Layer / File(s) Summary
normalizeChildren branch
packages/runtime-core/src/vnode.ts
normalizeChildren now handles function children on element and Teleport vnodes by normalizing through a { default: children } shape and returning early.
Runtime and dts tests
packages/runtime-core/__tests__/vnode.spec.ts, packages-private/dts-test/h.test-d.ts
The vnode runtime tests and h() type tests now cover function children for component slots, element text children, and Teleport children.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

scope: teleport, :hammer: p3-minor-bug

Poem

A bunny hopped through vnode glade,
Where function-children paths were made.
div and Teleport now hum along,
With slot-shaped hops and a tiny song.
🐇🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The changes and tests address the reported rendering bug for function children on elements and Teleport, matching issue #9107.
Out of Scope Changes check ✅ Passed The diff stays focused on vnode normalization and related tests, with no unrelated feature work.
Title check ✅ Passed The title clearly matches the main change: runtime-core normalization of function children for elements and Teleport.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 04028bc

@edison1105 edison1105 changed the title fix(runtime-core): fix rendering error when Element and Teleport children are function fix(runtime-core): normalize function children for elements and Teleport Jun 25, 2026
@edison1105 edison1105 removed the ready for review This PR requires more reviews label Jun 25, 2026
@edison1105

Copy link
Copy Markdown
Member

/ecosystem-ci run

@vue-bot

vue-bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 merged commit 2f374cd into vuejs:main Jun 25, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge The PR is ready to be merged. scope: slots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<component> tag render problem

6 participants