react-refresh 0.16.0-rc.0 → 0.16.0-rc.1
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.
|
@@ -8,647 +8,331 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
|
18
|
-
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
|
19
|
-
|
|
20
|
-
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // We never remove these associations.
|
|
21
|
-
// It's OK to reference families, but use WeakMap/Set for types.
|
|
22
|
-
|
|
23
|
-
var allFamiliesByID = new Map();
|
|
24
|
-
var allFamiliesByType = new PossiblyWeakMap();
|
|
25
|
-
var allSignaturesByType = new PossiblyWeakMap(); // This WeakMap is read by React, so we only put families
|
|
26
|
-
// that have actually been edited here. This keeps checks fast.
|
|
27
|
-
|
|
28
|
-
var updatedFamiliesByType = new PossiblyWeakMap(); // This is cleared on every performReactRefresh() call.
|
|
29
|
-
// It is an array of [Family, NextType] tuples.
|
|
30
|
-
|
|
31
|
-
var pendingUpdates = []; // This is injected by the renderer via DevTools global hook.
|
|
32
|
-
|
|
33
|
-
var helpersByRendererID = new Map();
|
|
34
|
-
var helpersByRoot = new Map(); // We keep track of mounted roots so we can schedule updates.
|
|
35
|
-
|
|
36
|
-
var mountedRoots = new Set(); // If a root captures an error, we remember it so we can retry on edit.
|
|
37
|
-
|
|
38
|
-
var failedRoots = new Set(); // In environments that support WeakMap, we also remember the last element for every root.
|
|
39
|
-
// It needs to be weak because we do this even for roots that failed to mount.
|
|
40
|
-
// If there is no WeakMap, we won't attempt to do retrying.
|
|
41
|
-
|
|
42
|
-
var rootElements = typeof WeakMap === 'function' ? new WeakMap() : null;
|
|
43
|
-
var isPerformingRefresh = false;
|
|
44
|
-
|
|
45
|
-
function computeFullKey(signature) {
|
|
46
|
-
if (signature.fullKey !== null) {
|
|
47
|
-
return signature.fullKey;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var fullKey = signature.ownKey;
|
|
51
|
-
var hooks;
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
hooks = signature.getCustomHooks();
|
|
55
|
-
} catch (err) {
|
|
56
|
-
// This can happen in an edge case, e.g. if expression like Foo.useSomething
|
|
57
|
-
// depends on Foo which is lazily initialized during rendering.
|
|
58
|
-
// In that case just assume we'll have to remount.
|
|
59
|
-
signature.forceReset = true;
|
|
60
|
-
signature.fullKey = fullKey;
|
|
61
|
-
return fullKey;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (var i = 0; i < hooks.length; i++) {
|
|
65
|
-
var hook = hooks[i];
|
|
66
|
-
|
|
67
|
-
if (typeof hook !== 'function') {
|
|
68
|
-
// Something's wrong. Assume we need to remount.
|
|
69
|
-
signature.forceReset = true;
|
|
70
|
-
signature.fullKey = fullKey;
|
|
71
|
-
return fullKey;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
var nestedHookSignature = allSignaturesByType.get(hook);
|
|
75
|
-
|
|
76
|
-
if (nestedHookSignature === undefined) {
|
|
77
|
-
// No signature means Hook wasn't in the source code, e.g. in a library.
|
|
78
|
-
// We'll skip it because we can assume it won't change during this session.
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
var nestedHookKey = computeFullKey(nestedHookSignature);
|
|
83
|
-
|
|
84
|
-
if (nestedHookSignature.forceReset) {
|
|
85
|
-
signature.forceReset = true;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
fullKey += '\n---\n' + nestedHookKey;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
signature.fullKey = fullKey;
|
|
92
|
-
return fullKey;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function haveEqualSignatures(prevType, nextType) {
|
|
96
|
-
var prevSignature = allSignaturesByType.get(prevType);
|
|
97
|
-
var nextSignature = allSignaturesByType.get(nextType);
|
|
98
|
-
|
|
99
|
-
if (prevSignature === undefined && nextSignature === undefined) {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (prevSignature === undefined || nextSignature === undefined) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (computeFullKey(prevSignature) !== computeFullKey(nextSignature)) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (nextSignature.forceReset) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function isReactClass(type) {
|
|
119
|
-
return type.prototype && type.prototype.isReactComponent;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function canPreserveStateBetween(prevType, nextType) {
|
|
123
|
-
if (isReactClass(prevType) || isReactClass(nextType)) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (haveEqualSignatures(prevType, nextType)) {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function resolveFamily(type) {
|
|
135
|
-
// Only check updated types to keep lookups fast.
|
|
136
|
-
return updatedFamiliesByType.get(type);
|
|
137
|
-
} // If we didn't care about IE11, we could use new Map/Set(iterable).
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function cloneMap(map) {
|
|
141
|
-
var clone = new Map();
|
|
142
|
-
map.forEach(function (value, key) {
|
|
143
|
-
clone.set(key, value);
|
|
144
|
-
});
|
|
145
|
-
return clone;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function cloneSet(set) {
|
|
149
|
-
var clone = new Set();
|
|
150
|
-
set.forEach(function (value) {
|
|
151
|
-
clone.add(value);
|
|
152
|
-
});
|
|
153
|
-
return clone;
|
|
154
|
-
} // This is a safety mechanism to protect against rogue getters and Proxies.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
function getProperty(object, property) {
|
|
158
|
-
try {
|
|
159
|
-
return object[property];
|
|
160
|
-
} catch (err) {
|
|
161
|
-
// Intentionally ignore.
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function performReactRefresh() {
|
|
167
|
-
|
|
168
|
-
if (pendingUpdates.length === 0) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (isPerformingRefresh) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
isPerformingRefresh = true;
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
var staleFamilies = new Set();
|
|
180
|
-
var updatedFamilies = new Set();
|
|
181
|
-
var updates = pendingUpdates;
|
|
182
|
-
pendingUpdates = [];
|
|
183
|
-
updates.forEach(function (_ref) {
|
|
184
|
-
var family = _ref[0],
|
|
185
|
-
nextType = _ref[1];
|
|
186
|
-
// Now that we got a real edit, we can create associations
|
|
187
|
-
// that will be read by the React reconciler.
|
|
188
|
-
var prevType = family.current;
|
|
189
|
-
updatedFamiliesByType.set(prevType, family);
|
|
190
|
-
updatedFamiliesByType.set(nextType, family);
|
|
191
|
-
family.current = nextType; // Determine whether this should be a re-render or a re-mount.
|
|
192
|
-
|
|
193
|
-
if (canPreserveStateBetween(prevType, nextType)) {
|
|
194
|
-
updatedFamilies.add(family);
|
|
195
|
-
} else {
|
|
196
|
-
staleFamilies.add(family);
|
|
197
|
-
}
|
|
198
|
-
}); // TODO: rename these fields to something more meaningful.
|
|
199
|
-
|
|
200
|
-
var update = {
|
|
201
|
-
updatedFamilies: updatedFamilies,
|
|
202
|
-
// Families that will re-render preserving state
|
|
203
|
-
staleFamilies: staleFamilies // Families that will be remounted
|
|
204
|
-
|
|
205
|
-
};
|
|
206
|
-
helpersByRendererID.forEach(function (helpers) {
|
|
207
|
-
// Even if there are no roots, set the handler on first update.
|
|
208
|
-
// This ensures that if *new* roots are mounted, they'll use the resolve handler.
|
|
209
|
-
helpers.setRefreshHandler(resolveFamily);
|
|
210
|
-
});
|
|
211
|
-
var didError = false;
|
|
212
|
-
var firstError = null; // We snapshot maps and sets that are mutated during commits.
|
|
213
|
-
// If we don't do this, there is a risk they will be mutated while
|
|
214
|
-
// we iterate over them. For example, trying to recover a failed root
|
|
215
|
-
// may cause another root to be added to the failed list -- an infinite loop.
|
|
216
|
-
|
|
217
|
-
var failedRootsSnapshot = cloneSet(failedRoots);
|
|
218
|
-
var mountedRootsSnapshot = cloneSet(mountedRoots);
|
|
219
|
-
var helpersByRootSnapshot = cloneMap(helpersByRoot);
|
|
220
|
-
failedRootsSnapshot.forEach(function (root) {
|
|
221
|
-
var helpers = helpersByRootSnapshot.get(root);
|
|
222
|
-
|
|
223
|
-
if (helpers === undefined) {
|
|
224
|
-
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!failedRoots.has(root)) {// No longer failed.
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (rootElements === null) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (!rootElements.has(root)) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
var element = rootElements.get(root);
|
|
239
|
-
|
|
11
|
+
"use strict";
|
|
12
|
+
"production" !== process.env.NODE_ENV &&
|
|
13
|
+
(function () {
|
|
14
|
+
function computeFullKey(signature) {
|
|
15
|
+
if (null !== signature.fullKey) return signature.fullKey;
|
|
16
|
+
var fullKey = signature.ownKey;
|
|
240
17
|
try {
|
|
241
|
-
|
|
18
|
+
var hooks = signature.getCustomHooks();
|
|
242
19
|
} catch (err) {
|
|
243
|
-
|
|
244
|
-
didError = true;
|
|
245
|
-
firstError = err;
|
|
246
|
-
} // Keep trying other roots.
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
mountedRootsSnapshot.forEach(function (root) {
|
|
251
|
-
var helpers = helpersByRootSnapshot.get(root);
|
|
252
|
-
|
|
253
|
-
if (helpers === undefined) {
|
|
254
|
-
throw new Error('Could not find helpers for a root. This is a bug in React Refresh.');
|
|
20
|
+
return (signature.forceReset = !0), (signature.fullKey = fullKey);
|
|
255
21
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
} // Keep trying other roots.
|
|
267
|
-
|
|
22
|
+
for (var i = 0; i < hooks.length; i++) {
|
|
23
|
+
var hook = hooks[i];
|
|
24
|
+
if ("function" !== typeof hook)
|
|
25
|
+
return (signature.forceReset = !0), (signature.fullKey = fullKey);
|
|
26
|
+
hook = allSignaturesByType.get(hook);
|
|
27
|
+
if (void 0 !== hook) {
|
|
28
|
+
var nestedHookKey = computeFullKey(hook);
|
|
29
|
+
hook.forceReset && (signature.forceReset = !0);
|
|
30
|
+
fullKey += "\n---\n" + nestedHookKey;
|
|
31
|
+
}
|
|
268
32
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (didError) {
|
|
272
|
-
throw firstError;
|
|
33
|
+
return (signature.fullKey = fullKey);
|
|
273
34
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
} finally {
|
|
277
|
-
isPerformingRefresh = false;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function register(type, id) {
|
|
281
|
-
{
|
|
282
|
-
if (type === null) {
|
|
283
|
-
return;
|
|
35
|
+
function resolveFamily(type) {
|
|
36
|
+
return updatedFamiliesByType.get(type);
|
|
284
37
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (allFamiliesByType.has(type)) {
|
|
294
|
-
return;
|
|
295
|
-
} // Create family or remember to update it.
|
|
296
|
-
// None of this bookkeeping affects reconciliation
|
|
297
|
-
// until the first performReactRefresh() call above.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
var family = allFamiliesByID.get(id);
|
|
301
|
-
|
|
302
|
-
if (family === undefined) {
|
|
303
|
-
family = {
|
|
304
|
-
current: type
|
|
305
|
-
};
|
|
306
|
-
allFamiliesByID.set(id, family);
|
|
307
|
-
} else {
|
|
308
|
-
pendingUpdates.push([family, type]);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
allFamiliesByType.set(type, family); // Visit inner types because we might not have registered them.
|
|
312
|
-
|
|
313
|
-
if (typeof type === 'object' && type !== null) {
|
|
314
|
-
switch (getProperty(type, '$$typeof')) {
|
|
315
|
-
case REACT_FORWARD_REF_TYPE:
|
|
316
|
-
register(type.render, id + '$render');
|
|
317
|
-
break;
|
|
318
|
-
|
|
319
|
-
case REACT_MEMO_TYPE:
|
|
320
|
-
register(type.type, id + '$type');
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
38
|
+
function cloneMap(map) {
|
|
39
|
+
var clone = new Map();
|
|
40
|
+
map.forEach(function (value, key) {
|
|
41
|
+
clone.set(key, value);
|
|
42
|
+
});
|
|
43
|
+
return clone;
|
|
323
44
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
function
|
|
327
|
-
|
|
328
|
-
var getCustomHooks = arguments.length > 3 ? arguments[3] : undefined;
|
|
329
|
-
|
|
330
|
-
{
|
|
331
|
-
if (!allSignaturesByType.has(type)) {
|
|
332
|
-
allSignaturesByType.set(type, {
|
|
333
|
-
forceReset: forceReset,
|
|
334
|
-
ownKey: key,
|
|
335
|
-
fullKey: null,
|
|
336
|
-
getCustomHooks: getCustomHooks || function () {
|
|
337
|
-
return [];
|
|
338
|
-
}
|
|
45
|
+
function cloneSet(set) {
|
|
46
|
+
var clone = new Set();
|
|
47
|
+
set.forEach(function (value) {
|
|
48
|
+
clone.add(value);
|
|
339
49
|
});
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (typeof type === 'object' && type !== null) {
|
|
344
|
-
switch (getProperty(type, '$$typeof')) {
|
|
345
|
-
case REACT_FORWARD_REF_TYPE:
|
|
346
|
-
setSignature(type.render, key, forceReset, getCustomHooks);
|
|
347
|
-
break;
|
|
348
|
-
|
|
349
|
-
case REACT_MEMO_TYPE:
|
|
350
|
-
setSignature(type.type, key, forceReset, getCustomHooks);
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
50
|
+
return clone;
|
|
353
51
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
function collectCustomHooksForSignature(type) {
|
|
359
|
-
{
|
|
360
|
-
var signature = allSignaturesByType.get(type);
|
|
361
|
-
|
|
362
|
-
if (signature !== undefined) {
|
|
363
|
-
computeFullKey(signature);
|
|
52
|
+
function getProperty(object, property) {
|
|
53
|
+
try {
|
|
54
|
+
return object[property];
|
|
55
|
+
} catch (err) {}
|
|
364
56
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
57
|
+
function register(type, id) {
|
|
58
|
+
if (
|
|
59
|
+
!(
|
|
60
|
+
null === type ||
|
|
61
|
+
("function" !== typeof type && "object" !== typeof type) ||
|
|
62
|
+
allFamiliesByType.has(type)
|
|
63
|
+
)
|
|
64
|
+
) {
|
|
65
|
+
var family = allFamiliesByID.get(id);
|
|
66
|
+
void 0 === family
|
|
67
|
+
? ((family = { current: type }), allFamiliesByID.set(id, family))
|
|
68
|
+
: pendingUpdates.push([family, type]);
|
|
69
|
+
allFamiliesByType.set(type, family);
|
|
70
|
+
if ("object" === typeof type && null !== type)
|
|
71
|
+
switch (getProperty(type, "$$typeof")) {
|
|
72
|
+
case REACT_FORWARD_REF_TYPE:
|
|
73
|
+
register(type.render, id + "$render");
|
|
74
|
+
break;
|
|
75
|
+
case REACT_MEMO_TYPE:
|
|
76
|
+
register(type.type, id + "$type");
|
|
77
|
+
}
|
|
385
78
|
}
|
|
386
|
-
|
|
387
|
-
var instancesForRoot = helpers.findHostInstancesForRefresh(root, families);
|
|
388
|
-
instancesForRoot.forEach(function (inst) {
|
|
389
|
-
affectedInstances.add(inst);
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
return affectedInstances;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function injectIntoGlobalHook(globalObject) {
|
|
396
|
-
{
|
|
397
|
-
// For React Native, the global hook will be set up by require('react-devtools-core').
|
|
398
|
-
// That code will run before us. So we need to monkeypatch functions on existing hook.
|
|
399
|
-
// For React Web, the global hook will be set up by the extension.
|
|
400
|
-
// This will also run before us.
|
|
401
|
-
var hook = globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
402
|
-
|
|
403
|
-
if (hook === undefined) {
|
|
404
|
-
// However, if there is no DevTools extension, we'll need to set up the global hook ourselves.
|
|
405
|
-
// Note that in this case it's important that renderer code runs *after* this method call.
|
|
406
|
-
// Otherwise, the renderer will think that there is no global hook, and won't do the injection.
|
|
407
|
-
var nextID = 0;
|
|
408
|
-
globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = {
|
|
409
|
-
renderers: new Map(),
|
|
410
|
-
supportsFiber: true,
|
|
411
|
-
inject: function (injected) {
|
|
412
|
-
return nextID++;
|
|
413
|
-
},
|
|
414
|
-
onScheduleFiberRoot: function (id, root, children) {},
|
|
415
|
-
onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {},
|
|
416
|
-
onCommitFiberUnmount: function () {}
|
|
417
|
-
};
|
|
418
79
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
var id = oldInject.apply(this, arguments);
|
|
433
|
-
|
|
434
|
-
if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') {
|
|
435
|
-
// This version supports React Refresh.
|
|
436
|
-
helpersByRendererID.set(id, injected);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
return id;
|
|
440
|
-
}; // Do the same for any already injected roots.
|
|
441
|
-
// This is useful if ReactDOM has already been initialized.
|
|
442
|
-
// https://github.com/facebook/react/issues/17626
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
hook.renderers.forEach(function (injected, id) {
|
|
446
|
-
if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') {
|
|
447
|
-
// This version supports React Refresh.
|
|
448
|
-
helpersByRendererID.set(id, injected);
|
|
449
|
-
}
|
|
450
|
-
}); // We also want to track currently mounted roots.
|
|
451
|
-
|
|
452
|
-
var oldOnCommitFiberRoot = hook.onCommitFiberRoot;
|
|
453
|
-
|
|
454
|
-
var oldOnScheduleFiberRoot = hook.onScheduleFiberRoot || function () {};
|
|
455
|
-
|
|
456
|
-
hook.onScheduleFiberRoot = function (id, root, children) {
|
|
457
|
-
if (!isPerformingRefresh) {
|
|
458
|
-
// If it was intentionally scheduled, don't attempt to restore.
|
|
459
|
-
// This includes intentionally scheduled unmounts.
|
|
460
|
-
failedRoots.delete(root);
|
|
461
|
-
|
|
462
|
-
if (rootElements !== null) {
|
|
463
|
-
rootElements.set(root, children);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return oldOnScheduleFiberRoot.apply(this, arguments);
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
hook.onCommitFiberRoot = function (id, root, maybePriorityLevel, didError) {
|
|
471
|
-
var helpers = helpersByRendererID.get(id);
|
|
472
|
-
|
|
473
|
-
if (helpers !== undefined) {
|
|
474
|
-
helpersByRoot.set(root, helpers);
|
|
475
|
-
var current = root.current;
|
|
476
|
-
var alternate = current.alternate; // We need to determine whether this root has just (un)mounted.
|
|
477
|
-
// This logic is copy-pasted from similar logic in the DevTools backend.
|
|
478
|
-
// If this breaks with some refactoring, you'll want to update DevTools too.
|
|
479
|
-
|
|
480
|
-
if (alternate !== null) {
|
|
481
|
-
var wasMounted = alternate.memoizedState != null && alternate.memoizedState.element != null && mountedRoots.has(root);
|
|
482
|
-
var isMounted = current.memoizedState != null && current.memoizedState.element != null;
|
|
483
|
-
|
|
484
|
-
if (!wasMounted && isMounted) {
|
|
485
|
-
// Mount a new root.
|
|
486
|
-
mountedRoots.add(root);
|
|
487
|
-
failedRoots.delete(root);
|
|
488
|
-
} else if (wasMounted && isMounted) ; else if (wasMounted && !isMounted) {
|
|
489
|
-
// Unmount an existing root.
|
|
490
|
-
mountedRoots.delete(root);
|
|
491
|
-
|
|
492
|
-
if (didError) {
|
|
493
|
-
// We'll remount it on future edits.
|
|
494
|
-
failedRoots.add(root);
|
|
495
|
-
} else {
|
|
496
|
-
helpersByRoot.delete(root);
|
|
497
|
-
}
|
|
498
|
-
} else if (!wasMounted && !isMounted) {
|
|
499
|
-
if (didError) {
|
|
500
|
-
// We'll remount it on future edits.
|
|
501
|
-
failedRoots.add(root);
|
|
80
|
+
function setSignature(type, key) {
|
|
81
|
+
var forceReset =
|
|
82
|
+
2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : !1,
|
|
83
|
+
getCustomHooks = 3 < arguments.length ? arguments[3] : void 0;
|
|
84
|
+
allSignaturesByType.has(type) ||
|
|
85
|
+
allSignaturesByType.set(type, {
|
|
86
|
+
forceReset: forceReset,
|
|
87
|
+
ownKey: key,
|
|
88
|
+
fullKey: null,
|
|
89
|
+
getCustomHooks:
|
|
90
|
+
getCustomHooks ||
|
|
91
|
+
function () {
|
|
92
|
+
return [];
|
|
502
93
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
94
|
+
});
|
|
95
|
+
if ("object" === typeof type && null !== type)
|
|
96
|
+
switch (getProperty(type, "$$typeof")) {
|
|
97
|
+
case REACT_FORWARD_REF_TYPE:
|
|
98
|
+
setSignature(type.render, key, forceReset, getCustomHooks);
|
|
99
|
+
break;
|
|
100
|
+
case REACT_MEMO_TYPE:
|
|
101
|
+
setSignature(type.type, key, forceReset, getCustomHooks);
|
|
507
102
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
103
|
+
}
|
|
104
|
+
function collectCustomHooksForSignature(type) {
|
|
105
|
+
type = allSignaturesByType.get(type);
|
|
106
|
+
void 0 !== type && computeFullKey(type);
|
|
107
|
+
}
|
|
108
|
+
var REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
|
|
109
|
+
REACT_MEMO_TYPE = Symbol.for("react.memo"),
|
|
110
|
+
PossiblyWeakMap = "function" === typeof WeakMap ? WeakMap : Map,
|
|
111
|
+
allFamiliesByID = new Map(),
|
|
112
|
+
allFamiliesByType = new PossiblyWeakMap(),
|
|
113
|
+
allSignaturesByType = new PossiblyWeakMap(),
|
|
114
|
+
updatedFamiliesByType = new PossiblyWeakMap(),
|
|
115
|
+
pendingUpdates = [],
|
|
116
|
+
helpersByRendererID = new Map(),
|
|
117
|
+
helpersByRoot = new Map(),
|
|
118
|
+
mountedRoots = new Set(),
|
|
119
|
+
failedRoots = new Set(),
|
|
120
|
+
rootElements = "function" === typeof WeakMap ? new WeakMap() : null,
|
|
121
|
+
isPerformingRefresh = !1;
|
|
122
|
+
exports._getMountedRootCount = function () {
|
|
123
|
+
return mountedRoots.size;
|
|
512
124
|
};
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
125
|
+
exports.collectCustomHooksForSignature = collectCustomHooksForSignature;
|
|
126
|
+
exports.createSignatureFunctionForTransform = function () {
|
|
127
|
+
var savedType,
|
|
128
|
+
hasCustomHooks,
|
|
129
|
+
didCollectHooks = !1;
|
|
130
|
+
return function (type, key, forceReset, getCustomHooks) {
|
|
131
|
+
if ("string" === typeof key)
|
|
132
|
+
return (
|
|
133
|
+
savedType ||
|
|
134
|
+
((savedType = type),
|
|
135
|
+
(hasCustomHooks = "function" === typeof getCustomHooks)),
|
|
136
|
+
null == type ||
|
|
137
|
+
("function" !== typeof type && "object" !== typeof type) ||
|
|
138
|
+
setSignature(type, key, forceReset, getCustomHooks),
|
|
139
|
+
type
|
|
140
|
+
);
|
|
141
|
+
!didCollectHooks &&
|
|
142
|
+
hasCustomHooks &&
|
|
143
|
+
((didCollectHooks = !0), collectCustomHooksForSignature(savedType));
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
exports.getFamilyByID = function (id) {
|
|
147
|
+
return allFamiliesByID.get(id);
|
|
148
|
+
};
|
|
149
|
+
exports.getFamilyByType = function (type) {
|
|
150
|
+
return allFamiliesByType.get(type);
|
|
151
|
+
};
|
|
152
|
+
exports.hasUnrecoverableErrors = function () {
|
|
153
|
+
return !1;
|
|
154
|
+
};
|
|
155
|
+
exports.injectIntoGlobalHook = function (globalObject) {
|
|
156
|
+
var hook = globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
157
|
+
if (void 0 === hook) {
|
|
158
|
+
var nextID = 0;
|
|
159
|
+
globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = {
|
|
160
|
+
renderers: new Map(),
|
|
161
|
+
supportsFiber: !0,
|
|
162
|
+
inject: function () {
|
|
163
|
+
return nextID++;
|
|
164
|
+
},
|
|
165
|
+
onScheduleFiberRoot: function () {},
|
|
166
|
+
onCommitFiberRoot: function () {},
|
|
167
|
+
onCommitFiberUnmount: function () {}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (hook.isDisabled)
|
|
171
|
+
console.warn(
|
|
172
|
+
"Something has shimmed the React DevTools global hook (__REACT_DEVTOOLS_GLOBAL_HOOK__). Fast Refresh is not compatible with this shim and will be disabled."
|
|
173
|
+
);
|
|
174
|
+
else {
|
|
175
|
+
var oldInject = hook.inject;
|
|
176
|
+
hook.inject = function (injected) {
|
|
177
|
+
var id = oldInject.apply(this, arguments);
|
|
178
|
+
"function" === typeof injected.scheduleRefresh &&
|
|
179
|
+
"function" === typeof injected.setRefreshHandler &&
|
|
180
|
+
helpersByRendererID.set(id, injected);
|
|
181
|
+
return id;
|
|
182
|
+
};
|
|
183
|
+
hook.renderers.forEach(function (injected, id) {
|
|
184
|
+
"function" === typeof injected.scheduleRefresh &&
|
|
185
|
+
"function" === typeof injected.setRefreshHandler &&
|
|
186
|
+
helpersByRendererID.set(id, injected);
|
|
187
|
+
});
|
|
188
|
+
var oldOnCommitFiberRoot = hook.onCommitFiberRoot,
|
|
189
|
+
oldOnScheduleFiberRoot = hook.onScheduleFiberRoot || function () {};
|
|
190
|
+
hook.onScheduleFiberRoot = function (id, root, children) {
|
|
191
|
+
isPerformingRefresh ||
|
|
192
|
+
(failedRoots.delete(root),
|
|
193
|
+
null !== rootElements && rootElements.set(root, children));
|
|
194
|
+
return oldOnScheduleFiberRoot.apply(this, arguments);
|
|
195
|
+
};
|
|
196
|
+
hook.onCommitFiberRoot = function (
|
|
197
|
+
id,
|
|
198
|
+
root,
|
|
199
|
+
maybePriorityLevel,
|
|
200
|
+
didError
|
|
201
|
+
) {
|
|
202
|
+
var helpers = helpersByRendererID.get(id);
|
|
203
|
+
if (void 0 !== helpers) {
|
|
204
|
+
helpersByRoot.set(root, helpers);
|
|
205
|
+
helpers = root.current;
|
|
206
|
+
var alternate = helpers.alternate;
|
|
207
|
+
null !== alternate
|
|
208
|
+
? ((alternate =
|
|
209
|
+
null != alternate.memoizedState &&
|
|
210
|
+
null != alternate.memoizedState.element &&
|
|
211
|
+
mountedRoots.has(root)),
|
|
212
|
+
(helpers =
|
|
213
|
+
null != helpers.memoizedState &&
|
|
214
|
+
null != helpers.memoizedState.element),
|
|
215
|
+
!alternate && helpers
|
|
216
|
+
? (mountedRoots.add(root), failedRoots.delete(root))
|
|
217
|
+
: (alternate && helpers) ||
|
|
218
|
+
(alternate && !helpers
|
|
219
|
+
? (mountedRoots.delete(root),
|
|
220
|
+
didError
|
|
221
|
+
? failedRoots.add(root)
|
|
222
|
+
: helpersByRoot.delete(root))
|
|
223
|
+
: alternate ||
|
|
224
|
+
helpers ||
|
|
225
|
+
(didError && failedRoots.add(root))))
|
|
226
|
+
: mountedRoots.add(root);
|
|
227
|
+
}
|
|
228
|
+
return oldOnCommitFiberRoot.apply(this, arguments);
|
|
229
|
+
};
|
|
579
230
|
}
|
|
580
231
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
function
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
case 'function':
|
|
587
|
-
{
|
|
588
|
-
// First, deal with classes.
|
|
589
|
-
if (type.prototype != null) {
|
|
590
|
-
if (type.prototype.isReactComponent) {
|
|
591
|
-
// React class.
|
|
592
|
-
return true;
|
|
593
|
-
}
|
|
594
|
-
|
|
232
|
+
exports.isLikelyComponentType = function (type) {
|
|
233
|
+
switch (typeof type) {
|
|
234
|
+
case "function":
|
|
235
|
+
if (null != type.prototype) {
|
|
236
|
+
if (type.prototype.isReactComponent) return !0;
|
|
595
237
|
var ownNames = Object.getOwnPropertyNames(type.prototype);
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
} // For plain functions and arrows, use name as a heuristic.
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
var name = type.name || type.displayName;
|
|
613
|
-
return typeof name === 'string' && /^[A-Z]/.test(name);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
case 'object':
|
|
617
|
-
{
|
|
618
|
-
if (type != null) {
|
|
619
|
-
switch (getProperty(type, '$$typeof')) {
|
|
238
|
+
if (
|
|
239
|
+
1 < ownNames.length ||
|
|
240
|
+
"constructor" !== ownNames[0] ||
|
|
241
|
+
type.prototype.__proto__ !== Object.prototype
|
|
242
|
+
)
|
|
243
|
+
return !1;
|
|
244
|
+
}
|
|
245
|
+
type = type.name || type.displayName;
|
|
246
|
+
return "string" === typeof type && /^[A-Z]/.test(type);
|
|
247
|
+
case "object":
|
|
248
|
+
if (null != type)
|
|
249
|
+
switch (getProperty(type, "$$typeof")) {
|
|
620
250
|
case REACT_FORWARD_REF_TYPE:
|
|
621
251
|
case REACT_MEMO_TYPE:
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
252
|
+
return !0;
|
|
253
|
+
}
|
|
254
|
+
return !1;
|
|
255
|
+
default:
|
|
256
|
+
return !1;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
exports.performReactRefresh = function () {
|
|
260
|
+
if (0 === pendingUpdates.length || isPerformingRefresh) return null;
|
|
261
|
+
isPerformingRefresh = !0;
|
|
262
|
+
try {
|
|
263
|
+
var staleFamilies = new Set(),
|
|
264
|
+
updatedFamilies = new Set(),
|
|
265
|
+
updates = pendingUpdates;
|
|
266
|
+
pendingUpdates = [];
|
|
267
|
+
updates.forEach(function (_ref) {
|
|
268
|
+
var family = _ref[0];
|
|
269
|
+
_ref = _ref[1];
|
|
270
|
+
var prevType = family.current;
|
|
271
|
+
updatedFamiliesByType.set(prevType, family);
|
|
272
|
+
updatedFamiliesByType.set(_ref, family);
|
|
273
|
+
family.current = _ref;
|
|
274
|
+
(prevType.prototype && prevType.prototype.isReactComponent) ||
|
|
275
|
+
(_ref.prototype && _ref.prototype.isReactComponent)
|
|
276
|
+
? (_ref = !1)
|
|
277
|
+
: ((prevType = allSignaturesByType.get(prevType)),
|
|
278
|
+
(_ref = allSignaturesByType.get(_ref)),
|
|
279
|
+
(_ref =
|
|
280
|
+
(void 0 === prevType && void 0 === _ref) ||
|
|
281
|
+
(void 0 !== prevType &&
|
|
282
|
+
void 0 !== _ref &&
|
|
283
|
+
computeFullKey(prevType) === computeFullKey(_ref) &&
|
|
284
|
+
!_ref.forceReset)
|
|
285
|
+
? !0
|
|
286
|
+
: !1));
|
|
287
|
+
_ref ? updatedFamilies.add(family) : staleFamilies.add(family);
|
|
288
|
+
});
|
|
289
|
+
var update = {
|
|
290
|
+
updatedFamilies: updatedFamilies,
|
|
291
|
+
staleFamilies: staleFamilies
|
|
292
|
+
};
|
|
293
|
+
helpersByRendererID.forEach(function (helpers) {
|
|
294
|
+
helpers.setRefreshHandler(resolveFamily);
|
|
295
|
+
});
|
|
296
|
+
var didError = !1,
|
|
297
|
+
firstError = null,
|
|
298
|
+
failedRootsSnapshot = cloneSet(failedRoots),
|
|
299
|
+
mountedRootsSnapshot = cloneSet(mountedRoots),
|
|
300
|
+
helpersByRootSnapshot = cloneMap(helpersByRoot);
|
|
301
|
+
failedRootsSnapshot.forEach(function (root) {
|
|
302
|
+
var helpers = helpersByRootSnapshot.get(root);
|
|
303
|
+
if (void 0 === helpers)
|
|
304
|
+
throw Error(
|
|
305
|
+
"Could not find helpers for a root. This is a bug in React Refresh."
|
|
306
|
+
);
|
|
307
|
+
failedRoots.has(root);
|
|
308
|
+
if (null !== rootElements && rootElements.has(root)) {
|
|
309
|
+
var element = rootElements.get(root);
|
|
310
|
+
try {
|
|
311
|
+
helpers.scheduleRoot(root, element);
|
|
312
|
+
} catch (err) {
|
|
313
|
+
didError || ((didError = !0), (firstError = err));
|
|
627
314
|
}
|
|
628
315
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
exports.
|
|
650
|
-
exports.
|
|
651
|
-
exports.register = register;
|
|
652
|
-
exports.setSignature = setSignature;
|
|
316
|
+
});
|
|
317
|
+
mountedRootsSnapshot.forEach(function (root) {
|
|
318
|
+
var helpers = helpersByRootSnapshot.get(root);
|
|
319
|
+
if (void 0 === helpers)
|
|
320
|
+
throw Error(
|
|
321
|
+
"Could not find helpers for a root. This is a bug in React Refresh."
|
|
322
|
+
);
|
|
323
|
+
mountedRoots.has(root);
|
|
324
|
+
try {
|
|
325
|
+
helpers.scheduleRefresh(root, update);
|
|
326
|
+
} catch (err) {
|
|
327
|
+
didError || ((didError = !0), (firstError = err));
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
if (didError) throw firstError;
|
|
331
|
+
return update;
|
|
332
|
+
} finally {
|
|
333
|
+
isPerformingRefresh = !1;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
exports.register = register;
|
|
337
|
+
exports.setSignature = setSignature;
|
|
653
338
|
})();
|
|
654
|
-
}
|