Skip to content

Commit

Permalink
Make oldVNode monomorphic
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 3, 2024
1 parent 0677d63 commit 700b89f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createVNode } from './create-element';

/** Normal hydration that attaches to a DOM tree but does not diff it. */
export const MODE_HYDRATE = 1 << 5;
/** Signifies this VNode suspended on the previous render */
Expand All @@ -12,5 +14,7 @@ export const RESET_MODE = ~(MODE_HYDRATE | MODE_SUSPENDED);

export const EMPTY_OBJ = /** @type {any} */ ({});
export const EMPTY_ARR = [];
export const EMPTY_VNODE = createVNode(null, EMPTY_OBJ, null, null);
// EMPTY_VNODE._children = []
export const IS_NON_DIMENSIONAL =
/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
6 changes: 3 additions & 3 deletions src/diff/children.js
Original file line number Diff line number Diff line change
@@ -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 { EMPTY_ARR, INSERT_VNODE, MATCHED, EMPTY_VNODE } from '../constants';
import { isArray } from '../util';
import { getDomSibling } from '../component';

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/render.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EMPTY_OBJ } from './constants';
import { EMPTY_OBJ, EMPTY_VNODE } from './constants';
import { commitRoot, diff } from './diff/index';
import { createElement, Fragment } from './create-element';
import options from './options';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 700b89f

Please sign in to comment.