diff --git a/.prettierignore b/.prettierignore index 2d653022d..b625db5e9 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,4 +9,5 @@ babel.js index.js patch.js root.js -test/hot/react-dom \ No newline at end of file +test/hot/react-dom +coverage \ No newline at end of file diff --git a/src/reconciler/componentComparator.js b/src/reconciler/componentComparator.js index f86379abd..4815644a8 100644 --- a/src/reconciler/componentComparator.js +++ b/src/reconciler/componentComparator.js @@ -182,30 +182,38 @@ const compareComponents = (oldType, newType, setNewType, baseType) => { const knownPairs = new WeakMap(); const emptyMap = new WeakMap(); +const getKnownPair = (oldType, newType) => { + const pair = knownPairs.get(oldType) || emptyMap; + return pair.get(newType); +}; + export const hotComponentCompare = (oldType, preNewType, setNewType, baseType) => { const hotActive = hotComparisonOpen(); const newType = configuration.integratedResolver ? resolveType(preNewType) : preNewType; - let result = oldType === newType; - if (!hotActive) { - return result; - } + // TODO: find out the root cause + // we could not use "fast result" here - go a full part to update a fiber. + // const knownType = getKnownPair(oldType, newType); + // if (knownType !== undefined) { + // return knownType; + // } - if ( - !isReloadableComponent(oldType) || - !isReloadableComponent(newType) || - isColdType(oldType) || - isColdType(oldType) || - !oldType || - !newType || - 0 - ) { - return result; - } + let result = oldType === newType; - // comparison should be active only if hot update window - // or it would merge components it shall not if (hotActive) { + // pre fail components which could not be merged + if ( + !isReloadableComponent(oldType) || + !isReloadableComponent(newType) || + isColdType(oldType) || + isColdType(oldType) || + !oldType || + !newType || + 0 + ) { + return result; + } + result = compareComponents(oldType, newType, setNewType, baseType); const pair = knownPairs.get(oldType) || new WeakMap(); pair.set(newType, result); @@ -213,10 +221,6 @@ export const hotComponentCompare = (oldType, preNewType, setNewType, baseType) = return result; } - if (result) { - return result; - } - - const pair = knownPairs.get(oldType) || emptyMap; - return pair.get(newType) || false; + // result - true if components are equal, or were "equal" at any point in the past + return result || getKnownPair(oldType, newType) || false; }; diff --git a/src/reconciler/resolver.js b/src/reconciler/resolver.js index fed4a60fa..f26430dc1 100644 --- a/src/reconciler/resolver.js +++ b/src/reconciler/resolver.js @@ -12,17 +12,23 @@ import configuration, { internalConfiguration } from '../configuration'; const shouldNotPatchComponent = type => isTypeBlacklisted(type); export function resolveType(type, options = {}) { - const element = { type }; - if (isLazyType(element) || isMemoType(element) || isForwardType(element) || isContextType(element)) { - return getProxyByType(type) || type; - } - + // fast return if (!isCompositeComponent(type) || isProxyType(type)) { return type; } + const element = { type }; + + // fast meta + if (typeof element === 'object') { + if (isLazyType(element) || isMemoType(element) || isForwardType(element) || isContextType(element)) { + return getProxyByType(type) || type; + } + } + const existingProxy = getProxyByType(type); + // cold API if (shouldNotPatchComponent(type)) { return existingProxy ? existingProxy.getCurrent() : type; }