-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathreact-server-dom-webpack-server.browser.development.js
3249 lines (2683 loc) · 95.9 KB
/
react-server-dom-webpack-server.browser.development.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @license React
* react-server-dom-webpack-server.browser.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';
var React = require('react');
var ReactDOM = require('react-dom');
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function error(format) {
{
{
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
printWarning('error', format, args);
}
}
}
function printWarning(level, format, args) {
// When changing this logic, you might want to also
// update consoleWithStackDev.www.js as well.
{
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
var stack = ReactDebugCurrentFrame.getStackAddendum();
if (stack !== '') {
format += '%s';
args = args.concat([stack]);
} // eslint-disable-next-line react-internal/safe-string-coercion
var argsWithFormat = args.map(function (item) {
return String(item);
}); // Careful: RN currently depends on this prefix
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
// breaks IE9: https://github.com/facebook/react/issues/13610
// eslint-disable-next-line react-internal/no-production-logging
Function.prototype.apply.call(console[level], console, argsWithFormat);
}
}
function scheduleWork(callback) {
callback();
}
var VIEW_SIZE = 512;
var currentView = null;
var writtenBytes = 0;
function beginWriting(destination) {
currentView = new Uint8Array(VIEW_SIZE);
writtenBytes = 0;
}
function writeChunk(destination, chunk) {
if (chunk.byteLength === 0) {
return;
}
if (chunk.byteLength > VIEW_SIZE) {
{
if (precomputedChunkSet.has(chunk)) {
error('A large precomputed chunk was passed to writeChunk without being copied.' + ' Large chunks get enqueued directly and are not copied. This is incompatible with precomputed chunks because you cannot enqueue the same precomputed chunk twice.' + ' Use "cloneChunk" to make a copy of this large precomputed chunk before writing it. This is a bug in React.');
}
} // this chunk may overflow a single view which implies it was not
// one that is cached by the streaming renderer. We will enqueu
// it directly and expect it is not re-used
if (writtenBytes > 0) {
destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
currentView = new Uint8Array(VIEW_SIZE);
writtenBytes = 0;
}
destination.enqueue(chunk);
return;
}
var bytesToWrite = chunk;
var allowableBytes = currentView.length - writtenBytes;
if (allowableBytes < bytesToWrite.byteLength) {
// this chunk would overflow the current view. We enqueue a full view
// and start a new view with the remaining chunk
if (allowableBytes === 0) {
// the current view is already full, send it
destination.enqueue(currentView);
} else {
// fill up the current view and apply the remaining chunk bytes
// to a new view.
currentView.set(bytesToWrite.subarray(0, allowableBytes), writtenBytes); // writtenBytes += allowableBytes; // this can be skipped because we are going to immediately reset the view
destination.enqueue(currentView);
bytesToWrite = bytesToWrite.subarray(allowableBytes);
}
currentView = new Uint8Array(VIEW_SIZE);
writtenBytes = 0;
}
currentView.set(bytesToWrite, writtenBytes);
writtenBytes += bytesToWrite.byteLength;
}
function writeChunkAndReturn(destination, chunk) {
writeChunk(destination, chunk); // in web streams there is no backpressure so we can alwas write more
return true;
}
function completeWriting(destination) {
if (currentView && writtenBytes > 0) {
destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
currentView = null;
writtenBytes = 0;
}
}
function close$1(destination) {
destination.close();
}
var textEncoder = new TextEncoder();
function stringToChunk(content) {
return textEncoder.encode(content);
}
var precomputedChunkSet = new Set() ;
function byteLengthOfChunk(chunk) {
return chunk.byteLength;
}
function closeWithError(destination, error) {
// $FlowFixMe[method-unbinding]
if (typeof destination.error === 'function') {
// $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
destination.error(error);
} else {
// Earlier implementations doesn't support this method. In that environment you're
// supposed to throw from a promise returned but we don't return a promise in our
// approach. We could fork this implementation but this is environment is an edge
// case to begin with. It's even less common to run this in an older environment.
// Even then, this is not where errors are supposed to happen and they get reported
// to a global callback in addition to this anyway. So it's fine just to close this.
destination.close();
}
}
// eslint-disable-next-line no-unused-vars
var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
function isClientReference(reference) {
return reference.$$typeof === CLIENT_REFERENCE_TAG;
}
function isServerReference(reference) {
return reference.$$typeof === SERVER_REFERENCE_TAG;
}
function registerClientReference(proxyImplementation, id, exportName) {
return registerClientReferenceImpl(proxyImplementation, id + '#' + exportName, false);
}
function registerClientReferenceImpl(proxyImplementation, id, async) {
return Object.defineProperties(proxyImplementation, {
$$typeof: {
value: CLIENT_REFERENCE_TAG
},
$$id: {
value: id
},
$$async: {
value: async
}
});
} // $FlowFixMe[method-unbinding]
var FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
var ArraySlice = Array.prototype.slice;
function bind() {
// $FlowFixMe[unsupported-syntax]
var newFn = FunctionBind.apply(this, arguments);
if (this.$$typeof === SERVER_REFERENCE_TAG) {
var args = ArraySlice.call(arguments, 1);
newFn.$$typeof = SERVER_REFERENCE_TAG;
newFn.$$id = this.$$id;
newFn.$$bound = this.$$bound ? this.$$bound.concat(args) : args;
}
return newFn;
}
function registerServerReference(reference, id, exportName) {
return Object.defineProperties(reference, {
$$typeof: {
value: SERVER_REFERENCE_TAG
},
$$id: {
value: exportName === null ? id : id + '#' + exportName
},
$$bound: {
value: null
},
bind: {
value: bind
}
});
}
var PROMISE_PROTOTYPE = Promise.prototype;
var deepProxyHandlers = {
get: function (target, name, receiver) {
switch (name) {
// These names are read by the Flight runtime if you end up using the exports object.
case '$$typeof':
// These names are a little too common. We should probably have a way to
// have the Flight runtime extract the inner target instead.
return target.$$typeof;
case '$$id':
return target.$$id;
case '$$async':
return target.$$async;
case 'name':
return target.name;
case 'displayName':
return undefined;
// We need to special case this because createElement reads it if we pass this
// reference.
case 'defaultProps':
return undefined;
// Avoid this attempting to be serialized.
case 'toJSON':
return undefined;
case Symbol.toPrimitive:
// $FlowFixMe[prop-missing]
return Object.prototype[Symbol.toPrimitive];
case 'Provider':
throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
} // eslint-disable-next-line react-internal/safe-string-coercion
var expression = String(target.name) + '.' + String(name);
throw new Error("Cannot access " + expression + " on the server. " + 'You cannot dot into a client module from a server component. ' + 'You can only pass the imported name through.');
},
set: function () {
throw new Error('Cannot assign to a client module from a server module.');
}
};
var proxyHandlers = {
get: function (target, name, receiver) {
switch (name) {
// These names are read by the Flight runtime if you end up using the exports object.
case '$$typeof':
return target.$$typeof;
case '$$id':
return target.$$id;
case '$$async':
return target.$$async;
case 'name':
return target.name;
// We need to special case this because createElement reads it if we pass this
// reference.
case 'defaultProps':
return undefined;
// Avoid this attempting to be serialized.
case 'toJSON':
return undefined;
case Symbol.toPrimitive:
// $FlowFixMe[prop-missing]
return Object.prototype[Symbol.toPrimitive];
case '__esModule':
// Something is conditionally checking which export to use. We'll pretend to be
// an ESM compat module but then we'll check again on the client.
var moduleId = target.$$id;
target.default = registerClientReferenceImpl(function () {
throw new Error("Attempted to call the default export of " + moduleId + " from the server " + "but it's on the client. It's not possible to invoke a client function from " + "the server, it can only be rendered as a Component or passed to props of a " + "Client Component.");
}, target.$$id + '#', target.$$async);
return true;
case 'then':
if (target.then) {
// Use a cached value
return target.then;
}
if (!target.$$async) {
// If this module is expected to return a Promise (such as an AsyncModule) then
// we should resolve that with a client reference that unwraps the Promise on
// the client.
var clientReference = registerClientReferenceImpl({}, target.$$id, true);
var proxy = new Proxy(clientReference, proxyHandlers); // Treat this as a resolved Promise for React's use()
target.status = 'fulfilled';
target.value = proxy;
var then = target.then = registerClientReferenceImpl(function then(resolve, reject) {
// Expose to React.
return Promise.resolve(resolve(proxy));
}, // If this is not used as a Promise but is treated as a reference to a `.then`
// export then we should treat it as a reference to that name.
target.$$id + '#then', false);
return then;
} else {
// Since typeof .then === 'function' is a feature test we'd continue recursing
// indefinitely if we return a function. Instead, we return an object reference
// if we check further.
return undefined;
}
}
var cachedReference = target[name];
if (!cachedReference) {
var reference = registerClientReferenceImpl(function () {
throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
"Attempted to call " + String(name) + "() from the server but " + String(name) + " is on the client. " + "It's not possible to invoke a client function from the server, it can " + "only be rendered as a Component or passed to props of a Client Component.");
}, target.$$id + '#' + name, target.$$async);
Object.defineProperty(reference, 'name', {
value: name
});
cachedReference = target[name] = new Proxy(reference, deepProxyHandlers);
}
return cachedReference;
},
getPrototypeOf: function (target) {
// Pretend to be a Promise in case anyone asks.
return PROMISE_PROTOTYPE;
},
set: function () {
throw new Error('Cannot assign to a client module from a server module.');
}
};
function createClientModuleProxy(moduleId) {
var clientReference = registerClientReferenceImpl({}, // Represents the whole Module object instead of a particular import.
moduleId, false);
return new Proxy(clientReference, proxyHandlers);
}
function getClientReferenceKey(reference) {
return reference.$$async ? reference.$$id + '#async' : reference.$$id;
}
function resolveClientReferenceMetadata(config, clientReference) {
var modulePath = clientReference.$$id;
var name = '';
var resolvedModuleData = config[modulePath];
if (resolvedModuleData) {
// The potentially aliased name.
name = resolvedModuleData.name;
} else {
// We didn't find this specific export name but we might have the * export
// which contains this name as well.
// TODO: It's unfortunate that we now have to parse this string. We should
// probably go back to encoding path and name separately on the client reference.
var idx = modulePath.lastIndexOf('#');
if (idx !== -1) {
name = modulePath.slice(idx + 1);
resolvedModuleData = config[modulePath.slice(0, idx)];
}
if (!resolvedModuleData) {
throw new Error('Could not find the module "' + modulePath + '" in the React Client Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
}
}
return {
id: resolvedModuleData.id,
chunks: resolvedModuleData.chunks,
name: name,
async: !!clientReference.$$async
};
}
function getServerReferenceId(config, serverReference) {
return serverReference.$$id;
}
function getServerReferenceBoundArguments(config, serverReference) {
return serverReference.$$bound;
}
var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var ReactDOMFlightServerDispatcher = {
prefetchDNS: prefetchDNS,
preconnect: preconnect,
preload: preload,
preloadModule: preloadModule$1,
preinit: preinit,
preinitModule: preinitModule
};
function prefetchDNS(href, options) {
{
if (typeof href === 'string') {
var request = resolveRequest();
if (request) {
var hints = getHints(request);
var key = 'D' + href;
if (hints.has(key)) {
// duplicate hint
return;
}
hints.add(key);
if (options) {
emitHint(request, 'D', [href, options]);
} else {
emitHint(request, 'D', href);
}
}
}
}
}
function preconnect(href, options) {
{
if (typeof href === 'string') {
var request = resolveRequest();
if (request) {
var hints = getHints(request);
var crossOrigin = options == null || typeof options.crossOrigin !== 'string' ? null : options.crossOrigin === 'use-credentials' ? 'use-credentials' : '';
var key = "C" + (crossOrigin === null ? 'null' : crossOrigin) + "|" + href;
if (hints.has(key)) {
// duplicate hint
return;
}
hints.add(key);
if (options) {
emitHint(request, 'C', [href, options]);
} else {
emitHint(request, 'C', href);
}
}
}
}
}
function preload(href, options) {
{
if (typeof href === 'string') {
var request = resolveRequest();
if (request) {
var hints = getHints(request);
var key = 'L' + href;
if (hints.has(key)) {
// duplicate hint
return;
}
hints.add(key);
emitHint(request, 'L', [href, options]);
}
}
}
}
function preloadModule$1(href, options) {
{
if (typeof href === 'string') {
var request = resolveRequest();
if (request) {
var hints = getHints(request);
var key = 'm' + href;
if (hints.has(key)) {
// duplicate hint
return;
}
hints.add(key);
if (options) {
emitHint(request, 'm', [href, options]);
} else {
emitHint(request, 'm', href);
}
}
}
}
}
function preinit(href, options) {
{
if (typeof href === 'string') {
var request = resolveRequest();
if (request) {
var hints = getHints(request);
var key = 'I' + href;
if (hints.has(key)) {
// duplicate hint
return;
}
hints.add(key);
emitHint(request, 'I', [href, options]);
}
}
}
}
function preinitModule(href, options) {
{
if (typeof href === 'string') {
var request = resolveRequest();
if (request) {
var hints = getHints(request);
var key = 'M' + href;
if (hints.has(key)) {
// duplicate hint
return;
}
hints.add(key);
if (options) {
emitHint(request, 'M', [href, options]);
} else {
emitHint(request, 'M', href);
}
}
}
}
}
var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
function prepareHostDispatcher() {
ReactDOMCurrentDispatcher.current = ReactDOMFlightServerDispatcher;
} // Used to distinguish these contexts from ones used in other renderers.
function createHints() {
return new Set();
}
// ATTENTION
// When adding new symbols to this file,
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
// The Symbol used to tag the ReactElement-like types.
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
var REACT_MEMO_TYPE = Symbol.for('react.memo');
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator';
function getIteratorFn(maybeIterable) {
if (maybeIterable === null || typeof maybeIterable !== 'object') {
return null;
}
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
if (typeof maybeIterator === 'function') {
return maybeIterator;
}
return null;
}
var rendererSigil;
{
// Use this to detect multiple renderers using the same context
rendererSigil = {};
} // Used to store the parent path of all context overrides in a shared linked list.
// Forming a reverse tree.
// The structure of a context snapshot is an implementation of this file.
// Currently, it's implemented as tracking the current active node.
var rootContextSnapshot = null; // We assume that this runtime owns the "current" field on all ReactContext instances.
// This global (actually thread local) state represents what state all those "current",
// fields are currently in.
var currentActiveSnapshot = null;
function popNode(prev) {
{
prev.context._currentValue = prev.parentValue;
}
}
function pushNode(next) {
{
next.context._currentValue = next.value;
}
}
function popToNearestCommonAncestor(prev, next) {
if (prev === next) ; else {
popNode(prev);
var parentPrev = prev.parent;
var parentNext = next.parent;
if (parentPrev === null) {
if (parentNext !== null) {
throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
}
} else {
if (parentNext === null) {
throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
}
popToNearestCommonAncestor(parentPrev, parentNext); // On the way back, we push the new ones that weren't common.
pushNode(next);
}
}
}
function popAllPrevious(prev) {
popNode(prev);
var parentPrev = prev.parent;
if (parentPrev !== null) {
popAllPrevious(parentPrev);
}
}
function pushAllNext(next) {
var parentNext = next.parent;
if (parentNext !== null) {
pushAllNext(parentNext);
}
pushNode(next);
}
function popPreviousToCommonLevel(prev, next) {
popNode(prev);
var parentPrev = prev.parent;
if (parentPrev === null) {
throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
}
if (parentPrev.depth === next.depth) {
// We found the same level. Now we just need to find a shared ancestor.
popToNearestCommonAncestor(parentPrev, next);
} else {
// We must still be deeper.
popPreviousToCommonLevel(parentPrev, next);
}
}
function popNextToCommonLevel(prev, next) {
var parentNext = next.parent;
if (parentNext === null) {
throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
}
if (prev.depth === parentNext.depth) {
// We found the same level. Now we just need to find a shared ancestor.
popToNearestCommonAncestor(prev, parentNext);
} else {
// We must still be deeper.
popNextToCommonLevel(prev, parentNext);
}
pushNode(next);
} // Perform context switching to the new snapshot.
// To make it cheap to read many contexts, while not suspending, we make the switch eagerly by
// updating all the context's current values. That way reads, always just read the current value.
// At the cost of updating contexts even if they're never read by this subtree.
function switchContext(newSnapshot) {
// The basic algorithm we need to do is to pop back any contexts that are no longer on the stack.
// We also need to update any new contexts that are now on the stack with the deepest value.
// The easiest way to update new contexts is to just reapply them in reverse order from the
// perspective of the backpointers. To avoid allocating a lot when switching, we use the stack
// for that. Therefore this algorithm is recursive.
// 1) First we pop which ever snapshot tree was deepest. Popping old contexts as we go.
// 2) Then we find the nearest common ancestor from there. Popping old contexts as we go.
// 3) Then we reapply new contexts on the way back up the stack.
var prev = currentActiveSnapshot;
var next = newSnapshot;
if (prev !== next) {
if (prev === null) {
// $FlowFixMe[incompatible-call]: This has to be non-null since it's not equal to prev.
pushAllNext(next);
} else if (next === null) {
popAllPrevious(prev);
} else if (prev.depth === next.depth) {
popToNearestCommonAncestor(prev, next);
} else if (prev.depth > next.depth) {
popPreviousToCommonLevel(prev, next);
} else {
popNextToCommonLevel(prev, next);
}
currentActiveSnapshot = next;
}
}
function pushProvider(context, nextValue) {
var prevValue;
{
prevValue = context._currentValue;
context._currentValue = nextValue;
{
if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
}
context._currentRenderer = rendererSigil;
}
}
var prevNode = currentActiveSnapshot;
var newNode = {
parent: prevNode,
depth: prevNode === null ? 0 : prevNode.depth + 1,
context: context,
parentValue: prevValue,
value: nextValue
};
currentActiveSnapshot = newNode;
return newNode;
}
function popProvider() {
var prevSnapshot = currentActiveSnapshot;
if (prevSnapshot === null) {
throw new Error('Tried to pop a Context at the root of the app. This is a bug in React.');
}
{
var value = prevSnapshot.parentValue;
if (value === REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED) {
prevSnapshot.context._currentValue = prevSnapshot.context._defaultValue;
} else {
prevSnapshot.context._currentValue = value;
}
}
return currentActiveSnapshot = prevSnapshot.parent;
}
function getActiveContext() {
return currentActiveSnapshot;
}
function readContext$1(context) {
var value = context._currentValue ;
return value;
}
// Corresponds to ReactFiberWakeable and ReactFizzWakeable modules. Generally,
// changes to one module should be reflected in the others.
// TODO: Rename this module and the corresponding Fiber one to "Thenable"
// instead of "Wakeable". Or some other more appropriate name.
// An error that is thrown (e.g. by `use`) to trigger Suspense. If we
// detect this is caught by userspace, we'll log a warning in development.
var SuspenseException = new Error("Suspense Exception: This is not a real error! It's an implementation " + 'detail of `use` to interrupt the current render. You must either ' + 'rethrow it immediately, or move the `use` call outside of the ' + '`try/catch` block. Capturing without rethrowing will lead to ' + 'unexpected behavior.\n\n' + 'To handle async errors, wrap your component in an error boundary, or ' + "call the promise's `.catch` method and pass the result to `use`");
function createThenableState() {
// The ThenableState is created the first time a component suspends. If it
// suspends again, we'll reuse the same state.
return [];
}
function noop() {}
function trackUsedThenable(thenableState, thenable, index) {
var previous = thenableState[index];
if (previous === undefined) {
thenableState.push(thenable);
} else {
if (previous !== thenable) {
// Reuse the previous thenable, and drop the new one. We can assume
// they represent the same value, because components are idempotent.
// Avoid an unhandled rejection errors for the Promises that we'll
// intentionally ignore.
thenable.then(noop, noop);
thenable = previous;
}
} // We use an expando to track the status and result of a thenable so that we
// can synchronously unwrap the value. Think of this as an extension of the
// Promise API, or a custom interface that is a superset of Thenable.
//
// If the thenable doesn't have a status, set it to "pending" and attach
// a listener that will update its status and result when it resolves.
switch (thenable.status) {
case 'fulfilled':
{
var fulfilledValue = thenable.value;
return fulfilledValue;
}
case 'rejected':
{
var rejectedError = thenable.reason;
throw rejectedError;
}
default:
{
if (typeof thenable.status === 'string') ; else {
var pendingThenable = thenable;
pendingThenable.status = 'pending';
pendingThenable.then(function (fulfilledValue) {
if (thenable.status === 'pending') {
var fulfilledThenable = thenable;
fulfilledThenable.status = 'fulfilled';
fulfilledThenable.value = fulfilledValue;
}
}, function (error) {
if (thenable.status === 'pending') {
var rejectedThenable = thenable;
rejectedThenable.status = 'rejected';
rejectedThenable.reason = error;
}
}); // Check one more time in case the thenable resolved synchronously
switch (thenable.status) {
case 'fulfilled':
{
var fulfilledThenable = thenable;
return fulfilledThenable.value;
}
case 'rejected':
{
var rejectedThenable = thenable;
throw rejectedThenable.reason;
}
}
} // Suspend.
//
// Throwing here is an implementation detail that allows us to unwind the
// call stack. But we shouldn't allow it to leak into userspace. Throw an
// opaque placeholder value instead of the actual thenable. If it doesn't
// get captured by the work loop, log a warning, because that means
// something in userspace must have caught it.
suspendedThenable = thenable;
throw SuspenseException;
}
}
} // This is used to track the actual thenable that suspended so it can be
// passed to the rest of the Suspense implementation — which, for historical
// reasons, expects to receive a thenable.
var suspendedThenable = null;
function getSuspendedThenable() {
// This is called right after `use` suspends by throwing an exception. `use`
// throws an opaque value instead of the thenable itself so that it can't be
// caught in userspace. Then the work loop accesses the actual thenable using
// this function.
if (suspendedThenable === null) {
throw new Error('Expected a suspended thenable. This is a bug in React. Please file ' + 'an issue.');
}
var thenable = suspendedThenable;
suspendedThenable = null;
return thenable;
}
var currentRequest$1 = null;
var thenableIndexCounter = 0;
var thenableState = null;
function prepareToUseHooksForRequest(request) {
currentRequest$1 = request;
}
function resetHooksForRequest() {
currentRequest$1 = null;
}
function prepareToUseHooksForComponent(prevThenableState) {
thenableIndexCounter = 0;
thenableState = prevThenableState;
}
function getThenableStateAfterSuspending() {
var state = thenableState;
thenableState = null;
return state;
}
function readContext(context) {
{
if (context.$$typeof !== REACT_SERVER_CONTEXT_TYPE) {
if (isClientReference(context)) {
error('Cannot read a Client Context from a Server Component.');
} else {
error('Only createServerContext is supported in Server Components.');
}
}
if (currentRequest$1 === null) {
error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
}
}
return readContext$1(context);
}
var HooksDispatcher = {
useMemo: function (nextCreate) {
return nextCreate();
},
useCallback: function (callback) {
return callback;
},
useDebugValue: function () {},
useDeferredValue: unsupportedHook,
useTransition: unsupportedHook,
readContext: readContext,
useContext: readContext,
useReducer: unsupportedHook,
useRef: unsupportedHook,
useState: unsupportedHook,
useInsertionEffect: unsupportedHook,
useLayoutEffect: unsupportedHook,
useImperativeHandle: unsupportedHook,
useEffect: unsupportedHook,
useId: useId,
useSyncExternalStore: unsupportedHook,
useCacheRefresh: function () {
return unsupportedRefresh;
},
useMemoCache: function (size) {
var data = new Array(size);
for (var i = 0; i < size; i++) {
data[i] = REACT_MEMO_CACHE_SENTINEL;
}
return data;
},
use: use
};
function unsupportedHook() {
throw new Error('This Hook is not supported in Server Components.');
}
function unsupportedRefresh() {
throw new Error('Refreshing the cache is not supported in Server Components.');
}
function useId() {
if (currentRequest$1 === null) {
throw new Error('useId can only be used while React is rendering');
}
var id = currentRequest$1.identifierCount++; // use 'S' for Flight components to distinguish from 'R' and 'r' in Fizz/Client
return ':' + currentRequest$1.identifierPrefix + 'S' + id.toString(32) + ':';
}