浏览代码

wip: avoid proxy when slots are static

Evan You 1 年之前
父节点
当前提交
8331aa43c4
共有 2 个文件被更改,包括 7 次插入3 次删除
  1. 6 2
      packages/runtime-vapor/src/component.ts
  2. 1 1
      packages/runtime-vapor/src/componentSlots.ts

+ 6 - 2
packages/runtime-vapor/src/component.ts

@@ -35,7 +35,7 @@ import { setClass, setDynamicProp } from './dom/prop'
 import {
 import {
   type RawSlots,
   type RawSlots,
   type StaticSlots,
   type StaticSlots,
-  slotsProxyHandlers,
+  dynamicSlotsProxyHandlers,
 } from './componentSlots'
 } from './componentSlots'
 
 
 export { currentInstance } from '@vue/runtime-dom'
 export { currentInstance } from '@vue/runtime-dom'
@@ -257,7 +257,11 @@ export class VaporComponentInstance implements GenericComponentInstance {
     }
     }
 
 
     // init slots
     // init slots
-    this.slots = rawSlots ? new Proxy(rawSlots, slotsProxyHandlers) : EMPTY_OBJ
+    this.slots = rawSlots
+      ? rawSlots.$
+        ? new Proxy(rawSlots, dynamicSlotsProxyHandlers)
+        : rawSlots
+      : EMPTY_OBJ
 
 
     if (__DEV__) {
     if (__DEV__) {
       // validate props
       // validate props

+ 1 - 1
packages/runtime-vapor/src/componentSlots.ts

@@ -11,7 +11,7 @@ export type Slot = (...args: any[]) => Block
 export type DynamicSlot = { name: string; fn: Slot }
 export type DynamicSlot = { name: string; fn: Slot }
 export type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
 export type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
 
 
-export const slotsProxyHandlers: ProxyHandler<RawSlots> = {
+export const dynamicSlotsProxyHandlers: ProxyHandler<RawSlots> = {
   get: getSlot,
   get: getSlot,
   has: (target, key: string) => !!getSlot(target, key),
   has: (target, key: string) => !!getSlot(target, key),
   getOwnPropertyDescriptor(target, key: string) {
   getOwnPropertyDescriptor(target, key: string) {