From: Ivan Date: Fri, 16 Jan 2026 01:56:49 +0000 (+0300) Subject: fix(runtime-vapor): handle component scopeid on nested slot (#14326) X-Git-Tag: v3.6.0-beta.4~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=732479182ab01706d95d3108f95e93fd07a44d74;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-vapor): handle component scopeid on nested slot (#14326) Co-authored-by: daiwei --- diff --git a/packages/runtime-vapor/__tests__/scopeId.spec.ts b/packages/runtime-vapor/__tests__/scopeId.spec.ts index 04b54e7d1c..646a50f619 100644 --- a/packages/runtime-vapor/__tests__/scopeId.spec.ts +++ b/packages/runtime-vapor/__tests__/scopeId.spec.ts @@ -310,6 +310,70 @@ describe('scopeId', () => { ``, ) }) + + test('nested components with slots', async () => { + const Child = defineVaporComponent({ + setup() { + const n0 = template('
')() as any + setInsertionState(n0, null, true) + createSlot('default') + return n0 + }, + }) + const Parent = defineVaporComponent({ + __scopeId: 'data-v-parent', + setup() { + const n3 = createComponent( + Child, + null, + { + default: withVaporCtx(() => { + const n2 = createComponent( + Child, + null, + { + default: withVaporCtx(() => { + const n1 = createComponent( + Child, + null, + { + default: () => { + const t0 = template('test')() as any + return t0 + }, + }, + true, + ) + return n1 + }), + }, + true, + ) + return n2 + }), + }, + true, + ) + return n3 + }, + }) + + const { host } = define({ + __scopeId: 'app', + setup() { + return createComponent(Parent) + }, + }).render() + + expect(host.innerHTML).toBe( + `
` + + `
` + + `
test` + + `
` + + `
` + + `
`, + ) + }) }) describe('vdom interop', () => { diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts index 36cb9f260f..11f091cbdb 100644 --- a/packages/runtime-vapor/src/componentSlots.ts +++ b/packages/runtime-vapor/src/componentSlots.ts @@ -159,7 +159,7 @@ export function getScopeOwner(): VaporComponentInstance | null { * 2. Elements inherit the slot owner's scopeId */ export function withVaporCtx(fn: Function): BlockFn { - const owner = currentInstance as VaporComponentInstance + const owner = getScopeOwner() return (...args: any[]) => { const prevOwner = setCurrentSlotOwner(owner) try {