From: Evan You Date: Fri, 6 Dec 2024 15:10:41 +0000 (+0800) Subject: wip: avoid proxy when slots are static X-Git-Tag: v3.6.0-alpha.1~16^2~215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8331aa43c4c2ff18f89cc9b1e13a2ca7256d5f17;p=thirdparty%2Fvuejs%2Fcore.git wip: avoid proxy when slots are static --- diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts index 79f05c9cd6..bb2e21db0d 100644 --- a/packages/runtime-vapor/src/component.ts +++ b/packages/runtime-vapor/src/component.ts @@ -35,7 +35,7 @@ import { setClass, setDynamicProp } from './dom/prop' import { type RawSlots, type StaticSlots, - slotsProxyHandlers, + dynamicSlotsProxyHandlers, } from './componentSlots' export { currentInstance } from '@vue/runtime-dom' @@ -257,7 +257,11 @@ export class VaporComponentInstance implements GenericComponentInstance { } // init slots - this.slots = rawSlots ? new Proxy(rawSlots, slotsProxyHandlers) : EMPTY_OBJ + this.slots = rawSlots + ? rawSlots.$ + ? new Proxy(rawSlots, dynamicSlotsProxyHandlers) + : rawSlots + : EMPTY_OBJ if (__DEV__) { // validate props diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts index a77ade4f3c..3a37abee24 100644 --- a/packages/runtime-vapor/src/componentSlots.ts +++ b/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 DynamicSlotFn = () => DynamicSlot | DynamicSlot[] -export const slotsProxyHandlers: ProxyHandler = { +export const dynamicSlotsProxyHandlers: ProxyHandler = { get: getSlot, has: (target, key: string) => !!getSlot(target, key), getOwnPropertyDescriptor(target, key: string) {