From 4fdb550e9ee05062ae4587904eef9afb97b005c2 Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 13 Jun 2025 09:42:13 +0800 Subject: [PATCH 1/4] fix(runtime-core): make cache indexes marker non-enumerable in initSlots --- packages/runtime-core/src/componentSlots.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 3812695431e..6114f6c86cf 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -193,6 +193,10 @@ export const initSlots = ( ): void => { const slots = (instance.slots = createInternalObject()) if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) { + const cacheIndexes = (children as RawSlots).__ + // make cache indexes marker non-enumerable + if (cacheIndexes) def(slots, '__', cacheIndexes, true) + const type = (children as RawSlots)._ if (type) { assignSlots(slots, children as Slots, optimized) From 61d75e1ab925f98c5450a9983cf50a770cbd038e Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 13 Jun 2025 10:17:08 +0800 Subject: [PATCH 2/4] test: add test --- .../runtime-core/__tests__/componentSlots.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/runtime-core/__tests__/componentSlots.spec.ts b/packages/runtime-core/__tests__/componentSlots.spec.ts index 2cf50b964bf..5a72d8e11bb 100644 --- a/packages/runtime-core/__tests__/componentSlots.spec.ts +++ b/packages/runtime-core/__tests__/componentSlots.spec.ts @@ -6,6 +6,7 @@ import { nodeOps, ref, render, + useSlots, } from '@vue/runtime-test' import { createBlock, normalizeVNode } from '../src/vnode' import { createSlots } from '../src/helpers/createSlots' @@ -42,6 +43,19 @@ describe('component: slots', () => { expect(slots).toMatchObject({}) }) + test('initSlots: ensure compiler marker non-enumerable', () => { + const Comp = { + render() { + const slots = useSlots() + // should not have compiler marker(`_` and `__`) + expect(Object.keys(slots)).toMatchObject(['foo']) + return h('div') + }, + } + const slots = { foo: () => {}, _: 1, __: [1] } + render(createBlock(Comp, null, slots), nodeOps.createElement('div')) + }) + test('initSlots: should normalize object slots (when value is null, string, array)', () => { const { slots } = renderWithSlots({ _inner: '_inner', From f27f03ec0434e9470c4490d2f49d5799a6570f2b Mon Sep 17 00:00:00 2001 From: edison Date: Fri, 13 Jun 2025 10:23:22 +0800 Subject: [PATCH 3/4] Update packages/runtime-core/__tests__/componentSlots.spec.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- packages/runtime-core/__tests__/componentSlots.spec.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/__tests__/componentSlots.spec.ts b/packages/runtime-core/__tests__/componentSlots.spec.ts index 5a72d8e11bb..d05f4befb9f 100644 --- a/packages/runtime-core/__tests__/componentSlots.spec.ts +++ b/packages/runtime-core/__tests__/componentSlots.spec.ts @@ -47,8 +47,14 @@ describe('component: slots', () => { const Comp = { render() { const slots = useSlots() - // should not have compiler marker(`_` and `__`) - expect(Object.keys(slots)).toMatchObject(['foo']) + // Only user-defined slots should be enumerable + expect(Object.keys(slots)).toEqual(['foo']) + + // Internal compiler markers must still exist but be non-enumerable + expect(slots).toHaveProperty('_') + expect(Object.getOwnPropertyDescriptor(slots, '_')!.enumerable).toBe(false) + expect(slots).toHaveProperty('__') + expect(Object.getOwnPropertyDescriptor(slots, '__')!.enumerable).toBe(false) return h('div') }, } From 0c82d7c4d62b427b0fb3af58430efaa6632ff46a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 13 Jun 2025 02:24:12 +0000 Subject: [PATCH 4/4] [autofix.ci] apply automated fixes --- packages/runtime-core/__tests__/componentSlots.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/__tests__/componentSlots.spec.ts b/packages/runtime-core/__tests__/componentSlots.spec.ts index d05f4befb9f..ad87e5367d7 100644 --- a/packages/runtime-core/__tests__/componentSlots.spec.ts +++ b/packages/runtime-core/__tests__/componentSlots.spec.ts @@ -52,9 +52,13 @@ describe('component: slots', () => { // Internal compiler markers must still exist but be non-enumerable expect(slots).toHaveProperty('_') - expect(Object.getOwnPropertyDescriptor(slots, '_')!.enumerable).toBe(false) + expect(Object.getOwnPropertyDescriptor(slots, '_')!.enumerable).toBe( + false, + ) expect(slots).toHaveProperty('__') - expect(Object.getOwnPropertyDescriptor(slots, '__')!.enumerable).toBe(false) + expect(Object.getOwnPropertyDescriptor(slots, '__')!.enumerable).toBe( + false, + ) return h('div') }, }