From d8f0e211ff6154f4a2e00281d93171c94460e247 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Thu, 3 Oct 2024 17:03:11 +0200 Subject: [PATCH] Make oldVNode monomorphic --- src/create-element.js | 4 ++++ src/diff/children.js | 8 ++++---- src/render.js | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/create-element.js b/src/create-element.js index 66898b22243..b5855678723 100644 --- a/src/create-element.js +++ b/src/create-element.js @@ -1,5 +1,6 @@ import { slice } from './util'; import options from './options'; +import { EMPTY_OBJ } from './constants'; let vnodeId = 0; @@ -84,6 +85,9 @@ export function createVNode(type, props, key, ref, original) { return vnode; } +// @ts-ignore +export const EMPTY_VNODE = createVNode(null, EMPTY_OBJ); + export function createRef() { return { current: null }; } diff --git a/src/diff/children.js b/src/diff/children.js index ba2730478c1..59b668b3097 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -1,6 +1,6 @@ import { diff, unmount, applyRef } from './index'; -import { createVNode, Fragment } from '../create-element'; -import { EMPTY_OBJ, EMPTY_ARR, INSERT_VNODE, MATCHED } from '../constants'; +import { createVNode, Fragment, EMPTY_VNODE } from '../create-element'; +import { EMPTY_ARR, INSERT_VNODE, MATCHED } from '../constants'; import { isArray } from '../util'; import { getDomSibling } from '../component'; @@ -67,9 +67,9 @@ export function diffChildren( // At this point, constructNewChildrenArray has assigned _index to be the // matchingIndex for this VNode's oldVNode (or -1 if there is no oldVNode). if (childVNode._index === -1) { - oldVNode = EMPTY_OBJ; + oldVNode = EMPTY_VNODE; } else { - oldVNode = oldChildren[childVNode._index] || EMPTY_OBJ; + oldVNode = oldChildren[childVNode._index] || EMPTY_VNODE; } // Update childVNode._index to its final index diff --git a/src/render.js b/src/render.js index e0fec45424a..dac3036dc25 100644 --- a/src/render.js +++ b/src/render.js @@ -1,6 +1,6 @@ import { EMPTY_OBJ } from './constants'; import { commitRoot, diff } from './diff/index'; -import { createElement, Fragment } from './create-element'; +import { createElement, Fragment, EMPTY_VNODE } from './create-element'; import options from './options'; import { slice } from './util'; @@ -39,7 +39,7 @@ export function render(vnode, parentDom, replaceNode) { // Determine the new vnode tree and store it on the DOM element on // our custom `_children` property. vnode, - oldVNode || EMPTY_OBJ, + oldVNode || EMPTY_VNODE, EMPTY_OBJ, parentDom.namespaceURI, !isHydrating && replaceNode