Skip to content

Commit c9f10be

Browse files
committed
refactor(runtime-core): extract key/ref normalization logic
1 parent ad2b940 commit c9f10be

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/runtime-core/src/vnode.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ const createVNodeWithArgsTransform = (
239239

240240
export const InternalObjectKey = `__vInternal`
241241

242+
const normalizeKey = ({ key }: VNodeProps): VNode['key'] =>
243+
key != null ? key : null
244+
245+
const normalizeRef = ({ ref }: VNodeProps): VNode['ref'] =>
246+
(ref != null
247+
? isArray(ref)
248+
? ref
249+
: [currentRenderingInstance!, ref]
250+
: null) as any
251+
242252
export const createVNode = (__DEV__
243253
? createVNodeWithArgsTransform
244254
: _createVNode) as typeof _createVNode
@@ -312,11 +322,8 @@ function _createVNode(
312322
_isVNode: true,
313323
type,
314324
props,
315-
key: props && props.key != null ? props.key : null,
316-
ref:
317-
props && props.ref != null
318-
? [currentRenderingInstance!, props.ref]
319-
: null,
325+
key: props && normalizeKey(props),
326+
ref: props && normalizeRef(props),
320327
scopeId: currentScopeId,
321328
children: null,
322329
component: null,
@@ -373,13 +380,8 @@ export function cloneVNode<T, U>(
373380
_isVNode: true,
374381
type: vnode.type,
375382
props,
376-
key: props && props.key != null ? props.key : null,
377-
ref:
378-
props && props.ref != null
379-
? isArray(props.ref)
380-
? props.ref
381-
: [currentRenderingInstance!, props.ref]
382-
: null,
383+
key: props && normalizeKey(props),
384+
ref: props && normalizeRef(props),
383385
scopeId: vnode.scopeId,
384386
children: vnode.children,
385387
target: vnode.target,

0 commit comments

Comments
 (0)