react-refresh 0.5.2 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /** @license React v0.5.2
1
+ /** @license React vundefined
2
2
  * react-refresh-babel.development.js
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -28,6 +28,8 @@ var ReactFreshBabelPlugin = function (babel) {
28
28
  }
29
29
 
30
30
  var t = babel.types;
31
+ var refreshReg = t.identifier(opts.refreshReg || '$RefreshReg$');
32
+ var refreshSig = t.identifier(opts.refreshSig || '$RefreshSig$');
31
33
  var registrationsByProgramPath = new Map();
32
34
 
33
35
  function createRegistration(programPath, persistentID) {
@@ -569,7 +571,7 @@ var ReactFreshBabelPlugin = function (babel) {
569
571
  var sigCallID = path.scope.generateUidIdentifier('_s');
570
572
  path.scope.parent.push({
571
573
  id: sigCallID,
572
- init: t.callExpression(t.identifier('$RefreshSig$'), [])
574
+ init: t.callExpression(refreshSig, [])
573
575
  }); // The signature call is split in two parts. One part is called inside the function.
574
576
  // This is used to signal when first render happens.
575
577
 
@@ -614,7 +616,7 @@ var ReactFreshBabelPlugin = function (babel) {
614
616
  var sigCallID = path.scope.generateUidIdentifier('_s');
615
617
  path.scope.parent.push({
616
618
  id: sigCallID,
617
- init: t.callExpression(t.identifier('$RefreshSig$'), [])
619
+ init: t.callExpression(refreshSig, [])
618
620
  }); // The signature call is split in two parts. One part is called inside the function.
619
621
  // This is used to signal when first render happens.
620
622
 
@@ -746,7 +748,7 @@ var ReactFreshBabelPlugin = function (babel) {
746
748
  registrations.forEach(function (_ref) {
747
749
  var handle = _ref.handle,
748
750
  persistentID = _ref.persistentID;
749
- path.pushContainer('body', t.expressionStatement(t.callExpression(t.identifier('$RefreshReg$'), [handle, t.stringLiteral(persistentID)])));
751
+ path.pushContainer('body', t.expressionStatement(t.callExpression(refreshReg, [handle, t.stringLiteral(persistentID)])));
750
752
  declarators.push(t.variableDeclarator(handle));
751
753
  });
752
754
  }
@@ -1,4 +1,4 @@
1
- /** @license React v0.5.2
1
+ /** @license React vundefined
2
2
  * react-refresh-babel.production.min.js
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -7,17 +7,17 @@
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
 
10
- 'use strict';function v(q){function r(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 t(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(!t(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,
11
- 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,t(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")||
10
+ '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,
11
+ 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")||
12
12
  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=
13
- 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 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=
14
- !0;break a;default:a=!1}return!a}).map(function(a){return e.cloneDeep(a.callee)})}}function D(a){a=a.hub.file;var b=x.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}x.set(a,b);return b}function u(a,b,d){var c=b.key;b=b.customHooks;var f=D(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)?
15
- g.push(a):f=!0});b=c;"function"!==typeof require||y.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 y=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if("function"===typeof q.getEnv){var z=q.getEnv();if("development"!==z&&!y.skipEnvCheck)throw Error('React Refresh Babel transform should only be enabled in development environment. Instead, the environment is: "'+
16
- z+'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.');}var e=q.types,l=new Map,x=new WeakMap,k=new WeakSet,p=new WeakSet,A=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());
17
- 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=r(f,a),c.replaceWith(e.assignmentExpression("=",a,b)))})}},FunctionDeclaration:{enter:function(a){var b=
18
- 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,t(f)&&!k.has(b)&&(k.add(b),m(f,a,function(a,b){a=r(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=w(b);if(null!==c&&!p.has(b)){p.add(b);b=a.scope.generateUidIdentifier("_s");
19
- 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(d,c,f.scope))))}}}},"ArrowFunctionExpression|FunctionExpression":{exit:function(a){var b=a.node,d=w(b);if(null!==d&&!p.has(b)){p.add(b);var c=a.scope.generateUidIdentifier("_s");a.scope.parent.push({id:c,
20
- init:e.callExpression(e.identifier("$RefreshSig$"),[])});"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,u(a.parent.id,d,f.scope))))}else a.replaceWith(e.callExpression(c,u(b,d,a.scope)))}}},
21
- 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=r(c,a),"ArrowFunctionExpression"!==b.type&&"FunctionExpression"!==b.type||"VariableDeclarator"!==h.parent.type?h.replaceWith(e.assignmentExpression("=",
22
- 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(!A.has(d)){A.add(d);l.delete(a);var c=[];a.pushContainer("body",e.variableDeclaration("var",c));b.forEach(function(b){var d=b.handle;b=b.persistentID;a.pushContainer("body",e.expressionStatement(e.callExpression(e.identifier("$RefreshReg$"),[d,e.stringLiteral(b)])));c.push(e.variableDeclarator(d))})}}}}}}}
23
- var B={default:v},C=B&&v||B;module.exports=C.default||C;
13
+ 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=
14
+ !0;break a;default:a=!1}return!a}).map(function(a){return e.cloneDeep(a.callee)})}}function E(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=E(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)?
15
+ 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: "'+
16
+ z+'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.');}var e=r.types,F=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,G={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;
17
+ 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,
18
+ 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)))})))},
19
+ 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=
20
+ 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,
21
+ 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"!==
22
+ 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(G)},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(F,
23
+ [d,e.stringLiteral(b.persistentID)])));c.push(e.variableDeclarator(d))})}}}}}}}var C={default:w},D=C&&w||C;module.exports=D.default||D;
@@ -1,4 +1,4 @@
1
- /** @license React v0.5.2
1
+ /** @license React vundefined
2
2
  * react-refresh-runtime.development.js
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -51,10 +51,16 @@ var pendingUpdates = []; // This is injected by the renderer via DevTools global
51
51
  var helpersByRendererID = new Map();
52
52
  var helpersByRoot = new Map(); // We keep track of mounted roots so we can schedule updates.
53
53
 
54
- var mountedRoots = new Set(); // If a root captures an error, we add its element to this Map so we can retry on edit.
54
+ var mountedRoots = new Set(); // If a root captures an error, we remember it so we can retry on edit.
55
55
 
56
- var failedRoots = new Map();
57
- var didSomeRootFailOnMount = false;
56
+ var failedRoots = new Set(); // In environments that support WeakMap, we also remember the last element for every root.
57
+ // It needs to be weak because we do this even for roots that failed to mount.
58
+ // If there is no WeakMap, we won't attempt to do retrying.
59
+ // $FlowIssue
60
+
61
+ var rootElements = // $FlowIssue
62
+ typeof WeakMap === 'function' ? new WeakMap() : null;
63
+ var isPerformingRefresh = false;
58
64
 
59
65
  function computeFullKey(signature) {
60
66
  if (signature.fullKey !== null) {
@@ -148,14 +154,37 @@ function canPreserveStateBetween(prevType, nextType) {
148
154
  function resolveFamily(type) {
149
155
  // Only check updated types to keep lookups fast.
150
156
  return updatedFamiliesByType.get(type);
157
+ } // If we didn't care about IE11, we could use new Map/Set(iterable).
158
+
159
+
160
+ function cloneMap(map) {
161
+ var clone = new Map();
162
+ map.forEach(function (value, key) {
163
+ clone.set(key, value);
164
+ });
165
+ return clone;
166
+ }
167
+
168
+ function cloneSet(set) {
169
+ var clone = new Set();
170
+ set.forEach(function (value) {
171
+ clone.add(value);
172
+ });
173
+ return clone;
151
174
  }
152
175
 
153
176
  function performReactRefresh() {
154
- {
155
- if (pendingUpdates.length === 0) {
156
- return null;
157
- }
177
+ if (pendingUpdates.length === 0) {
178
+ return null;
179
+ }
180
+
181
+ if (isPerformingRefresh) {
182
+ return null;
183
+ }
184
+
185
+ isPerformingRefresh = true;
158
186
 
187
+ try {
159
188
  var staleFamilies = new Set();
160
189
  var updatedFamilies = new Set();
161
190
  var updates = pendingUpdates;
@@ -189,14 +218,34 @@ function performReactRefresh() {
189
218
  helpers.setRefreshHandler(resolveFamily);
190
219
  });
191
220
  var didError = false;
192
- var firstError = null;
193
- failedRoots.forEach(function (element, root) {
194
- var helpers = helpersByRoot.get(root);
221
+ var firstError = null; // We snapshot maps and sets that are mutated during commits.
222
+ // If we don't do this, there is a risk they will be mutated while
223
+ // we iterate over them. For example, trying to recover a failed root
224
+ // may cause another root to be added to the failed list -- an infinite loop.
225
+
226
+ var failedRootsSnapshot = cloneSet(failedRoots);
227
+ var mountedRootsSnapshot = cloneSet(mountedRoots);
228
+ var helpersByRootSnapshot = cloneMap(helpersByRoot);
229
+ failedRootsSnapshot.forEach(function (root) {
230
+ var helpers = helpersByRootSnapshot.get(root);
195
231
 
196
232
  if (helpers === undefined) {
197
233
  throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
198
234
  }
199
235
 
236
+ if (!failedRoots.has(root)) {// No longer failed.
237
+ }
238
+
239
+ if (rootElements === null) {
240
+ return;
241
+ }
242
+
243
+ if (!rootElements.has(root)) {
244
+ return;
245
+ }
246
+
247
+ var element = rootElements.get(root);
248
+
200
249
  try {
201
250
  helpers.scheduleRoot(root, element);
202
251
  } catch (err) {
@@ -207,13 +256,16 @@ function performReactRefresh() {
207
256
 
208
257
  }
209
258
  });
210
- mountedRoots.forEach(function (root) {
211
- var helpers = helpersByRoot.get(root);
259
+ mountedRootsSnapshot.forEach(function (root) {
260
+ var helpers = helpersByRootSnapshot.get(root);
212
261
 
213
262
  if (helpers === undefined) {
214
263
  throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
215
264
  }
216
265
 
266
+ if (!mountedRoots.has(root)) {// No longer mounted.
267
+ }
268
+
217
269
  try {
218
270
  helpers.scheduleRefresh(root, update);
219
271
  } catch (err) {
@@ -230,6 +282,8 @@ function performReactRefresh() {
230
282
  }
231
283
 
232
284
  return update;
285
+ } finally {
286
+ isPerformingRefresh = false;
233
287
  }
234
288
  }
235
289
  function register(type, id) {
@@ -346,10 +400,12 @@ function injectIntoGlobalHook(globalObject) {
346
400
  // Otherwise, the renderer will think that there is no global hook, and won't do the injection.
347
401
  var nextID = 0;
348
402
  globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = {
403
+ renderers: new Map(),
349
404
  supportsFiber: true,
350
405
  inject: function (injected) {
351
406
  return nextID++;
352
407
  },
408
+ onScheduleFiberRoot: function (id, root, children) {},
353
409
  onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {},
354
410
  onCommitFiberUnmount: function () {}
355
411
  };
@@ -367,11 +423,36 @@ function injectIntoGlobalHook(globalObject) {
367
423
  }
368
424
 
369
425
  return id;
370
- }; // We also want to track currently mounted roots.
426
+ }; // Do the same for any already injected roots.
427
+ // This is useful if ReactDOM has already been initialized.
428
+ // https://github.com/facebook/react/issues/17626
429
+
371
430
 
431
+ hook.renderers.forEach(function (injected, id) {
432
+ if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') {
433
+ // This version supports React Refresh.
434
+ helpersByRendererID.set(id, injected);
435
+ }
436
+ }); // We also want to track currently mounted roots.
372
437
 
373
438
  var oldOnCommitFiberRoot = hook.onCommitFiberRoot;
374
439
 
440
+ var oldOnScheduleFiberRoot = hook.onScheduleFiberRoot || function () {};
441
+
442
+ hook.onScheduleFiberRoot = function (id, root, children) {
443
+ if (!isPerformingRefresh) {
444
+ // If it was intentionally scheduled, don't attempt to restore.
445
+ // This includes intentionally scheduled unmounts.
446
+ failedRoots.delete(root);
447
+
448
+ if (rootElements !== null) {
449
+ rootElements.set(root, children);
450
+ }
451
+ }
452
+
453
+ return oldOnScheduleFiberRoot.apply(this, arguments);
454
+ };
455
+
375
456
  hook.onCommitFiberRoot = function (id, root, maybePriorityLevel, didError) {
376
457
  var helpers = helpersByRendererID.get(id);
377
458
 
@@ -401,23 +482,14 @@ function injectIntoGlobalHook(globalObject) {
401
482
 
402
483
  if (didError) {
403
484
  // We'll remount it on future edits.
404
- // Remember what was rendered so we can restore it.
405
- failedRoots.set(root, alternate.memoizedState.element);
485
+ failedRoots.add(root);
406
486
  } else {
407
487
  helpersByRoot.delete(root);
408
488
  }
409
489
  } else if (!wasMounted && !isMounted) {
410
- if (didError && !failedRoots.has(root)) {
411
- // The root had an error during the initial mount.
412
- // We can't read its last element from the memoized state
413
- // because there was no previously committed alternate.
414
- // Ideally, it would be nice if we had a way to extract
415
- // the last attempted rendered element, but accessing the update queue
416
- // would tie this package too closely to the reconciler version.
417
- // So instead, we just set a flag.
418
- // TODO: Maybe we could fix this as the same time as when we fix
419
- // DevTools to not depend on `alternate.memoizedState.element`.
420
- didSomeRootFailOnMount = true;
490
+ if (didError) {
491
+ // We'll remount it on future edits.
492
+ failedRoots.add(root);
421
493
  }
422
494
  }
423
495
  } else {
@@ -430,7 +502,8 @@ function injectIntoGlobalHook(globalObject) {
430
502
  }
431
503
  }
432
504
  function hasUnrecoverableErrors() {
433
- return didSomeRootFailOnMount;
505
+ // TODO: delete this after removing dependency in RN.
506
+ return false;
434
507
  } // Exposed for testing.
435
508
 
436
509
  function _getMountedRootCount() {
@@ -462,22 +535,37 @@ function _getMountedRootCount() {
462
535
 
463
536
  function createSignatureFunctionForTransform() {
464
537
  {
465
- var call = 0;
538
+ // We'll fill in the signature in two steps.
539
+ // First, we'll know the signature itself. This happens outside the component.
540
+ // Then, we'll know the references to custom Hooks. This happens inside the component.
541
+ // After that, the returned function will be a fast path no-op.
542
+ var status = 'needsSignature';
466
543
  var savedType;
467
544
  var hasCustomHooks;
468
545
  return function (type, key, forceReset, getCustomHooks) {
469
- switch (call++) {
470
- case 0:
471
- savedType = type;
472
- hasCustomHooks = typeof getCustomHooks === 'function';
473
- setSignature(type, key, forceReset, getCustomHooks);
546
+ switch (status) {
547
+ case 'needsSignature':
548
+ if (type !== undefined) {
549
+ // If we received an argument, this is the initial registration call.
550
+ savedType = type;
551
+ hasCustomHooks = typeof getCustomHooks === 'function';
552
+ setSignature(type, key, forceReset, getCustomHooks); // The next call we expect is from inside a function, to fill in the custom Hooks.
553
+
554
+ status = 'needsCustomHooks';
555
+ }
556
+
474
557
  break;
475
558
 
476
- case 1:
559
+ case 'needsCustomHooks':
477
560
  if (hasCustomHooks) {
478
561
  collectCustomHooksForSignature(savedType);
479
562
  }
480
563
 
564
+ status = 'resolved';
565
+ break;
566
+
567
+ case 'resolved':
568
+ // Do nothing. Fast path for all future renders.
481
569
  break;
482
570
  }
483
571
 
@@ -1,4 +1,4 @@
1
- /** @license React v0.5.2
1
+ /** @license React vundefined
2
2
  * react-refresh-runtime.production.min.js
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "react"
6
6
  ],
7
- "version": "0.5.2",
7
+ "version": "0.7.2",
8
8
  "homepage": "https://reactjs.org/",
9
9
  "bugs": "https://github.com/facebook/react/issues",
10
10
  "license": "MIT",
package/build-info.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "branch": "pull/17007",
3
- "buildNumber": "50178",
4
- "checksum": "39106c3",
5
- "commit": "4ab6305f6",
6
- "environment": "ci",
7
- "reactVersion": "16.10.1-canary-4ab6305f6"
8
- }