8000 feat(runtime-vapor): support functional slot in vdom component by zhiyuanzmj · Pull Request #13571 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

feat(runtime-vapor): support functional slot in vdom component #13571

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000 Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(runtime-vapor): support functional slot in vdom component
  • Loading branch information
zhiyuanzmj committed Jul 5, 2025
commit a359aff61a705546a3cf3b066c5b5aca128c31b2
2 changes: 1 addition & 1 deletion packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function renderSlot(
let slot = slots[name]

// vapor slots rendered in vdom
if (slot && slots._vapor) {
if (slot && (slot as any).__vapor) {
const ret = (openBlock(), createBlock(VaporSlot, props))
ret.vs = { slot, fallback }
return ret
Expand Down
33 changes: 31 additions & 2 deletions packages/runtime-vapor/__tests__/vdomInterop.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, h } from '@vue/runtime-dom'
import { defineComponent, h, renderSlot } from '@vue/runtime-dom'
import { makeInteropRender } from './_utils'
import { createComponent, defineVaporComponent } from '../src'

Expand All @@ -9,7 +9,36 @@ describe('vdomInterop', () => {

describe.todo('emit', () => {})

describe.todo('slots', () => {})
describe('slots', () => {
test('functional slot', () => {
const VDomChild = defineComponent({
setup(_, { slots }) {
return () => renderSlot(slots, 'default')
},
})

const VaporChild = defineVaporComponent({
setup() {
return createComponent(
VDomChild as any,
null,
{
default: () => document.createTextNode('default slot'),
},
true,
)
},
})

const { html } = define({
setup() {
return () => h(VaporChild as any)
},
}).render()

expect(html()).toBe('default slot')
})
})

describe.todo('provide', () => {})

Expand Down
16 changes: 11 additions & 5 deletions packages/runtime-vapor/src/vdomInterop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,17 @@ const vaporSlotPropsProxyHandler: ProxyHandler<

const vaporSlotsProxyHandler: ProxyHandler<any> = {
get(target, key) {
if (key === '_vapor') {
return target
} else {
return target[key]
}
const fn = target[key]
return isFunction(fn)
? new Proxy(fn, {
get(fnTarget, fnKey) {
if (fnKey === '__vapor') {
return true
}
return fnTarget[fnKey]
},
})
: fn
},
}

Expand Down
0