Skip to content

Commit fe3a998

Browse files
authored
fix(runtime-vapor): preserve correct parent instance for slotted content (#14095)
1 parent 5bfda8c commit fe3a998

File tree

13 files changed

+226
-150
lines changed

13 files changed

+226
-150
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ exports[`compiler: transform <slot> outlets > slot outlet with scopeId and slott
115115
"import { createSlot as _createSlot } from 'vue';
116116
117117
export function render(_ctx) {
118-
const n0 = _createSlot("default", null, null, undefined, true)
118+
const n0 = _createSlot("default", null, null, true)
119119
return n0
120120
}"
121121
`;

packages/compiler-vapor/src/generators/slotOutlet.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export function genSlotOutlet(
3030
nameExpr,
3131
genRawProps(oper.props, context) || 'null',
3232
fallbackArg,
33-
noSlotted && 'undefined', // instance
3433
noSlotted && 'true', // noSlotted
3534
),
3635
)

packages/runtime-core/src/apiCreateApp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ export interface VaporInteropInterface {
212212
transition: TransitionHooks,
213213
): void
214214

215-
vdomMount: (component: ConcreteComponent, props?: any, slots?: any) => any
215+
vdomMount: (
216+
component: ConcreteComponent,
217+
parentComponent: any,
218+
props?: any,
219+
slots?: any,
220+
) => any
216221
vdomUnmount: UnmountComponentFn
217222
vdomSlot: (
218223
slots: any,

packages/runtime-vapor/__tests__/apiInject.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import {
1212
} from '@vue/runtime-dom'
1313
import {
1414
createComponent,
15+
createSlot,
1516
createTextNode,
1617
createVaporApp,
18+
defineVaporComponent,
1719
renderEffect,
20+
withVaporCtx,
1821
} from '../src'
1922
import { makeRender } from './_utils'
2023
import { setElementText } from '../src/dom/prop'
@@ -368,6 +371,32 @@ describe('api: provide/inject', () => {
368371
expect(host.innerHTML).toBe('')
369372
})
370373

374+
it('should work with slots', () => {
375+
const Parent = defineVaporComponent({
376+
setup() {
377+
provide('test', 'hello')
378+
return createSlot('default', null)
379+
},
380+
})
381+
382+
const Child = defineVaporComponent({
383+
setup() {
384+
const test = inject('test')
385+
return createTextNode(toDisplayString(test))
386+
},
387+
})
388+
389+
const { host } = define({
390+
setup() {
391+
return createComponent(Parent, null, {
392+
default: withVaporCtx(() => createComponent(Child)),
393+
})
394+
},
395+
}).render()
396+
397+
expect(host.innerHTML).toBe('hello<!--slot-->')
398+
})
399+
371400
describe('hasInjectionContext', () => {
372401
it('should be false outside of setup', () => {
373402
expect(hasInjectionContext()).toBe(false)

packages/runtime-vapor/__tests__/apiSetupContext.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
setDynamicProps,
1111
setText,
1212
template,
13+
withVaporCtx,
1314
} from '../src'
1415
import { nextTick, reactive, ref, watchEffect } from '@vue/runtime-dom'
1516
import { makeRender } from './_utils'
@@ -113,11 +114,11 @@ describe('api: setup context', () => {
113114
inheritAttrs: false,
114115
setup(_: any, { attrs }: any) {
115116
const n0 = createComponent(Wrapper, null, {
116-
default: () => {
117+
default: withVaporCtx(() => {
117118
const n0 = template('<div>')() as HTMLDivElement
118119
renderEffect(() => setDynamicProps(n0, [attrs]))
119120
return n0
120-
},
121+
}),
121122
})
122123
return n0
123124
},

packages/runtime-vapor/__tests__/componentAttrs.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
setProp,
1111
setStyle,
1212
template,
13+
withVaporCtx,
1314
} from '../src'
1415
import { makeRender } from './_utils'
1516
import { stringifyStyle } from '@vue/shared'
@@ -286,10 +287,10 @@ describe('attribute fallthrough', () => {
286287
() => 'button',
287288
null,
288289
{
289-
default: () => {
290+
default: withVaporCtx(() => {
290291
const n0 = createSlot('default', null)
291292
return n0
292-
},
293+
}),
293294
},
294295
true,
295296
)

0 commit comments

Comments
 (0)