Skip to content

Commit

Permalink
backport #3956
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jan 22, 2024
1 parent b128ba5 commit 0726ad3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/create-element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UNDEFINED } from './constants';
import options from './options';
import { isArray } from './util';

let vnodeId = 0;

Expand Down Expand Up @@ -65,7 +66,7 @@ export function normalizeToVNode(childVNode) {
}

if (type == 'object' || type == 'function') {
if (Array.isArray(childVNode)) {
if (isArray(childVNode)) {
return createElement(Fragment, null, childVNode);
}

Expand Down
3 changes: 2 additions & 1 deletion src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { mount } from './mount';
import { patch } from './patch';
import { unmount } from './unmount';
import { createInternal, getDomSibling } from '../tree';
import { isArray } from '../util';

/**
* Update an internal with new children.
Expand Down Expand Up @@ -274,7 +275,7 @@ export function insertComponentDom(internal, nextSibling, parentDom) {
export function toChildArray(children, out) {
out = out || [];
if (children == null || typeof children == 'boolean') {
} else if (Array.isArray(children)) {
} else if (isArray(children)) {
for (children of children) {
toChildArray(children, out);
}
Expand Down
5 changes: 3 additions & 2 deletions src/diff/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createInternal, getParentContext } from '../tree';
import options from '../options';
import { ENABLE_CLASSES } from '../component';
import { commitQueue } from './commit';
import { isArray } from '../util';
/**
* Diff two virtual nodes and apply proper changes to the DOM
* @param {import('../internal').Internal} internal The Internal node to mount
Expand Down Expand Up @@ -201,7 +202,7 @@ function mountElement(internal, dom, refs) {
} else if (newChildren != null) {
mountChildren(
internal,
Array.isArray(newChildren) ? newChildren : [newChildren],
isArray(newChildren) ? newChildren : [newChildren],
dom,
isNew ? null : dom.firstChild,
refs
Expand Down Expand Up @@ -409,7 +410,7 @@ function mountComponent(internal, startDom) {
if (renderResult.type === Fragment && renderResult.key == null) {
renderResult = renderResult.props.children;
}
if (!Array.isArray(renderResult)) {
if (!isArray(renderResult)) {
renderResult = [renderResult];
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/diff/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { mountChildren } from './mount';
import { Fragment } from '../create-element';
import { ENABLE_CLASSES } from '../component';
import { commitQueue } from './commit';
import { isArray } from '../util';

/**
* Diff two virtual nodes and apply proper changes to the DOM
Expand Down Expand Up @@ -182,7 +183,7 @@ function patchElement(internal, vnode) {
if (oldHtml) dom.innerHTML = '';
patchChildren(
internal,
newChildren && Array.isArray(newChildren) ? newChildren : [newChildren],
newChildren && isArray(newChildren) ? newChildren : [newChildren],
dom
);
}
Expand Down Expand Up @@ -311,7 +312,7 @@ function patchComponent(internal, newVNode) {
if (renderResult.type === Fragment && renderResult.key == null) {
renderResult = renderResult.props.children;
}
if (!Array.isArray(renderResult)) {
if (!isArray(renderResult)) {
renderResult = [renderResult];
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isArray = Array.isArray;

0 comments on commit 0726ad3

Please sign in to comment.