Repository: vuejs/core (TypeScript)

Issue:
Slots behave differently from Vue 3.5.14, breaks code that worked in 3.5.13
### Vue version

3.5.14+

### Link to minimal reproduction

https://github.com/uandco/vuejs-314-slots-bug

### Steps to reproduce

Run `npm install`
Run `vite`

Go to http://localhost:8080

Page displays OK

Change `"vue": "3.5.13"` to `"vue": "3.5.14"` or later
Run `npm install`
Run `vite`

Go to http://localhost:8080

Page doesn't display, throws:

```
uuFaq.vue:5 Uncaught TypeError: item is not a function
    at uuFaq.vue:5:36
    at Proxy._sfc_render (uuFaq.vue:1:1)
```

### What is expected?

Iterating slots and extracting props from them should work as it did in Vue 3.5.13 and below

### What is actually happening?

It doesn't work when loading the page, getting this:

```
TypeError: item is not a function
    at uuFaq.vue:5:36
    at renderList (runtime-core.esm-bundler.js:2935:18)
    at Proxy._sfc_render (uuFaq.vue:1:1)
```

But changing something in the `App.vue` and letting Vite hot-reload it makes it work.

It never works for built assets though.

### System Info

```shell

```

### Any additional comments?

It might be related to https://github.com/vuejs/core/commit/5d166f3796a03a497435fc079c6a83a4e9c6cf52


Discussion:
I tried to reproduce this in the Playground, but it seems to need `whitespace: 'preserve'`, which isn't available in the main Playground. I added `whitespace: 'preserve'` to a local copy of the Playground and was able to observe the same problem described here.
> I tried to reproduce this in the Playground, but it seems to need `whitespace: 'preserve'`, which isn't available in the main Playground. I added `whitespace: 'preserve'` to a local copy of the Playground and was able to observe the same problem described here.

Ah, that's a very good catch, I tried to reproduce in the playground too but couldn't, and didnt make the link with `whitespace: 'preserve'`. It is indeed what is triggering the bug!
Here is a minimal reproduction
- [Playground](https://play.vuejs.org/#eNp9Uk1P4zAQ/SuzviSVuolWu6duyqeQgAMgytGXkk5at44d2U4pivLfGdttoAg42X7vzZux/Tp23jTZtkU2YYUtjWgcWHRtc8KVqBttHHRgsIIeKqNrSEiaDNSlrps9nuX+4J2I5qrUypLTSr/A1NenzrQ44qrIYxOyp4PDupFzh3QCKJ5b57SCs1KKcjPlbF/9y6+cnXRd9DuF5FosMIEJJDMCEuj7Io/F0SiMtf0tqr0JFXtIK1SuCHOSrsg/dGdj5izNXIlltrZa0Wt03oqzktRCorlvnKA7cTaBwHhuLqV+uQ2Yv974gJcrLDdf4Gu78xhnDwYtmi1yNnBubpboIn01u8Md7Qey1otWkvoH8hGtlq2fMcouWrWgsT/owrQ34eOEWj7Zq51DZQ+X8oN6ZR/0nNFH+of67urv4/7N/oU6rnp6xUMIfopTa3EmtbNHmfo/ZCZQ00GVUmo8oyVmUi/T++c1li7b4KtNg3Z0HKtPoVr9CSvtFmJLoai0oVSkglRjIJMRCBV7UkqikrQegIma10hiUhFHLQg8mOXkFhvkocNxmvo31bIdkA==)



Patch:
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)


Test patch:
diff --git a/packages/runtime-core/__tests__/componentSlots.spec.ts b/packages/runtime-core/__tests__/componentSlots.spec.ts
index 2cf50b964bf..ad87e5367d7 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,29 @@ describe('component: slots', () => {
     expect(slots).toMatchObject({})
   })
 
+  test('initSlots: ensure compiler marker non-enumerable', () => {
+    const Comp = {
+      render() {
+        const slots = useSlots()
+        // 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')
+      },
+    }
+    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',