From f43d1fa22234ba6ce2b58a43e6cc1d86bbe9c41f Mon Sep 17 00:00:00 2001 From: Josh Nelson Date: Fri, 21 Apr 2023 00:07:35 -0700 Subject: [PATCH 1/2] Copy patch of https://github.com/preactjs/preact/pull/3968 --- src/clone-element.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/clone-element.js b/src/clone-element.js index 4cff226275..e10050fdcd 100644 --- a/src/clone-element.js +++ b/src/clone-element.js @@ -13,10 +13,21 @@ export function cloneElement(vnode, props, children) { key, ref, i; + + let defaultProps; + + if (vnode.type && vnode.type.defaultProps) { + defaultProps = vnode.type.defaultProps; + } + for (i in props) { if (i == 'key') key = props[i]; else if (i == 'ref') ref = props[i]; - else normalizedProps[i] = props[i]; + else if (props[i] === undefined && defaultProps !== undefined) { + normalizedProps[i] = defaultProps[i]; + } else { + normalizedProps[i] = props[i]; + } } if (arguments.length > 2) { @@ -31,4 +42,4 @@ export function cloneElement(vnode, props, children) { ref || vnode.ref, null ); -} +} \ No newline at end of file From 69f9408637c8f1ba13c82a55dc3bdeb48937590a Mon Sep 17 00:00:00 2001 From: Josh Nelson Date: Fri, 21 Apr 2023 00:08:08 -0700 Subject: [PATCH 2/2] Patch to make unmounting faster. PR TBD --- src/create-context.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/create-context.js b/src/create-context.js index df939ee325..4032e626de 100644 --- a/src/create-context.js +++ b/src/create-context.js @@ -52,7 +52,10 @@ export function createContext(defaultValue, contextId) { subs.push(c); let old = c.componentWillUnmount; c.componentWillUnmount = () => { - subs.splice(subs.indexOf(c), 1); + // Patch: this is a hot path, and taking sub out of the array is much + // faster this way since it's an unordered list. + subs[subs.indexOf(c)] = subs[subs.length - 1]; + subs.pop(); if (old) old.call(c); }; };