react-refresh
Advanced tools
Comparing version 0.0.0-experimental-38dd17ab9 to 0.0.0-experimental-38e3b23483-20240529
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-refresh-babel.production.min.js'); | ||
module.exports = require('./cjs/react-refresh-babel.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-refresh-babel.development.js'); | ||
} |
@@ -1,5 +0,6 @@ | ||
/** @license React v0.0.0-experimental-38dd17ab9 | ||
/** | ||
* @license React | ||
* react-refresh-babel.development.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -12,4 +13,2 @@ * This source code is licensed under the MIT license found in the | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -19,8 +18,8 @@ (function() { | ||
var ReactFreshBabelPlugin = function (babel) { | ||
function ReactFreshBabelPlugin (babel) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (typeof babel.getEnv === 'function') { | ||
if (typeof babel.env === 'function') { | ||
// Only available in Babel 7. | ||
var env = babel.getEnv(); | ||
var env = babel.env(); | ||
@@ -33,2 +32,4 @@ if (env !== 'development' && !opts.skipEnvCheck) { | ||
var t = babel.types; | ||
var refreshReg = t.identifier(opts.refreshReg || '$RefreshReg$'); | ||
var refreshSig = t.identifier(opts.refreshSig || '$RefreshSig$'); | ||
var registrationsByProgramPath = new Map(); | ||
@@ -174,8 +175,3 @@ | ||
} else if (calleeType === 'MemberExpression') {// Could be something like React.forwardRef(...) | ||
// Pass through. | ||
} else { | ||
// More complicated call. | ||
return false; | ||
} | ||
} else ; | ||
@@ -214,3 +210,3 @@ break; | ||
if (ref.node.type !== 'JSXIdentifier' && ref.node.type !== 'Identifier') { | ||
if (ref.node && ref.node.type !== 'JSXIdentifier' && ref.node.type !== 'Identifier') { | ||
continue; | ||
@@ -277,6 +273,24 @@ } | ||
case 'React.useContext': | ||
case 'useImperativeMethods': | ||
case 'React.useImperativeMethods': | ||
case 'useImperativeHandle': | ||
case 'React.useImperativeHandle': | ||
case 'useDebugValue': | ||
case 'React.useDebugValue': | ||
case 'useId': | ||
case 'React.useId': | ||
case 'useDeferredValue': | ||
case 'React.useDeferredValue': | ||
case 'useTransition': | ||
case 'React.useTransition': | ||
case 'useInsertionEffect': | ||
case 'React.useInsertionEffect': | ||
case 'useSyncExternalStore': | ||
case 'React.useSyncExternalStore': | ||
case 'useFormStatus': | ||
case 'React.useFormStatus': | ||
case 'useFormState': | ||
case 'React.useFormState': | ||
case 'useActionState': | ||
case 'React.useActionState': | ||
case 'useOptimistic': | ||
case 'React.useOptimistic': | ||
return true; | ||
@@ -369,3 +383,3 @@ | ||
// This makes it deterministically compact, even if there's | ||
// e.g. a useState ininitalizer with some code inside. | ||
// e.g. a useState initializer with some code inside. | ||
// We also need it for www that has transforms like cx() | ||
@@ -391,2 +405,34 @@ // that don't understand if something is part of a string. | ||
function findHOCCallPathsAbove(path) { | ||
var calls = []; | ||
while (true) { | ||
if (!path) { | ||
return calls; | ||
} | ||
var parentPath = path.parentPath; | ||
if (!parentPath) { | ||
return calls; | ||
} | ||
if ( // hoc(_c = function() { }) | ||
parentPath.node.type === 'AssignmentExpression' && path.node === parentPath.node.right) { | ||
// Ignore registrations. | ||
path = parentPath; | ||
continue; | ||
} | ||
if ( // hoc1(hoc2(...)) | ||
parentPath.node.type === 'CallExpression' && path.node !== parentPath.node.callee) { | ||
calls.push(parentPath); | ||
path = parentPath; | ||
continue; | ||
} | ||
return calls; // Stop at other types. | ||
} | ||
} | ||
var seenForRegistration = new WeakSet(); | ||
@@ -506,2 +552,3 @@ var seenForSignature = new WeakSet(); | ||
var insertAfterPath; | ||
var modulePrefix = ''; | ||
@@ -514,2 +561,7 @@ switch (path.parent.type) { | ||
case 'TSModuleBlock': | ||
insertAfterPath = path; | ||
programPath = insertAfterPath.parentPath.parentPath; | ||
break; | ||
case 'ExportNamedDeclaration': | ||
@@ -527,2 +579,19 @@ insertAfterPath = path.parentPath; | ||
return; | ||
} // These types can be nested in typescript namespace | ||
// We need to find the export chain | ||
// Or return if it stays local | ||
if (path.parent.type === 'TSModuleBlock' || path.parent.type === 'ExportNamedDeclaration') { | ||
while (programPath.type !== 'Program') { | ||
if (programPath.type === 'TSModuleDeclaration') { | ||
if (programPath.parentPath.type !== 'Program' && programPath.parentPath.type !== 'ExportNamedDeclaration') { | ||
return; | ||
} | ||
modulePrefix = programPath.node.id.name + '$' + modulePrefix; | ||
} | ||
programPath = programPath.parentPath; | ||
} | ||
} | ||
@@ -550,6 +619,7 @@ | ||
seenForRegistration.add(node); // Don't mutate the tree above this point. | ||
// export function Named() {} | ||
var innerName = modulePrefix + inferredName; // export function Named() {} | ||
// function Named() {} | ||
findInnerComponents(inferredName, path, function (persistentID, targetExpr) { | ||
findInnerComponents(innerName, path, function (persistentID, targetExpr) { | ||
var handle = createRegistration(programPath, persistentID); | ||
@@ -584,3 +654,3 @@ insertAfterPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', handle, targetExpr))); | ||
id: sigCallID, | ||
init: t.callExpression(t.identifier('$RefreshSig$'), []) | ||
init: t.callExpression(refreshSig, []) | ||
}); // The signature call is split in two parts. One part is called inside the function. | ||
@@ -593,3 +663,3 @@ // This is used to signal when first render happens. | ||
// declarations too. So we need to search for a path where | ||
// we can insert a statement rather than hardcoding it. | ||
// we can insert a statement rather than hard coding it. | ||
@@ -631,3 +701,3 @@ var insertAfterPath = null; | ||
id: sigCallID, | ||
init: t.callExpression(t.identifier('$RefreshSig$'), []) | ||
init: t.callExpression(refreshSig, []) | ||
}); // The signature call is split in two parts. One part is called inside the function. | ||
@@ -664,3 +734,6 @@ // This is used to signal when first render happens. | ||
// let Foo = hoc(() => {}) | ||
path.replaceWith(t.callExpression(sigCallID, createArgumentsForSignature(node, signature, path.scope))); // Result: let Foo = hoc(__signature(() => {}, ...)) | ||
var paths = [path].concat(findHOCCallPathsAbove(path)); | ||
paths.forEach(function (p) { | ||
p.replaceWith(t.callExpression(sigCallID, createArgumentsForSignature(p.node, signature, p.scope))); | ||
}); // Result: let Foo = __signature(hoc(__signature(() => {}, ...)), ...) | ||
} | ||
@@ -673,2 +746,3 @@ } | ||
var insertAfterPath; | ||
var modulePrefix = ''; | ||
@@ -681,2 +755,7 @@ switch (path.parent.type) { | ||
case 'TSModuleBlock': | ||
insertAfterPath = path; | ||
programPath = insertAfterPath.parentPath.parentPath; | ||
break; | ||
case 'ExportNamedDeclaration': | ||
@@ -694,2 +773,19 @@ insertAfterPath = path.parentPath; | ||
return; | ||
} // These types can be nested in typescript namespace | ||
// We need to find the export chain | ||
// Or return if it stays local | ||
if (path.parent.type === 'TSModuleBlock' || path.parent.type === 'ExportNamedDeclaration') { | ||
while (programPath.type !== 'Program') { | ||
if (programPath.type === 'TSModuleDeclaration') { | ||
if (programPath.parentPath.type !== 'Program' && programPath.parentPath.type !== 'ExportNamedDeclaration') { | ||
return; | ||
} | ||
modulePrefix = programPath.node.id.name + '$' + modulePrefix; | ||
} | ||
programPath = programPath.parentPath; | ||
} | ||
} // Make sure we're not mutating the same tree twice. | ||
@@ -713,3 +809,4 @@ // This can happen if another Babel plugin replaces parents. | ||
var inferredName = declPath.node.id.name; | ||
findInnerComponents(inferredName, declPath, function (persistentID, targetExpr, targetPath) { | ||
var innerName = modulePrefix + inferredName; | ||
findInnerComponents(innerName, declPath, function (persistentID, targetExpr, targetPath) { | ||
if (targetPath === null) { | ||
@@ -725,12 +822,15 @@ // For case like: | ||
if ((targetExpr.type === 'ArrowFunctionExpression' || targetExpr.type === 'FunctionExpression') && targetPath.parent.type === 'VariableDeclarator') { | ||
// Special case when a function would get an inferred name: | ||
if (targetPath.parent.type === 'VariableDeclarator') { | ||
// Special case when a variable would get an inferred name: | ||
// let Foo = () => {} | ||
// let Foo = function() {} | ||
// let Foo = styled.div``; | ||
// We'll register it on next line so that | ||
// we don't mess up the inferred 'Foo' function name. | ||
// (eg: with @babel/plugin-transform-react-display-name or | ||
// babel-plugin-styled-components) | ||
insertAfterPath.insertAfter(t.expressionStatement(t.assignmentExpression('=', handle, declPath.node.id))); // Result: let Foo = () => {}; _c1 = Foo; | ||
} else { | ||
// let Foo = hoc(() => {}) | ||
targetPath.replaceWith(t.assignmentExpression('=', handle, targetExpr)); // Result: let Foo = _c1 = hoc(() => {}) | ||
targetPath.replaceWith(t.assignmentExpression('=', handle, targetExpr)); // Result: let Foo = hoc(_c1 = () => {}) | ||
} | ||
@@ -770,3 +870,3 @@ }); | ||
persistentID = _ref.persistentID; | ||
path.pushContainer('body', t.expressionStatement(t.callExpression(t.identifier('$RefreshReg$'), [handle, t.stringLiteral(persistentID)]))); | ||
path.pushContainer('body', t.expressionStatement(t.callExpression(refreshReg, [handle, t.stringLiteral(persistentID)]))); | ||
declarators.push(t.variableDeclarator(handle)); | ||
@@ -778,17 +878,6 @@ }); | ||
}; | ||
}; | ||
} | ||
var ReactFreshBabelPlugin$1 = Object.freeze({ | ||
default: ReactFreshBabelPlugin | ||
}); | ||
var ReactFreshBabelPlugin$2 = ( ReactFreshBabelPlugin$1 && ReactFreshBabelPlugin ) || ReactFreshBabelPlugin$1; | ||
// This is hacky but makes it work with both Rollup and Jest. | ||
var babel = ReactFreshBabelPlugin$2.default || ReactFreshBabelPlugin$2; | ||
module.exports = babel; | ||
module.exports = ReactFreshBabelPlugin; | ||
})(); | ||
} |
@@ -1,5 +0,6 @@ | ||
/** @license React v0.0.0-experimental-38dd17ab9 | ||
/** | ||
* @license React | ||
* react-refresh-runtime.development.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -12,4 +13,2 @@ * This source code is licensed under the MIT license found in the | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -19,21 +18,5 @@ (function() { | ||
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol | ||
// nor polyfill, then a plain number is used for performance. | ||
var hasSymbol = typeof Symbol === 'function' && Symbol.for; | ||
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref'); | ||
var REACT_MEMO_TYPE = Symbol.for('react.memo'); | ||
// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary | ||
// (unstable) APIs that have been removed. Can we remove the symbols? | ||
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; | ||
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; | ||
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // We never remove these associations. | ||
@@ -46,3 +29,2 @@ // It's OK to reference families, but use WeakMap/Set for types. | ||
// that have actually been edited here. This keeps checks fast. | ||
// $FlowIssue | ||
@@ -57,7 +39,11 @@ var updatedFamiliesByType = new PossiblyWeakMap(); // This is cleared on every performReactRefresh() call. | ||
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. | ||
var rootElements = typeof WeakMap === 'function' ? new WeakMap() : null; | ||
var isPerformingRefresh = false; | ||
function computeFullKey(signature) { | ||
@@ -155,10 +141,44 @@ 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; | ||
} // This is a safety mechanism to protect against rogue getters and Proxies. | ||
function getProperty(object, property) { | ||
try { | ||
return object[property]; | ||
} catch (err) { | ||
// Intentionally ignore. | ||
return undefined; | ||
} | ||
} | ||
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(); | ||
@@ -197,6 +217,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) { | ||
@@ -206,2 +233,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 { | ||
@@ -217,4 +257,4 @@ helpers.scheduleRoot(root, element); | ||
}); | ||
mountedRoots.forEach(function (root) { | ||
var helpers = helpersByRoot.get(root); | ||
mountedRootsSnapshot.forEach(function (root) { | ||
var helpers = helpersByRootSnapshot.get(root); | ||
@@ -225,2 +265,5 @@ if (helpers === undefined) { | ||
if (!mountedRoots.has(root)) {// No longer mounted. | ||
} | ||
try { | ||
@@ -242,2 +285,4 @@ helpers.scheduleRefresh(root, update); | ||
return update; | ||
} finally { | ||
isPerformingRefresh = false; | ||
} | ||
@@ -279,3 +324,3 @@ } | ||
if (typeof type === 'object' && type !== null) { | ||
switch (type.$$typeof) { | ||
switch (getProperty(type, '$$typeof')) { | ||
case REACT_FORWARD_REF_TYPE: | ||
@@ -297,10 +342,25 @@ register(type.render, id + '$render'); | ||
{ | ||
allSignaturesByType.set(type, { | ||
forceReset: forceReset, | ||
ownKey: key, | ||
fullKey: null, | ||
getCustomHooks: getCustomHooks || function () { | ||
return []; | ||
if (!allSignaturesByType.has(type)) { | ||
allSignaturesByType.set(type, { | ||
forceReset: forceReset, | ||
ownKey: key, | ||
fullKey: null, | ||
getCustomHooks: getCustomHooks || function () { | ||
return []; | ||
} | ||
}); | ||
} // Visit inner types because we might not have signed them. | ||
if (typeof type === 'object' && type !== null) { | ||
switch (getProperty(type, '$$typeof')) { | ||
case REACT_FORWARD_REF_TYPE: | ||
setSignature(type.render, key, forceReset, getCustomHooks); | ||
break; | ||
case REACT_MEMO_TYPE: | ||
setSignature(type.type, key, forceReset, getCustomHooks); | ||
break; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -361,2 +421,3 @@ } // This is lazily called during first render for a type. | ||
globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { | ||
renderers: new Map(), | ||
supportsFiber: true, | ||
@@ -366,5 +427,14 @@ inject: function (injected) { | ||
}, | ||
onScheduleFiberRoot: function (id, root, children) {}, | ||
onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {}, | ||
onCommitFiberUnmount: function () {} | ||
}; | ||
} | ||
if (hook.isDisabled) { | ||
// This isn't a real property on the hook, but it can be set to opt out | ||
// of DevTools integration and associated warnings and logs. | ||
// Using console['warn'] to evade Babel and ESLint | ||
console['warn']('Something has shimmed the React DevTools global hook (__REACT_DEVTOOLS_GLOBAL_HOOK__). ' + 'Fast Refresh is not compatible with this shim and will be disabled.'); | ||
return; | ||
} // Here, we just want to get a reference to scheduleRefresh. | ||
@@ -384,60 +454,73 @@ | ||
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) { | ||
var helpers = helpersByRendererID.get(id); | ||
if (helpers === undefined) { | ||
return; | ||
} | ||
if (helpers !== undefined) { | ||
helpersByRoot.set(root, helpers); | ||
var current = root.current; | ||
var alternate = current.alternate; // We need to determine whether this root has just (un)mounted. | ||
// This logic is copy-pasted from similar logic in the DevTools backend. | ||
// If this breaks with some refactoring, you'll want to update DevTools too. | ||
helpersByRoot.set(root, helpers); | ||
var current = root.current; | ||
var alternate = current.alternate; // We need to determine whether this root has just (un)mounted. | ||
// This logic is copy-pasted from similar logic in the DevTools backend. | ||
// If this breaks with some refactoring, you'll want to update DevTools too. | ||
if (alternate !== null) { | ||
var wasMounted = alternate.memoizedState != null && alternate.memoizedState.element != null && mountedRoots.has(root); | ||
var isMounted = current.memoizedState != null && current.memoizedState.element != null; | ||
if (alternate !== null) { | ||
var wasMounted = alternate.memoizedState != null && alternate.memoizedState.element != null; | ||
var isMounted = current.memoizedState != null && current.memoizedState.element != null; | ||
if (!wasMounted && isMounted) { | ||
// Mount a new root. | ||
mountedRoots.add(root); | ||
failedRoots.delete(root); | ||
} else if (wasMounted && isMounted) ; else if (wasMounted && !isMounted) { | ||
// Unmount an existing root. | ||
mountedRoots.delete(root); | ||
if (!wasMounted && isMounted) { | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} else { | ||
helpersByRoot.delete(root); | ||
} | ||
} else if (!wasMounted && !isMounted) { | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
failedRoots.add(root); | ||
} | ||
} | ||
} else { | ||
// Mount a new root. | ||
mountedRoots.add(root); | ||
failedRoots.delete(root); | ||
} else if (wasMounted && isMounted) {// Update an existing root. | ||
// This doesn't affect our mounted root Set. | ||
} else if (wasMounted && !isMounted) { | ||
// Unmount an existing root. | ||
mountedRoots.delete(root); | ||
if (didError) { | ||
// We'll remount it on future edits. | ||
// Remember what was rendered so we can restore it. | ||
failedRoots.set(root, alternate.memoizedState.element); | ||
} else { | ||
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; | ||
} | ||
} | ||
} else { | ||
// Mount a new root. | ||
mountedRoots.add(root); | ||
} | ||
} // Always call the decorated DevTools hook. | ||
return oldOnCommitFiberRoot.apply(this, arguments); | ||
@@ -448,3 +531,4 @@ }; | ||
function hasUnrecoverableErrors() { | ||
return didSomeRootFailOnMount; | ||
// TODO: delete this after removing dependency in RN. | ||
return false; | ||
} // Exposed for testing. | ||
@@ -465,3 +549,3 @@ | ||
// const value = useCustomHook(); | ||
// _s(); /* Second call triggers collecting the custom Hook list. | ||
// _s(); /* Call without arguments triggers collecting the custom Hook list. | ||
// * This doesn't happen during the module evaluation because we | ||
@@ -473,3 +557,3 @@ // * don't want to change the module order with inline requires. | ||
// | ||
// /* First call specifies the signature: */ | ||
// /* Call with arguments attaches the signature to the type: */ | ||
// _s( | ||
@@ -483,22 +567,33 @@ // Hello, | ||
{ | ||
var call = 0; | ||
var savedType; | ||
var hasCustomHooks; | ||
var didCollectHooks = false; | ||
return function (type, key, forceReset, getCustomHooks) { | ||
switch (call++) { | ||
case 0: | ||
if (typeof key === 'string') { | ||
// We're in the initial phase that associates signatures | ||
// with the functions. Note this may be called multiple times | ||
// in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))). | ||
if (!savedType) { | ||
// We're in the innermost call, so this is the actual type. | ||
savedType = type; | ||
hasCustomHooks = typeof getCustomHooks === 'function'; | ||
} // Set the signature for all types (even wrappers!) in case | ||
// they have no signatures of their own. This is to prevent | ||
// problems like https://github.com/facebook/react/issues/20417. | ||
if (type != null && (typeof type === 'function' || typeof type === 'object')) { | ||
setSignature(type, key, forceReset, getCustomHooks); | ||
break; | ||
} | ||
case 1: | ||
if (hasCustomHooks) { | ||
collectCustomHooksForSignature(savedType); | ||
} | ||
break; | ||
return type; | ||
} else { | ||
// We're in the _s() call without arguments, which means | ||
// this is the time to collect custom Hook signatures. | ||
// Only do this once. This path is hot and runs *inside* every render! | ||
if (!didCollectHooks && hasCustomHooks) { | ||
didCollectHooks = true; | ||
collectCustomHooksForSignature(savedType); | ||
} | ||
} | ||
return type; | ||
}; | ||
@@ -543,3 +638,3 @@ } | ||
if (type != null) { | ||
switch (type.$$typeof) { | ||
switch (getProperty(type, '$$typeof')) { | ||
case REACT_FORWARD_REF_TYPE: | ||
@@ -566,24 +661,15 @@ case REACT_MEMO_TYPE: | ||
var ReactFreshRuntime = Object.freeze({ | ||
performReactRefresh: performReactRefresh, | ||
register: register, | ||
setSignature: setSignature, | ||
collectCustomHooksForSignature: collectCustomHooksForSignature, | ||
getFamilyByID: getFamilyByID, | ||
getFamilyByType: getFamilyByType, | ||
findAffectedHostInstances: findAffectedHostInstances, | ||
injectIntoGlobalHook: injectIntoGlobalHook, | ||
hasUnrecoverableErrors: hasUnrecoverableErrors, | ||
_getMountedRootCount: _getMountedRootCount, | ||
createSignatureFunctionForTransform: createSignatureFunctionForTransform, | ||
isLikelyComponentType: isLikelyComponentType | ||
}); | ||
// This is hacky but makes it work with both Rollup and Jest. | ||
var runtime = ReactFreshRuntime.default || ReactFreshRuntime; | ||
module.exports = runtime; | ||
exports._getMountedRootCount = _getMountedRootCount; | ||
exports.collectCustomHooksForSignature = collectCustomHooksForSignature; | ||
exports.createSignatureFunctionForTransform = createSignatureFunctionForTransform; | ||
exports.findAffectedHostInstances = findAffectedHostInstances; | ||
exports.getFamilyByID = getFamilyByID; | ||
exports.getFamilyByType = getFamilyByType; | ||
exports.hasUnrecoverableErrors = hasUnrecoverableErrors; | ||
exports.injectIntoGlobalHook = injectIntoGlobalHook; | ||
exports.isLikelyComponentType = isLikelyComponentType; | ||
exports.performReactRefresh = performReactRefresh; | ||
exports.register = register; | ||
exports.setSignature = setSignature; | ||
})(); | ||
} |
@@ -7,4 +7,4 @@ { | ||
], | ||
"version": "0.0.0-experimental-38dd17ab9", | ||
"homepage": "https://reactjs.org/", | ||
"version": "0.0.0-experimental-38e3b23483-20240529", | ||
"homepage": "https://react.dev/", | ||
"bugs": "https://github.com/facebook/react/issues", | ||
@@ -17,7 +17,11 @@ "license": "MIT", | ||
"runtime.js", | ||
"build-info.json", | ||
"cjs/", | ||
"umd/" | ||
"cjs/" | ||
], | ||
"main": "index.js", | ||
"main": "runtime.js", | ||
"exports": { | ||
".": "./runtime.js", | ||
"./runtime": "./runtime.js", | ||
"./babel": "./babel.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"repository": { | ||
@@ -30,3 +34,8 @@ "type": "git", | ||
"node": ">=0.10.0" | ||
}, | ||
"devDependencies": { | ||
"react-16-8": "npm:react@16.8.0", | ||
"react-dom-16-8": "npm:react-dom@16.8.0", | ||
"scheduler-0-13": "npm:scheduler@0.13.0" | ||
} | ||
} | ||
} |
# react-refresh | ||
This is an experimental package for hot reloading. | ||
This package implements the wiring necessary to integrate Fast Refresh into bundlers. Fast Refresh is a feature that lets you edit React components in a running application without losing their state. It is similar to an old feature known as "hot reloading", but Fast Refresh is more reliable and officially supported by React. | ||
**Its API is not as stable as that of React, React Native, or React DOM, and does not follow the common versioning scheme.** | ||
**Use it at your own risk.** | ||
This package is primarily aimed at developers of bundler plugins. If you’re working on one, here is a [rough guide](https://github.com/facebook/react/issues/16604#issuecomment-528663101) for Fast Refresh integration using this package. |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-refresh-runtime.production.min.js'); | ||
module.exports = require('./cjs/react-refresh-runtime.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-refresh-runtime.development.js'); | ||
} |
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
71756
1840
1
3
9
6