import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig'
import { DeprecationTypes } from './compat/compatConfig'
import { shouldSkipAttr } from './compat/attrsFallthrough'
+import { createInternalObject } from './internalObject'
export type ComponentPropsOptions<P = Data> =
| ComponentObjectPropsOptions<P>
export type NormalizedProps = Record<string, NormalizedProp>
export type NormalizedPropsOptions = [NormalizedProps, string[]] | []
-/**
- * Used during vnode props normalization to check if the vnode props is the
- * attrs object of a component via `Object.getPrototypeOf`. This is more
- * performant than defining a non-enumerable property.
- */
-export const attrsProto = {}
-
export function initProps(
instance: ComponentInternalInstance,
rawProps: Data | null,
isSSR = false,
) {
const props: Data = {}
- const attrs: Data = Object.create(attrsProto)
+ const attrs: Data = createInternalObject()
instance.propsDefaults = Object.create(null)
import { toRaw } from '@vue/reactivity'
import { trigger } from '@vue/reactivity'
import { TriggerOpTypes } from '@vue/reactivity'
+import { createInternalObject } from './internalObject'
export type Slot<T extends any = any> = (
...args: IfAny<T, any[], [T] | (T extends undefined ? [] : never)>
} else {
normalizeObjectSlots(
children as RawSlots,
- (instance.slots = {}),
+ (instance.slots = createInternalObject()),
instance,
)
}
} else {
- instance.slots = {}
+ instance.slots = createInternalObject()
if (children) {
normalizeVNodeSlots(instance, children)
}
--- /dev/null
+/**
+ * Used during vnode props/slots normalization to check if the vnode props/slots
+ * are the internal attrs / slots object of a component via
+ * `Object.getPrototypeOf`. This is more performant than defining a
+ * non-enumerable property. (one of the optimizations done for ssr-benchmark)
+ */
+const internalObjectProto = Object.create(null)
+
+export const createInternalObject = () => Object.create(internalObjectProto)
+
+export const isInternalObject = (obj: object) =>
+ Object.getPrototypeOf(obj) === internalObjectProto
import { defineLegacyVNodeProperties } from './compat/renderFn'
import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
import type { ComponentPublicInstance } from './componentPublicInstance'
-import { attrsProto } from './componentProps'
+import { isInternalObject } from './internalObject'
export const Fragment = Symbol.for('v-fgt') as any as {
__isFragment: true
export function guardReactiveProps(props: (Data & VNodeProps) | null) {
if (!props) return null
- return isProxy(props) || Object.getPrototypeOf(props) === attrsProto
- ? extend({}, props)
- : props
+ return isProxy(props) || isInternalObject(props) ? extend({}, props) : props
}
export function cloneVNode<T, U>(
} else {
type = ShapeFlags.SLOTS_CHILDREN
const slotFlag = (children as RawSlots)._
- if (!slotFlag) {
+ if (!slotFlag && !isInternalObject(children)) {
// if slots are not normalized, attach context instance
// (compiled / normalized slots already have context)
;(children as RawSlots)._ctx = currentRenderingInstance