Skip to content

fix(runtime-core): fix rendering error when Element and Teleport children are function #9108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Alfred-Skyblue
Copy link
Member

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

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

@github-actions
Copy link

github-actions bot commented Sep 1, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 89.3 kB (+2.19 kB) 34 kB (+838 B) 30.6 kB (+719 B)
vue.global.prod.js 146 kB (+13.2 kB) 53.2 kB (+3.23 kB) 47.5 kB (+2.74 kB)

Usages

Name Size Gzip Brotli
createApp 49.7 kB (+1.38 kB) 19.5 kB (+448 B) 17.8 kB (+378 B)
createSSRApp 53.1 kB (+1.47 kB) 20.8 kB (+468 B) 19 kB (+471 B)
defineCustomElement 52 kB (+1.27 kB) 20.2 kB (+420 B) 18.4 kB (+336 B)
overall 63.2 kB (+1.48 kB) 24.4 kB (+523 B) 22.2 kB (+426 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
Copy link
Member

@baiwusanyu-c baiwusanyu-c left a comment

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
Copy link
Member

pikax commented Oct 13, 2023

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
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
Copy link
Member

pikax commented Oct 16, 2023

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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review This PR requires more reviews ready to merge The PR is ready to be merged. scope: slots
Projects
Status: Waiting
Development

Successfully merging this pull request may close these issues.

<component> tag render problem
5 participants