Skip to content

Commit 46cd53e

Browse files
Merge branch 'main' into fix_4631
2 parents dfc9c2f + f35272e commit 46cd53e

15 files changed

+334
-55
lines changed

devtools/src/devtools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function initDevTools() {
1313
globalVar !== undefined &&
1414
globalVar.__PREACT_DEVTOOLS__
1515
) {
16-
globalVar.__PREACT_DEVTOOLS__.attachPreact('10.26.2', options, {
16+
globalVar.__PREACT_DEVTOOLS__.attachPreact('10.26.4', options, {
1717
Fragment,
1818
Component
1919
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "preact",
33
"amdName": "preact",
4-
"version": "10.26.2",
4+
"version": "10.26.4",
55
"private": false,
66
"description": "Fast 3kb React-compatible Virtual DOM library.",
77
"main": "dist/preact.js",

src/clone-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function cloneElement(vnode, props, children) {
2626
for (i in props) {
2727
if (i == 'key') key = props[i];
2828
else if (i == 'ref') ref = props[i];
29-
else if (props[i] === UNDEFINED && defaultProps !== UNDEFINED) {
29+
else if (props[i] == UNDEFINED && defaultProps != UNDEFINED) {
3030
normalizedProps[i] = defaultProps[i];
3131
} else {
3232
normalizedProps[i] = props[i];

src/component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function BaseComponent(props, context) {
2828
BaseComponent.prototype.setState = function (update, callback) {
2929
// only clone state when copying to nextState the first time.
3030
let s;
31-
if (this._nextState != NULL && this._nextState !== this.state) {
31+
if (this._nextState != NULL && this._nextState != this.state) {
3232
s = this._nextState;
3333
} else {
3434
s = this._nextState = assign({}, this.state);
@@ -204,7 +204,7 @@ export function enqueueRender(c) {
204204
(c._dirty = true) &&
205205
rerenderQueue.push(c) &&
206206
!process._rerenderCount++) ||
207-
prevDebounce !== options.debounceRendering
207+
prevDebounce != options.debounceRendering
208208
) {
209209
prevDebounce = options.debounceRendering;
210210
(prevDebounce || defer)(process);

src/create-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function createContext(defaultValue) {
1919

2020
this.shouldComponentUpdate = function (_props) {
2121
// @ts-expect-error even
22-
if (this.props.value !== _props.value) {
22+
if (this.props.value != _props.value) {
2323
subs.forEach(c => {
2424
c._force = true;
2525
enqueueRender(c);

src/create-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function createElement(type, props, children) {
3333
// Note: type may be undefined in development, must never error here.
3434
if (typeof type == 'function' && type.defaultProps != NULL) {
3535
for (i in type.defaultProps) {
36-
if (normalizedProps[i] === UNDEFINED) {
36+
if (normalizedProps[i] == UNDEFINED) {
3737
normalizedProps[i] = type.defaultProps[i];
3838
}
3939
}

src/diff/children.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function diffChildren(
8484

8585
// At this point, constructNewChildrenArray has assigned _index to be the
8686
// matchingIndex for this VNode's oldVNode (or -1 if there is no oldVNode).
87-
if (childVNode._index === -1) {
87+
if (childVNode._index == -1) {
8888
oldVNode = EMPTY_OBJ;
8989
} else {
9090
oldVNode = oldChildren[childVNode._index] || EMPTY_OBJ;
@@ -207,7 +207,7 @@ function constructNewChildrenArray(
207207
NULL,
208208
NULL
209209
);
210-
} else if (childVNode.constructor === UNDEFINED && childVNode._depth > 0) {
210+
} else if (childVNode.constructor == UNDEFINED && childVNode._depth > 0) {
211211
// VNode is already in use, clone it. This can happen in the following
212212
// scenario:
213213
// const reuse = <div />
@@ -238,7 +238,7 @@ function constructNewChildrenArray(
238238
));
239239

240240
oldVNode = NULL;
241-
if (matchingIndex !== -1) {
241+
if (matchingIndex != -1) {
242242
oldVNode = oldChildren[matchingIndex];
243243
remainingOldChildren--;
244244
if (oldVNode) {
@@ -248,8 +248,8 @@ function constructNewChildrenArray(
248248

249249
// Here, we define isMounting for the purposes of the skew diffing
250250
// algorithm. Nodes that are unsuspending are considered mounting and we detect
251-
// this by checking if oldVNode._original === null
252-
const isMounting = oldVNode == NULL || oldVNode._original === NULL;
251+
// this by checking if oldVNode._original == null
252+
const isMounting = oldVNode == NULL || oldVNode._original == NULL;
253253

254254
if (isMounting) {
255255
if (matchingIndex == -1) {
@@ -428,7 +428,7 @@ function findMatchingIndex(
428428
(oldVNode === NULL && childVNode.key == null) ||
429429
(oldVNode &&
430430
key == oldVNode.key &&
431-
type === oldVNode.type &&
431+
type == oldVNode.type &&
432432
(oldVNode._flags & MATCHED) == 0)
433433
) {
434434
return skewedIndex;
@@ -442,7 +442,7 @@ function findMatchingIndex(
442442
oldVNode &&
443443
(oldVNode._flags & MATCHED) == 0 &&
444444
key == oldVNode.key &&
445-
type === oldVNode.type
445+
type == oldVNode.type
446446
) {
447447
return x;
448448
}
@@ -455,7 +455,7 @@ function findMatchingIndex(
455455
oldVNode &&
456456
(oldVNode._flags & MATCHED) == 0 &&
457457
key == oldVNode.key &&
458-
type === oldVNode.type
458+
type == oldVNode.type
459459
) {
460460
return y;
461461
}

src/diff/index.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function diff(
6464

6565
// When passing through createElement it assigns the object
6666
// constructor as undefined. This to prevent JSON-injection.
67-
if (newVNode.constructor !== UNDEFINED) return NULL;
67+
if (newVNode.constructor != UNDEFINED) return NULL;
6868

6969
// If the previous diff bailed out, resume creating/hydrating.
7070
if (oldVNode._flags & MODE_SUSPENDED) {
@@ -165,14 +165,14 @@ export function diff(
165165
}
166166

167167
if (
168-
!c._force &&
169-
((c.shouldComponentUpdate != NULL &&
168+
(!c._force &&
169+
c.shouldComponentUpdate != NULL &&
170170
c.shouldComponentUpdate(
171171
newProps,
172172
c._nextState,
173173
componentContext
174174
) === false) ||
175-
newVNode._original == oldVNode._original)
175+
newVNode._original == oldVNode._original
176176
) {
177177
// More info about this here: https://gist.github.com/JoviDeCroock/bec5f2ce93544d2e6070ef8e0036e4e8
178178
if (newVNode._original != oldVNode._original) {
@@ -258,10 +258,10 @@ export function diff(
258258

259259
let isTopLevelFragment =
260260
tmp != NULL && tmp.type === Fragment && tmp.key == NULL;
261-
let renderResult = isTopLevelFragment ? tmp.props.children : tmp;
261+
let renderResult = tmp;
262262

263263
if (isTopLevelFragment) {
264-
tmp.props.children = NULL;
264+
renderResult = cloneNode(tmp.props.children);
265265
}
266266

267267
oldDom = diffChildren(
@@ -368,6 +368,22 @@ export function commitRoot(commitQueue, root, refQueue) {
368368
});
369369
}
370370

371+
function cloneNode(node) {
372+
if (
373+
typeof node != 'object' ||
374+
node == NULL ||
375+
(node._depth && node._depth > 0)
376+
) {
377+
return node;
378+
}
379+
380+
if (isArray(node)) {
381+
return node.map(cloneNode);
382+
}
383+
384+
return assign({}, node);
385+
}
386+
371387
/**
372388
* Diff two virtual nodes representing DOM element
373389
* @param {PreactElement} dom The DOM element representing the virtual nodes
@@ -455,9 +471,9 @@ function diffElementNodes(
455471
excessDomChildren = NULL;
456472
}
457473

458-
if (nodeType === NULL) {
474+
if (nodeType == NULL) {
459475
// During hydration, we still have to split merged text from SSR'd HTML.
460-
if (oldProps !== newProps && (!isHydrating || dom.data !== newProps)) {
476+
if (oldProps !== newProps && (!isHydrating || dom.data != newProps)) {
461477
dom.data = newProps;
462478
}
463479
} else {
@@ -519,8 +535,7 @@ function diffElementNodes(
519535
if (
520536
!isHydrating &&
521537
(!oldHtml ||
522-
(newHtml.__html !== oldHtml.__html &&
523-
newHtml.__html !== dom.innerHTML))
538+
(newHtml.__html != oldHtml.__html && newHtml.__html != dom.innerHTML))
524539
) {
525540
dom.innerHTML = newHtml.__html;
526541
}
@@ -531,7 +546,7 @@ function diffElementNodes(
531546

532547
diffChildren(
533548
// @ts-expect-error
534-
newVNode.type === 'template' ? dom.content : dom,
549+
newVNode.type == 'template' ? dom.content : dom,
535550
isArray(newChildren) ? newChildren : [newChildren],
536551
newVNode,
537552
oldVNode,
@@ -560,7 +575,7 @@ function diffElementNodes(
560575
if (nodeType == 'progress' && inputValue == NULL) {
561576
dom.removeAttribute('value');
562577
} else if (
563-
inputValue !== UNDEFINED &&
578+
inputValue != UNDEFINED &&
564579
// #2756 For the <progress>-element the initial value is 0,
565580
// despite the attribute not being present. When the attribute
566581
// is missing the progress bar is treated as indeterminate.
@@ -570,13 +585,13 @@ function diffElementNodes(
570585
// This is only for IE 11 to fix <select> value not being updated.
571586
// To avoid a stale select value we need to set the option.value
572587
// again, which triggers IE11 to re-evaluate the select value
573-
(nodeType == 'option' && inputValue !== oldProps[i]))
588+
(nodeType == 'option' && inputValue != oldProps[i]))
574589
) {
575590
setProperty(dom, i, inputValue, oldProps[i], namespace);
576591
}
577592

578593
i = 'checked';
579-
if (checked !== UNDEFINED && checked !== dom[i]) {
594+
if (checked != UNDEFINED && checked != dom[i]) {
580595
setProperty(dom, i, checked, oldProps[i], namespace);
581596
}
582597
}
@@ -624,7 +639,7 @@ export function unmount(vnode, parentVNode, skipRemove) {
624639
if (options.unmount) options.unmount(vnode);
625640

626641
if ((r = vnode.ref)) {
627-
if (!r.current || r.current === vnode._dom) {
642+
if (!r.current || r.current == vnode._dom) {
628643
applyRef(r, NULL, parentVNode);
629644
}
630645
}

src/diff/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function setProperty(dom, name, value, oldValue, namespace) {
5757

5858
if (value) {
5959
for (name in value) {
60-
if (!oldValue || value[name] !== oldValue[name]) {
60+
if (!oldValue || value[name] != oldValue[name]) {
6161
setStyle(dom.style, name, value[name]);
6262
}
6363
}

0 commit comments

Comments
 (0)