react-refresh
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -1,2 +0,2 @@ | ||
/** @license React v0.7.0 | ||
/** @license React vundefined | ||
* react-refresh-babel.development.js | ||
@@ -3,0 +3,0 @@ * |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.7.0 | ||
/** @license React vundefined | ||
* react-refresh-babel.production.min.js | ||
@@ -3,0 +3,0 @@ * |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.7.0 | ||
/** @license React vundefined | ||
* react-refresh-runtime.development.js | ||
@@ -54,7 +54,13 @@ * | ||
var mountedRoots = new Set(); // If a root captures an error, we add its element to this Map so we can retry on edit. | ||
var mountedRoots = new Set(); // If a root captures an error, we remember it so we can retry on edit. | ||
var failedRoots = new Map(); | ||
var didSomeRootFailOnMount = false; | ||
var failedRoots = new Set(); // In environments that support WeakMap, we also remember the last element for every root. | ||
// It needs to be weak because we do this even for roots that failed to mount. | ||
// If there is no WeakMap, we won't attempt to do retrying. | ||
// $FlowIssue | ||
var rootElements = // $FlowIssue | ||
typeof WeakMap === 'function' ? new WeakMap() : null; | ||
var isPerformingRefresh = false; | ||
function computeFullKey(signature) { | ||
@@ -152,10 +158,33 @@ if (signature.fullKey !== null) { | ||
return updatedFamiliesByType.get(type); | ||
} // If we didn't care about IE11, we could use new Map/Set(iterable). | ||
function cloneMap(map) { | ||
var clone = new Map(); | ||
map.forEach(function (value, key) { | ||
clone.set(key, value); | ||
}); | ||
return clone; | ||
} | ||
function cloneSet(set) { | ||
var clone = new Set(); | ||
set.forEach(function (value) { | ||
clone.add(value); | ||
}); | ||
return clone; | ||
} | ||
function performReactRefresh() { | ||
{ | ||
if (pendingUpdates.length === 0) { | ||
return null; | ||
} | ||
if (pendingUpdates.length === 0) { | ||
return null; | ||
} | ||
if (isPerformingRefresh) { | ||
return null; | ||
} | ||
isPerformingRefresh = true; | ||
try { | ||
var staleFamilies = new Set(); | ||
@@ -194,6 +223,13 @@ var updatedFamilies = new Set(); | ||
var didError = false; | ||
var firstError = null; | ||
failedRoots.forEach(function (element, root) { | ||
var helpers = helpersByRoot.get(root); | ||
var firstError = null; // We snapshot maps and sets that are mutated during commits. | ||
// If we don't do this, there is a risk they will be mutated while | ||
// we iterate over them. For example, trying to recover a failed root | ||
// may cause another root to be added to the failed list -- an infinite loop. | ||
var failedRootsSnapshot = cloneSet(failedRoots); | ||
var mountedRootsSnapshot = cloneSet(mountedRoots); | ||
var helpersByRootSnapshot = cloneMap(helpersByRoot); | ||
failedRootsSnapshot.forEach(function (root) { | ||
var helpers = helpersByRootSnapshot.get(root); | ||
if (helpers === undefined) { | ||
@@ -203,2 +239,15 @@ throw new Error('Could not find helpers for a root. This is a bug in React Refresh.'); | ||
if (!failedRoots.has(root)) {// No longer failed. | ||
} | ||
if (rootElements === null) { | ||
return; | ||
} | ||
if (!rootElements.has(root)) { | ||
return; | ||
} | ||
var element = rootElements.get(root); | ||
try { | ||
@@ -214,4 +263,4 @@ helpers.scheduleRoot(root, element); | ||
}); | ||
mountedRoots.forEach(function (root) { | ||
var helpers = helpersByRoot.get(root); | ||
mountedRootsSnapshot.forEach(function (root) { | ||
var helpers = helpersByRootSnapshot.get(root); | ||
@@ -222,2 +271,5 @@ if (helpers === undefined) { | ||
if (!mountedRoots.has(root)) {// No longer mounted. | ||
} | ||
try { | ||
@@ -239,2 +291,4 @@ helpers.scheduleRefresh(root, update); | ||
return update; | ||
} finally { | ||
isPerformingRefresh = false; | ||
} | ||
@@ -356,2 +410,3 @@ } | ||
globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { | ||
renderers: new Map(), | ||
supportsFiber: true, | ||
@@ -361,2 +416,3 @@ inject: function (injected) { | ||
}, | ||
onScheduleFiberRoot: function (id, root, children) {}, | ||
onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {}, | ||
@@ -379,7 +435,32 @@ onCommitFiberUnmount: function () {} | ||
return id; | ||
}; // We also want to track currently mounted roots. | ||
}; // Do the same for any already injected roots. | ||
// This is useful if ReactDOM has already been initialized. | ||
// https://github.com/facebook/react/issues/17626 | ||
hook.renderers.forEach(function (injected, id) { | ||
if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') { | ||
// This version supports React Refresh. | ||
helpersByRendererID.set(id, injected); | ||
} | ||
}); // We also want to track currently mounted roots. | ||
var oldOnCommitFiberRoot = hook.onCommitFiberRoot; | ||
var oldOnScheduleFiberRoot = hook.onScheduleFiberRoot || function () {}; | ||
hook.onScheduleFiberRoot = function (id, root, children) { | ||
if (!isPerformingRefresh) { | ||
// If it was intentionally scheduled, don't attempt to restore. | ||
// This includes intentionally scheduled unmounts. | ||
failedRoots.delete(root); | ||
if (rootElements !== null) { | ||
rootElements.set(root, children); | ||
} | ||
} | ||
return oldOnScheduleFiberRoot.apply(this, arguments); | ||
}; | ||
hook.onCommitFiberRoot = function (id, root, maybePriorityLevel, didError) { | ||
@@ -414,4 +495,3 @@ var helpers = helpersByRendererID.get(id); | ||
// We'll remount it on future edits. | ||
// Remember what was rendered so we can restore it. | ||
failedRoots.set(root, alternate.memoizedState.element); | ||
failedRoots.add(root); | ||
} else { | ||
@@ -421,13 +501,5 @@ helpersByRoot.delete(root); | ||
} else if (!wasMounted && !isMounted) { | ||
if (didError && !failedRoots.has(root)) { | ||
// The root had an error during the initial mount. | ||
// We can't read its last element from the memoized state | ||
// because there was no previously committed alternate. | ||
// Ideally, it would be nice if we had a way to extract | ||
// the last attempted rendered element, but accessing the update queue | ||
// would tie this package too closely to the reconciler version. | ||
// So instead, we just set a flag. | ||
// TODO: Maybe we could fix this as the same time as when we fix | ||
// DevTools to not depend on `alternate.memoizedState.element`. | ||
didSomeRootFailOnMount = true; | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} | ||
@@ -445,3 +517,4 @@ } | ||
function hasUnrecoverableErrors() { | ||
return didSomeRootFailOnMount; | ||
// TODO: delete this after removing dependency in RN. | ||
return false; | ||
} // Exposed for testing. | ||
@@ -448,0 +521,0 @@ |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.7.0 | ||
/** @license React vundefined | ||
* react-refresh-runtime.production.min.js | ||
@@ -3,0 +3,0 @@ * |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"homepage": "https://reactjs.org/", | ||
@@ -10,0 +10,0 @@ "bugs": "https://github.com/facebook/react/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53544
1191
9