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 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); }; };