react-refresh
Advanced tools
Comparing version 0.0.0-8d5403877 to 0.0.0-8d7535e54
{ | ||
"branch": "master", | ||
"buildNumber": "35115", | ||
"checksum": "1fa61b1", | ||
"commit": "8d5403877", | ||
"buildNumber": "90718", | ||
"checksum": "348207c", | ||
"commit": "8d7535e54", | ||
"environment": "ci", | ||
"reactVersion": "16.9.0-canary-8d5403877" | ||
"reactVersion": "16.12.0-8d7535e54" | ||
} |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-8d5403877 | ||
/** @license React v0.0.0-8d7535e54 | ||
* react-refresh-babel.development.js | ||
@@ -18,3 +18,5 @@ * | ||
var ReactFreshBabelPlugin = function (babel) { | ||
function ReactFreshBabelPlugin (babel) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (typeof babel.getEnv === 'function') { | ||
@@ -24,4 +26,4 @@ // Only available in Babel 7. | ||
if (env !== 'development') { | ||
throw new Error('React Refresh Babel transform should only be enabled in development environment. ' + 'Instead, the environment is: "' + env + '".'); | ||
if (env !== 'development' && !opts.skipEnvCheck) { | ||
throw new Error('React Refresh Babel transform should only be enabled in development environment. ' + 'Instead, the environment is: "' + env + '". If you want to override this check, pass {skipEnvCheck: true} as plugin options.'); | ||
} | ||
@@ -31,2 +33,4 @@ } | ||
var t = babel.types; | ||
var refreshReg = t.identifier(opts.refreshReg || '$RefreshReg$'); | ||
var refreshSig = t.identifier(opts.refreshSig || '$RefreshSig$'); | ||
var registrationsByProgramPath = new Map(); | ||
@@ -172,5 +176,3 @@ | ||
} else if (calleeType === 'MemberExpression') {// Could be something like React.forwardRef(...) | ||
// Pass through. | ||
} else { | ||
} else if (calleeType === 'MemberExpression') ; else { | ||
// More complicated call. | ||
@@ -360,4 +362,15 @@ return false; | ||
}); | ||
var args = [node, t.stringLiteral(key)]; | ||
var finalKey = key; | ||
if (typeof require === 'function' && !opts.emitFullSignatures) { | ||
// Prefer to hash when we can (e.g. outside of ASTExplorer). | ||
// This makes it deterministically compact, even if there's | ||
// e.g. a useState ininitalizer with some code inside. | ||
// We also need it for www that has transforms like cx() | ||
// that don't understand if something is part of a string. | ||
finalKey = require('crypto').createHash('sha1').update(key).digest('base64'); | ||
} | ||
var args = [node, t.stringLiteral(finalKey)]; | ||
if (forceReset || customHooksInScope.length > 0) { | ||
@@ -564,3 +577,3 @@ args.push(t.booleanLiteral(forceReset)); | ||
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. | ||
@@ -610,6 +623,10 @@ // This is used to signal when first render happens. | ||
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. | ||
// This is used to signal when first render happens. | ||
if (path.node.body.type !== 'BlockStatement') { | ||
path.node.body = t.blockStatement([t.returnStatement(path.node.body)]); | ||
} | ||
path.get('body').unshiftContainer('body', t.expressionStatement(t.callExpression(sigCallID, []))); // The second call is around the function itself. | ||
@@ -739,3 +756,3 @@ // This is used to associate a type with a signature. | ||
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)); | ||
@@ -747,14 +764,8 @@ }); | ||
}; | ||
}; | ||
} | ||
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; | ||
var babel = ReactFreshBabelPlugin.default || ReactFreshBabelPlugin; | ||
@@ -761,0 +772,0 @@ module.exports = babel; |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-8d5403877 | ||
/** @license React v0.0.0-8d7535e54 | ||
* react-refresh-babel.production.min.js | ||
@@ -10,14 +10,15 @@ * | ||
'use strict';function v(q){function r(a,b){var c=a.scope.generateUidIdentifier("c");l.has(a)||l.set(a,[]);l.get(a).push({handle:c,persistentID:b});return c}function t(a){return"string"===typeof a&&"A"<=a[0]&&"Z">=a[0]}function m(a,b,c){var d=b.node;switch(d.type){case "Identifier":if(!t(d.name))break;c(a,d,null);return!0;case "FunctionDeclaration":return c(a,d.id,null),!0;case "ArrowFunctionExpression":if("ArrowFunctionExpression"===d.body.type)break;c(a,d,b);return!0;case "FunctionExpression":return c(a, | ||
d,b),!0;case "CallExpression":var f=b.get("arguments");if(void 0===f||0===f.length)break;var g=b.get("callee");switch(g.node.type){case "MemberExpression":case "Identifier":g=g.getSource();if(!m(a+"$"+g,f[0],c))return!1;c(a,d,b);return!0;default:return!1}case "VariableDeclarator":if(f=d.init,null!==f&&(g=d.id.name,t(g))){switch(f.type){case "ArrowFunctionExpression":case "FunctionExpression":break;case "CallExpression":d=f.callee;var e=d.type;if("Import"===e)return!1;if("Identifier"===e){if(0===d.name.indexOf("require")|| | ||
0===d.name.indexOf("import"))return!1}else if("MemberExpression"!==e)return!1;break;case "TaggedTemplateExpression":break;default:return!1}d=b.get("init");if(m(a,d,c))return!0;g=b.scope.getBinding(g);if(void 0===g)return;b=!1;g=g.referencePaths;for(e=0;e<g.length;e++){var h=g[e];if("JSXIdentifier"===h.node.type||"Identifier"===h.node.type){h=h.parent;if("JSXOpeningElement"===h.type)b=!0;else if("CallExpression"===h.type){h=h.callee;var k=void 0;switch(h.type){case "Identifier":k=h.name;break;case "MemberExpression":k= | ||
h.property.name}switch(k){case "createElement":case "jsx":case "jsxDEV":case "jsxs":b=!0}}if(b)return c(a,f,d),!0}}}}return!1}function w(a){a=n.get(a);return void 0===a?null:{key:a.map(function(a){return a.name+"{"+a.key+"}"}).join("\n"),customHooks:a.filter(function(a){a:switch(a.name){case "useState":case "React.useState":case "useReducer":case "React.useReducer":case "useEffect":case "React.useEffect":case "useLayoutEffect":case "React.useLayoutEffect":case "useMemo":case "React.useMemo":case "useCallback":case "React.useCallback":case "useRef":case "React.useRef":case "useContext":case "React.useContext":case "useImperativeMethods":case "React.useImperativeMethods":case "useDebugValue":case "React.useDebugValue":a= | ||
!0;break a;default:a=!1}return!a}).map(function(a){return e.cloneDeep(a.callee)})}}function C(a){a=a.hub.file;var b=x.get(a);if(void 0!==b)return b;b=!1;for(var c=a.ast.comments,d=0;d<c.length;d++)if(-1!==c[d].value.indexOf("@refresh reset")){b=!0;break}x.set(a,b);return b}function u(a,b,c){var d=b.key;b=b.customHooks;var f=C(c.path),g=[];b.forEach(function(a){switch(a.type){case "MemberExpression":if("Identifier"===a.object.type)var b=a.object.name;break;case "Identifier":b=a.name}c.hasBinding(b)? | ||
g.push(a):f=!0});a=[a,e.stringLiteral(d)];(f||0<g.length)&&a.push(e.booleanLiteral(f));0<g.length&&a.push(e.functionExpression(null,[],e.blockStatement([e.returnStatement(e.arrayExpression(g))])));return a}if("function"===typeof q.getEnv){var y=q.getEnv();if("development"!==y)throw Error('React Refresh Babel transform should only be enabled in development environment. Instead, the environment is: "'+y+'".');}var e=q.types,l=new Map,x=new WeakMap,k=new WeakSet,p=new WeakSet,z=new WeakSet,n=new WeakMap, | ||
D={CallExpression:function(a){var b=a.node.callee,c=null;switch(b.type){case "Identifier":c=b.name;break;case "MemberExpression":c=b.property.name}if(null!==c&&/^use[A-Z]/.test(c)&&(b=a.scope.getFunctionParent(),null!==b)){b=b.block;n.has(b)||n.set(b,[]);b=n.get(b);var d="";"VariableDeclarator"===a.parent.type&&(d=a.parentPath.get("id").getSource());var f=a.get("arguments");"useState"===c&&0<f.length?d+="("+f[0].getSource()+")":"useReducer"===c&&1<f.length&&(d+="("+f[1].getSource()+")");b.push({callee:a.node.callee, | ||
name:c,key:d})}}};return{visitor:{ExportDefaultDeclaration:function(a){var b=a.node,c=b.declaration,d=a.get("declaration");if("CallExpression"===c.type&&!k.has(b)){k.add(b);var f=a.parentPath;m("%default%",d,function(a,b,c){null!==c&&(a=r(f,a),c.replaceWith(e.assignmentExpression("=",a,b)))})}},FunctionDeclaration:{enter:function(a){var b=a.node;switch(a.parent.type){case "Program":var c=a;var d=a.parentPath;break;case "ExportNamedDeclaration":c=a.parentPath;d=c.parentPath;break;case "ExportDefaultDeclaration":c= | ||
a.parentPath;d=c.parentPath;break;default:return}var f=b.id;null!==f&&(f=f.name,t(f)&&!k.has(b)&&(k.add(b),m(f,a,function(a,b){a=r(d,a);c.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,b)))})))},exit:function(a){var b=a.node,c=b.id;if(null!==c){var d=w(b);if(null!==d&&!p.has(b)){p.add(b);b=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:b,init:e.callExpression(e.identifier("$RefreshSig$"),[])});a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(b, | ||
[])));var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(b,u(c,d,f.scope))))}}}},"ArrowFunctionExpression|FunctionExpression":{exit:function(a){var b=a.node,c=w(b);if(null!==c&&!p.has(b)){p.add(b);var d=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:d,init:e.callExpression(e.identifier("$RefreshSig$"),[])});a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(d,[])));if("VariableDeclarator"=== | ||
a.parent.type){var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(d,u(a.parent.id,c,f.scope))))}else a.replaceWith(e.callExpression(d,u(b,c,a.scope)))}}},VariableDeclaration:function(a){var b=a.node;switch(a.parent.type){case "Program":var c=a;var d=a.parentPath;break;case "ExportNamedDeclaration":c=a.parentPath;d=c.parentPath;break;case "ExportDefaultDeclaration":c=a.parentPath;d=c.parentPath;break;default:return}if(!k.has(b)&& | ||
(k.add(b),a=a.get("declarations"),1===a.length)){var f=a[0];m(f.node.id.name,f,function(a,b,h){null!==h&&(a=r(d,a),"ArrowFunctionExpression"!==b.type&&"FunctionExpression"!==b.type||"VariableDeclarator"!==h.parent.type?h.replaceWith(e.assignmentExpression("=",a,b)):c.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,f.node.id))))})}},Program:{enter:function(a){a.traverse(D)},exit:function(a){var b=l.get(a);if(void 0!==b){var c=a.node;if(!z.has(c)){z.add(c);l.delete(a);var d=[];a.pushContainer("body", | ||
e.variableDeclaration("var",d));b.forEach(function(b){var c=b.handle;b=b.persistentID;a.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("$RefreshReg$"),[c,e.stringLiteral(b)])));d.push(e.variableDeclarator(c))})}}}}}}}var A={default:v},B=A&&v||A;module.exports=B.default||B; | ||
'use strict';function w(r){function t(a,b){var d=a.scope.generateUidIdentifier("c");l.has(a)||l.set(a,[]);l.get(a).push({handle:d,persistentID:b});return d}function u(a){return"string"===typeof a&&"A"<=a[0]&&"Z">=a[0]}function m(a,b,d){var c=b.node;switch(c.type){case "Identifier":if(!u(c.name))break;d(a,c,null);return!0;case "FunctionDeclaration":return d(a,c.id,null),!0;case "ArrowFunctionExpression":if("ArrowFunctionExpression"===c.body.type)break;d(a,c,b);return!0;case "FunctionExpression":return d(a, | ||
c,b),!0;case "CallExpression":var f=b.get("arguments");if(void 0===f||0===f.length)break;var g=b.get("callee");switch(g.node.type){case "MemberExpression":case "Identifier":g=g.getSource();if(!m(a+"$"+g,f[0],d))return!1;d(a,c,b);return!0;default:return!1}case "VariableDeclarator":if(f=c.init,null!==f&&(g=c.id.name,u(g))){switch(f.type){case "ArrowFunctionExpression":case "FunctionExpression":break;case "CallExpression":c=f.callee;var e=c.type;if("Import"===e)return!1;if("Identifier"===e){if(0===c.name.indexOf("require")|| | ||
0===c.name.indexOf("import"))return!1}else if("MemberExpression"!==e)return!1;break;case "TaggedTemplateExpression":break;default:return!1}c=b.get("init");if(m(a,c,d))return!0;g=b.scope.getBinding(g);if(void 0===g)return;b=!1;g=g.referencePaths;for(e=0;e<g.length;e++){var h=g[e];if("JSXIdentifier"===h.node.type||"Identifier"===h.node.type){h=h.parent;if("JSXOpeningElement"===h.type)b=!0;else if("CallExpression"===h.type){h=h.callee;var k=void 0;switch(h.type){case "Identifier":k=h.name;break;case "MemberExpression":k= | ||
h.property.name}switch(k){case "createElement":case "jsx":case "jsxDEV":case "jsxs":b=!0}}if(b)return d(a,f,c),!0}}}}return!1}function x(a){a=n.get(a);return void 0===a?null:{key:a.map(function(a){return a.name+"{"+a.key+"}"}).join("\n"),customHooks:a.filter(function(a){a:switch(a.name){case "useState":case "React.useState":case "useReducer":case "React.useReducer":case "useEffect":case "React.useEffect":case "useLayoutEffect":case "React.useLayoutEffect":case "useMemo":case "React.useMemo":case "useCallback":case "React.useCallback":case "useRef":case "React.useRef":case "useContext":case "React.useContext":case "useImperativeMethods":case "React.useImperativeMethods":case "useDebugValue":case "React.useDebugValue":a= | ||
!0;break a;default:a=!1}return!a}).map(function(a){return e.cloneDeep(a.callee)})}}function C(a){a=a.hub.file;var b=y.get(a);if(void 0!==b)return b;b=!1;for(var d=a.ast.comments,c=0;c<d.length;c++)if(-1!==d[c].value.indexOf("@refresh reset")){b=!0;break}y.set(a,b);return b}function v(a,b,d){var c=b.key;b=b.customHooks;var f=C(d.path),g=[];b.forEach(function(a){switch(a.type){case "MemberExpression":if("Identifier"===a.object.type)var b=a.object.name;break;case "Identifier":b=a.name}d.hasBinding(b)? | ||
g.push(a):f=!0});b=c;"function"!==typeof require||p.emitFullSignatures||(b=require("crypto").createHash("sha1").update(c).digest("base64"));a=[a,e.stringLiteral(b)];(f||0<g.length)&&a.push(e.booleanLiteral(f));0<g.length&&a.push(e.functionExpression(null,[],e.blockStatement([e.returnStatement(e.arrayExpression(g))])));return a}var p=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if("function"===typeof r.getEnv){var z=r.getEnv();if("development"!==z&&!p.skipEnvCheck)throw Error('React Refresh Babel transform should only be enabled in development environment. Instead, the environment is: "'+ | ||
z+'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.');}var e=r.types,D=e.identifier(p.refreshReg||"$RefreshReg$"),A=e.identifier(p.refreshSig||"$RefreshSig$"),l=new Map,y=new WeakMap,k=new WeakSet,q=new WeakSet,B=new WeakSet,n=new WeakMap,E={CallExpression:function(a){var b=a.node.callee,d=null;switch(b.type){case "Identifier":d=b.name;break;case "MemberExpression":d=b.property.name}if(null!==d&&/^use[A-Z]/.test(d)&&(b=a.scope.getFunctionParent(),null!==b)){b=b.block; | ||
n.has(b)||n.set(b,[]);b=n.get(b);var c="";"VariableDeclarator"===a.parent.type&&(c=a.parentPath.get("id").getSource());var f=a.get("arguments");"useState"===d&&0<f.length?c+="("+f[0].getSource()+")":"useReducer"===d&&1<f.length&&(c+="("+f[1].getSource()+")");b.push({callee:a.node.callee,name:d,key:c})}}};return{visitor:{ExportDefaultDeclaration:function(a){var b=a.node,d=b.declaration,c=a.get("declaration");if("CallExpression"===d.type&&!k.has(b)){k.add(b);var f=a.parentPath;m("%default%",c,function(a, | ||
b,c){null!==c&&(a=t(f,a),c.replaceWith(e.assignmentExpression("=",a,b)))})}},FunctionDeclaration:{enter:function(a){var b=a.node;switch(a.parent.type){case "Program":var d=a;var c=a.parentPath;break;case "ExportNamedDeclaration":d=a.parentPath;c=d.parentPath;break;case "ExportDefaultDeclaration":d=a.parentPath;c=d.parentPath;break;default:return}var f=b.id;null!==f&&(f=f.name,u(f)&&!k.has(b)&&(k.add(b),m(f,a,function(a,b){a=t(c,a);d.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,b)))})))}, | ||
exit:function(a){var b=a.node,d=b.id;if(null!==d){var c=x(b);if(null!==c&&!q.has(b)){q.add(b);b=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:b,init:e.callExpression(A,[])});a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(b,[])));var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(b,v(d,c,f.scope))))}}}},"ArrowFunctionExpression|FunctionExpression":{exit:function(a){var b= | ||
a.node,d=x(b);if(null!==d&&!q.has(b)){q.add(b);var c=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:c,init:e.callExpression(A,[])});"BlockStatement"!==a.node.body.type&&(a.node.body=e.blockStatement([e.returnStatement(a.node.body)]));a.get("body").unshiftContainer("body",e.expressionStatement(e.callExpression(c,[])));if("VariableDeclarator"===a.parent.type){var f=null;a.find(function(a){if(a.parentPath.isBlock())return f=a,!0});null!==f&&f.insertAfter(e.expressionStatement(e.callExpression(c, | ||
v(a.parent.id,d,f.scope))))}else a.replaceWith(e.callExpression(c,v(b,d,a.scope)))}}},VariableDeclaration:function(a){var b=a.node;switch(a.parent.type){case "Program":var d=a;var c=a.parentPath;break;case "ExportNamedDeclaration":d=a.parentPath;c=d.parentPath;break;case "ExportDefaultDeclaration":d=a.parentPath;c=d.parentPath;break;default:return}if(!k.has(b)&&(k.add(b),a=a.get("declarations"),1===a.length)){var f=a[0];m(f.node.id.name,f,function(a,b,h){null!==h&&(a=t(c,a),"ArrowFunctionExpression"!== | ||
b.type&&"FunctionExpression"!==b.type||"VariableDeclarator"!==h.parent.type?h.replaceWith(e.assignmentExpression("=",a,b)):d.insertAfter(e.expressionStatement(e.assignmentExpression("=",a,f.node.id))))})}},Program:{enter:function(a){a.traverse(E)},exit:function(a){var b=l.get(a);if(void 0!==b){var d=a.node;if(!B.has(d)){B.add(d);l.delete(a);var c=[];a.pushContainer("body",e.variableDeclaration("var",c));b.forEach(function(b){var d=b.handle;a.pushContainer("body",e.expressionStatement(e.callExpression(D, | ||
[d,e.stringLiteral(b.persistentID)])));c.push(e.variableDeclarator(d))})}}}}}}}module.exports=w.default||w; |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-8d5403877 | ||
/** @license React v0.0.0-8d7535e54 | ||
* react-refresh-runtime.development.js | ||
@@ -21,16 +21,3 @@ * | ||
var hasSymbol = typeof Symbol === 'function' && Symbol.for; | ||
// 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; | ||
@@ -55,7 +42,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) { | ||
@@ -153,10 +146,34 @@ 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(); | ||
@@ -195,6 +212,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) { | ||
@@ -204,2 +228,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 { | ||
@@ -215,4 +252,4 @@ helpers.scheduleRoot(root, element); | ||
}); | ||
mountedRoots.forEach(function (root) { | ||
var helpers = helpersByRoot.get(root); | ||
mountedRootsSnapshot.forEach(function (root) { | ||
var helpers = helpersByRootSnapshot.get(root); | ||
@@ -223,2 +260,5 @@ if (helpers === undefined) { | ||
if (!mountedRoots.has(root)) {// No longer mounted. | ||
} | ||
try { | ||
@@ -240,2 +280,4 @@ helpers.scheduleRefresh(root, update); | ||
return update; | ||
} finally { | ||
isPerformingRefresh = false; | ||
} | ||
@@ -357,2 +399,3 @@ } | ||
globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { | ||
renderers: new Map(), | ||
supportsFiber: true, | ||
@@ -362,2 +405,3 @@ inject: function (injected) { | ||
}, | ||
onScheduleFiberRoot: function (id, root, children) {}, | ||
onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {}, | ||
@@ -380,7 +424,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) { | ||
@@ -407,5 +476,3 @@ var helpers = helpersByRendererID.get(id); | ||
failedRoots.delete(root); | ||
} else if (wasMounted && isMounted) {// Update an existing root. | ||
// This doesn't affect our mounted root Set. | ||
} else if (wasMounted && !isMounted) { | ||
} else if (wasMounted && isMounted) ; else if (wasMounted && !isMounted) { | ||
// Unmount an existing root. | ||
@@ -416,4 +483,3 @@ mountedRoots.delete(root); | ||
// 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 { | ||
@@ -423,13 +489,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); | ||
} | ||
@@ -447,3 +505,4 @@ } | ||
function hasUnrecoverableErrors() { | ||
return didSomeRootFailOnMount; | ||
// TODO: delete this after removing dependency in RN. | ||
return false; | ||
} // Exposed for testing. | ||
@@ -480,14 +539,24 @@ | ||
{ | ||
var call = 0; | ||
// We'll fill in the signature in two steps. | ||
// First, we'll know the signature itself. This happens outside the component. | ||
// Then, we'll know the references to custom Hooks. This happens inside the component. | ||
// After that, the returned function will be a fast path no-op. | ||
var status = 'needsSignature'; | ||
var savedType; | ||
var hasCustomHooks; | ||
return function (type, key, forceReset, getCustomHooks) { | ||
switch (call++) { | ||
case 0: | ||
savedType = type; | ||
hasCustomHooks = typeof getCustomHooks === 'function'; | ||
setSignature(type, key, forceReset, getCustomHooks); | ||
switch (status) { | ||
case 'needsSignature': | ||
if (type !== undefined) { | ||
// If we received an argument, this is the initial registration call. | ||
savedType = type; | ||
hasCustomHooks = typeof getCustomHooks === 'function'; | ||
setSignature(type, key, forceReset, getCustomHooks); // The next call we expect is from inside a function, to fill in the custom Hooks. | ||
status = 'needsCustomHooks'; | ||
} | ||
break; | ||
case 1: | ||
case 'needsCustomHooks': | ||
if (hasCustomHooks) { | ||
@@ -497,2 +566,3 @@ collectCustomHooksForSignature(savedType); | ||
status = 'resolved'; | ||
break; | ||
@@ -563,15 +633,16 @@ } | ||
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 | ||
var ReactFreshRuntime = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
performReactRefresh: performReactRefresh, | ||
register: register, | ||
setSignature: setSignature, | ||
collectCustomHooksForSignature: collectCustomHooksForSignature, | ||
getFamilyByID: getFamilyByID, | ||
getFamilyByType: getFamilyByType, | ||
findAffectedHostInstances: findAffectedHostInstances, | ||
injectIntoGlobalHook: injectIntoGlobalHook, | ||
hasUnrecoverableErrors: hasUnrecoverableErrors, | ||
_getMountedRootCount: _getMountedRootCount, | ||
createSignatureFunctionForTransform: createSignatureFunctionForTransform, | ||
isLikelyComponentType: isLikelyComponentType | ||
}); | ||
@@ -578,0 +649,0 @@ |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.0.0-8d5403877 | ||
/** @license React v0.0.0-8d7535e54 | ||
* react-refresh-runtime.production.min.js | ||
@@ -3,0 +3,0 @@ * |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.0.0-8d5403877", | ||
"version": "0.0.0-8d7535e54", | ||
"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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
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
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
53831
1199
2
3
1