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 d8f0e21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/create-element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { slice } from './util';
import options from './options';
import { EMPTY_OBJ } from './constants';

let vnodeId = 0;

Expand Down Expand Up @@ -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 };
}
Expand Down
8 changes: 4 additions & 4 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 { createVNode, Fragment, EMPTY_VNODE } from '../create-element';
import { EMPTY_ARR, INSERT_VNODE, MATCHED } 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,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';

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 d8f0e21

Please sign in to comment.