-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathreact-server-dom-webpack-client.browser.development.js
1917 lines (1554 loc) · 51.6 KB
/
react-server-dom-webpack-client.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-client.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 ReactDOM = require('react-dom');
var React = require('react');
// -----------------------------------------------------------------------------
var enableBinaryFlight = false;
function createStringDecoder() {
return new TextDecoder();
}
var decoderOptions = {
stream: true
};
function readPartialStringChunk(decoder, buffer) {
return decoder.decode(buffer, decoderOptions);
}
function readFinalStringChunk(decoder, buffer) {
return decoder.decode(buffer);
}
// eslint-disable-next-line no-unused-vars
function resolveClientReference(bundlerConfig, metadata) {
if (bundlerConfig) {
var moduleExports = bundlerConfig[metadata.id];
var resolvedModuleData = moduleExports[metadata.name];
var name;
if (resolvedModuleData) {
// The potentially aliased name.
name = resolvedModuleData.name;
} else {
// If we don't have this specific name, we might have the full module.
resolvedModuleData = moduleExports['*'];
if (!resolvedModuleData) {
throw new Error('Could not find the module "' + metadata.id + '" in the React SSR Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
}
name = metadata.name;
}
return {
id: resolvedModuleData.id,
chunks: resolvedModuleData.chunks,
name: name,
async: !!metadata.async
};
}
return metadata;
}
// If they're still pending they're a thenable. This map also exists
// in Webpack but unfortunately it's not exposed so we have to
// replicate it in user space. null means that it has already loaded.
var chunkCache = new Map();
function requireAsyncModule(id) {
// We've already loaded all the chunks. We can require the module.
var promise = globalThis.__next_require__(id);
if (typeof promise.then !== 'function') {
// This wasn't a promise after all.
return null;
} else if (promise.status === 'fulfilled') {
// This module was already resolved earlier.
return null;
} else {
// Instrument the Promise to stash the result.
promise.then(function (value) {
var fulfilledThenable = promise;
fulfilledThenable.status = 'fulfilled';
fulfilledThenable.value = value;
}, function (reason) {
var rejectedThenable = promise;
rejectedThenable.status = 'rejected';
rejectedThenable.reason = reason;
});
return promise;
}
}
function ignoreReject() {// We rely on rejected promises to be handled by another listener.
} // Start preloading the modules since we might need them soon.
// This function doesn't suspend.
function preloadModule(metadata) {
var chunks = metadata.chunks;
var promises = [];
for (var i = 0; i < chunks.length; i++) {
var chunkId = chunks[i];
var entry = chunkCache.get(chunkId);
if (entry === undefined) {
var thenable = globalThis.__next_chunk_load__(chunkId);
promises.push(thenable); // $FlowFixMe[method-unbinding]
var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
thenable.then(resolve, ignoreReject);
chunkCache.set(chunkId, thenable);
} else if (entry !== null) {
promises.push(entry);
}
}
if (metadata.async) {
if (promises.length === 0) {
return requireAsyncModule(metadata.id);
} else {
return Promise.all(promises).then(function () {
return requireAsyncModule(metadata.id);
});
}
} else if (promises.length > 0) {
return Promise.all(promises);
} else {
return null;
}
} // Actually require the module or suspend if it's not yet ready.
// Increase priority if necessary.
function requireModule(metadata) {
var moduleExports = globalThis.__next_require__(metadata.id);
if (metadata.async) {
if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
// This Promise should've been instrumented by preloadModule.
moduleExports = moduleExports.value;
} else {
throw moduleExports.reason;
}
}
if (metadata.name === '*') {
// This is a placeholder value that represents that the caller imported this
// as a CommonJS module as is.
return moduleExports;
}
if (metadata.name === '') {
// This is a placeholder value that represents that the caller accessed the
// default property of this if it was an ESM interop module.
return moduleExports.__esModule ? moduleExports.default : moduleExports;
}
return moduleExports[metadata.name];
}
var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
// This client file is in the shared folder because it applies to both SSR and browser contexts.
var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
function dispatchHint(code, model) {
var dispatcher = ReactDOMCurrentDispatcher.current;
if (dispatcher) {
var href, options;
if (typeof model === 'string') {
href = model;
} else {
href = model[0];
options = model[1];
}
switch (code) {
case 'D':
{
// $FlowFixMe[prop-missing] options are not refined to their types by code
dispatcher.prefetchDNS(href, options);
return;
}
case 'C':
{
// $FlowFixMe[prop-missing] options are not refined to their types by code
dispatcher.preconnect(href, options);
return;
}
case 'L':
{
// $FlowFixMe[prop-missing] options are not refined to their types by code
// $FlowFixMe[incompatible-call] options are not refined to their types by code
dispatcher.preload(href, options);
return;
}
case 'm':
{
// $FlowFixMe[prop-missing] options are not refined to their types by code
// $FlowFixMe[incompatible-call] options are not refined to their types by code
dispatcher.preloadModule(href, options);
return;
}
case 'I':
{
// $FlowFixMe[prop-missing] options are not refined to their types by code
// $FlowFixMe[incompatible-call] options are not refined to their types by code
dispatcher.preinit(href, options);
return;
}
case 'M':
{
// $FlowFixMe[prop-missing] options are not refined to their types by code
// $FlowFixMe[incompatible-call] options are not refined to their types by code
dispatcher.preinitModule(href, options);
return;
}
}
}
}
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);
}
}
// 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_PROVIDER_TYPE = Symbol.for('react.provider');
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 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 isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
function isArray(a) {
return isArrayImpl(a);
}
// in case they error.
var jsxPropsParents = new WeakMap();
var jsxChildrenParents = new WeakMap();
function isObjectPrototype(object) {
if (!object) {
return false;
}
var ObjectPrototype = Object.prototype;
if (object === ObjectPrototype) {
return true;
} // It might be an object from a different Realm which is
// still just a plain simple object.
if (Object.getPrototypeOf(object)) {
return false;
}
var names = Object.getOwnPropertyNames(object);
for (var i = 0; i < names.length; i++) {
if (!(names[i] in ObjectPrototype)) {
return false;
}
}
return true;
}
function isSimpleObject(object) {
if (!isObjectPrototype(Object.getPrototypeOf(object))) {
return false;
}
var names = Object.getOwnPropertyNames(object);
for (var i = 0; i < names.length; i++) {
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
if (!descriptor) {
return false;
}
if (!descriptor.enumerable) {
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
// React adds key and ref getters to props objects to issue warnings.
// Those getters will not be transferred to the client, but that's ok,
// so we'll special case them.
continue;
}
return false;
}
}
return true;
}
function objectName(object) {
// $FlowFixMe[method-unbinding]
var name = Object.prototype.toString.call(object);
return name.replace(/^\[object (.*)\]$/, function (m, p0) {
return p0;
});
}
function describeKeyForErrorMessage(key) {
var encodedKey = JSON.stringify(key);
return '"' + key + '"' === encodedKey ? key : encodedKey;
}
function describeValueForErrorMessage(value) {
switch (typeof value) {
case 'string':
{
return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
}
case 'object':
{
if (isArray(value)) {
return '[...]';
}
var name = objectName(value);
if (name === 'Object') {
return '{...}';
}
return name;
}
case 'function':
return 'function';
default:
// eslint-disable-next-line react-internal/safe-string-coercion
return String(value);
}
}
function describeElementType(type) {
if (typeof type === 'string') {
return type;
}
switch (type) {
case REACT_SUSPENSE_TYPE:
return 'Suspense';
case REACT_SUSPENSE_LIST_TYPE:
return 'SuspenseList';
}
if (typeof type === 'object') {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
return describeElementType(type.render);
case REACT_MEMO_TYPE:
return describeElementType(type.type);
case REACT_LAZY_TYPE:
{
var lazyComponent = type;
var payload = lazyComponent._payload;
var init = lazyComponent._init;
try {
// Lazy may contain any component type so we recursively resolve it.
return describeElementType(init(payload));
} catch (x) {}
}
}
}
return '';
}
function describeObjectForErrorMessage(objectOrArray, expandedName) {
var objKind = objectName(objectOrArray);
if (objKind !== 'Object' && objKind !== 'Array') {
return objKind;
}
var str = '';
var start = -1;
var length = 0;
if (isArray(objectOrArray)) {
if (jsxChildrenParents.has(objectOrArray)) {
// Print JSX Children
var type = jsxChildrenParents.get(objectOrArray);
str = '<' + describeElementType(type) + '>';
var array = objectOrArray;
for (var i = 0; i < array.length; i++) {
var value = array[i];
var substr = void 0;
if (typeof value === 'string') {
substr = value;
} else if (typeof value === 'object' && value !== null) {
substr = '{' + describeObjectForErrorMessage(value) + '}';
} else {
substr = '{' + describeValueForErrorMessage(value) + '}';
}
if ('' + i === expandedName) {
start = str.length;
length = substr.length;
str += substr;
} else if (substr.length < 15 && str.length + substr.length < 40) {
str += substr;
} else {
str += '{...}';
}
}
str += '</' + describeElementType(type) + '>';
} else {
// Print Array
str = '[';
var _array = objectOrArray;
for (var _i = 0; _i < _array.length; _i++) {
if (_i > 0) {
str += ', ';
}
var _value = _array[_i];
var _substr = void 0;
if (typeof _value === 'object' && _value !== null) {
_substr = describeObjectForErrorMessage(_value);
} else {
_substr = describeValueForErrorMessage(_value);
}
if ('' + _i === expandedName) {
start = str.length;
length = _substr.length;
str += _substr;
} else if (_substr.length < 10 && str.length + _substr.length < 40) {
str += _substr;
} else {
str += '...';
}
}
str += ']';
}
} else {
if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
str = '<' + describeElementType(objectOrArray.type) + '/>';
} else if (jsxPropsParents.has(objectOrArray)) {
// Print JSX
var _type = jsxPropsParents.get(objectOrArray);
str = '<' + (describeElementType(_type) || '...');
var object = objectOrArray;
var names = Object.keys(object);
for (var _i2 = 0; _i2 < names.length; _i2++) {
str += ' ';
var name = names[_i2];
str += describeKeyForErrorMessage(name) + '=';
var _value2 = object[name];
var _substr2 = void 0;
if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
_substr2 = describeObjectForErrorMessage(_value2);
} else {
_substr2 = describeValueForErrorMessage(_value2);
}
if (typeof _value2 !== 'string') {
_substr2 = '{' + _substr2 + '}';
}
if (name === expandedName) {
start = str.length;
length = _substr2.length;
str += _substr2;
} else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
str += _substr2;
} else {
str += '...';
}
}
str += '>';
} else {
// Print Object
str = '{';
var _object = objectOrArray;
var _names = Object.keys(_object);
for (var _i3 = 0; _i3 < _names.length; _i3++) {
if (_i3 > 0) {
str += ', ';
}
var _name = _names[_i3];
str += describeKeyForErrorMessage(_name) + ': ';
var _value3 = _object[_name];
var _substr3 = void 0;
if (typeof _value3 === 'object' && _value3 !== null) {
_substr3 = describeObjectForErrorMessage(_value3);
} else {
_substr3 = describeValueForErrorMessage(_value3);
}
if (_name === expandedName) {
start = str.length;
length = _substr3.length;
str += _substr3;
} else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
str += _substr3;
} else {
str += '...';
}
}
str += '}';
}
}
if (expandedName === undefined) {
return str;
}
if (start > -1 && length > 0) {
var highlight = ' '.repeat(start) + '^'.repeat(length);
return '\n ' + str + '\n ' + highlight;
}
return '\n ' + str;
}
var knownServerReferences = new WeakMap(); // Serializable values
// Thenable<ReactServerValue>
// function serializeByValueID(id: number): string {
// return '$' + id.toString(16);
// }
function serializePromiseID(id) {
return '$@' + id.toString(16);
}
function serializeServerReferenceID(id) {
return '$F' + id.toString(16);
}
function serializeSymbolReference(name) {
return '$S' + name;
}
function serializeFormDataReference(id) {
// Why K? F is "Function". D is "Date". What else?
return '$K' + id.toString(16);
}
function serializeNumber(number) {
if (Number.isFinite(number)) {
if (number === 0 && 1 / number === -Infinity) {
return '$-0';
} else {
return number;
}
} else {
if (number === Infinity) {
return '$Infinity';
} else if (number === -Infinity) {
return '$-Infinity';
} else {
return '$NaN';
}
}
}
function serializeUndefined() {
return '$undefined';
}
function serializeDateFromDateJSON(dateJSON) {
// JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
// We need only tack on a $D prefix.
return '$D' + dateJSON;
}
function serializeBigInt(n) {
return '$n' + n.toString(10);
}
function serializeMapID(id) {
return '$Q' + id.toString(16);
}
function serializeSetID(id) {
return '$W' + id.toString(16);
}
function escapeStringValue(value) {
if (value[0] === '$') {
// We need to escape $ prefixed strings since we use those to encode
// references to IDs and as special symbol values.
return '$' + value;
} else {
return value;
}
}
function processReply(root, formFieldPrefix, resolve, reject) {
var nextPartId = 1;
var pendingParts = 0;
var formData = null;
function resolveToJSON(key, value) {
var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
{
// $FlowFixMe[incompatible-use]
var originalValue = parent[key];
if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
if (objectName(originalValue) !== 'Object') {
error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
} else {
error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
}
}
}
if (value === null) {
return null;
}
if (typeof value === 'object') {
// $FlowFixMe[method-unbinding]
if (typeof value.then === 'function') {
// We assume that any object with a .then property is a "Thenable" type,
// or a Promise type. Either of which can be represented by a Promise.
if (formData === null) {
// Upgrade to use FormData to allow us to stream this value.
formData = new FormData();
}
pendingParts++;
var promiseId = nextPartId++;
var thenable = value;
thenable.then(function (partValue) {
var partJSON = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
data.append(formFieldPrefix + promiseId, partJSON);
pendingParts--;
if (pendingParts === 0) {
resolve(data);
}
}, function (reason) {
// In the future we could consider serializing this as an error
// that throws on the server instead.
reject(reason);
});
return serializePromiseID(promiseId);
} // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
if (value instanceof FormData) {
if (formData === null) {
// Upgrade to use FormData to allow us to use rich objects as its values.
formData = new FormData();
}
var data = formData;
var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
// These must come first in the form order because we assume that all the
// fields are available before this is referenced.
var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
value.forEach(function (originalValue, originalKey) {
data.append(prefix + originalKey, originalValue);
});
return serializeFormDataReference(refId);
}
if (value instanceof Map) {
var partJSON = JSON.stringify(Array.from(value), resolveToJSON);
if (formData === null) {
formData = new FormData();
}
var mapId = nextPartId++;
formData.append(formFieldPrefix + mapId, partJSON);
return serializeMapID(mapId);
}
if (value instanceof Set) {
var _partJSON = JSON.stringify(Array.from(value), resolveToJSON);
if (formData === null) {
formData = new FormData();
}
var setId = nextPartId++;
formData.append(formFieldPrefix + setId, _partJSON);
return serializeSetID(setId);
}
if (!isArray(value)) {
var iteratorFn = getIteratorFn(value);
if (iteratorFn) {
return Array.from(value);
}
}
{
if (value !== null && !isArray(value)) {
// Verify that this is a simple plain object.
if (value.$$typeof === REACT_ELEMENT_TYPE) {
error('React Element cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
} else if (value.$$typeof === REACT_LAZY_TYPE) {
error('React Lazy cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
} else if (value.$$typeof === REACT_PROVIDER_TYPE) {
error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
} else if (objectName(value) !== 'Object') {
error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
} else if (!isSimpleObject(value)) {
error('Only plain objects can be passed to Client Components from Server Components. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
} else if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(value);
if (symbols.length > 0) {
error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
}
}
}
} // $FlowFixMe[incompatible-return]
return value;
}
if (typeof value === 'string') {
// TODO: Maybe too clever. If we support URL there's no similar trick.
if (value[value.length - 1] === 'Z') {
// Possibly a Date, whose toJSON automatically calls toISOString
// $FlowFixMe[incompatible-use]
var _originalValue = parent[key];
if (_originalValue instanceof Date) {
return serializeDateFromDateJSON(value);
}
}
return escapeStringValue(value);
}
if (typeof value === 'boolean') {
return value;
}
if (typeof value === 'number') {
return serializeNumber(value);
}
if (typeof value === 'undefined') {
return serializeUndefined();
}
if (typeof value === 'function') {
var metaData = knownServerReferences.get(value);
if (metaData !== undefined) {
var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
if (formData === null) {
// Upgrade to use FormData to allow us to stream this value.
formData = new FormData();
} // The reference to this function came from the same client so we can pass it back.
var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
formData.set(formFieldPrefix + _refId, metaDataJSON);
return serializeServerReferenceID(_refId);
}
throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
}
if (typeof value === 'symbol') {
// $FlowFixMe[incompatible-type] `description` might be undefined
var name = value.description;
if (Symbol.for(name) !== value) {
throw new Error('Only global symbols received from Symbol.for(...) can be passed to Server Functions. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
value.description + ") cannot be found among global symbols."));
}
return serializeSymbolReference(name);
}
if (typeof value === 'bigint') {
return serializeBigInt(value);
}
throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
} // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
var json = JSON.stringify(root, resolveToJSON);
if (formData === null) {
// If it's a simple data structure, we just use plain JSON.
resolve(json);
} else {
// Otherwise, we use FormData to let us stream in the result.
formData.set(formFieldPrefix + '0', json);
if (pendingParts === 0) {
// $FlowFixMe[incompatible-call] this has already been refined.
resolve(formData);
}
}
}
function createServerReference(id, callServer) {
var proxy = function () {
// $FlowFixMe[method-unbinding]
var args = Array.prototype.slice.call(arguments);
return callServer(id, args);
}; // Expose encoder for use by SSR.
knownServerReferences.set(proxy, {
id: id,
bound: null
});
return proxy;
}
var ContextRegistry = ReactSharedInternals.ContextRegistry;
function getOrCreateServerContext(globalName) {
if (!ContextRegistry[globalName]) {
ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
}
return ContextRegistry[globalName];
}
var ROW_ID = 0;
var ROW_TAG = 1;
var ROW_LENGTH = 2;
var ROW_CHUNK_BY_NEWLINE = 3;
var ROW_CHUNK_BY_LENGTH = 4;
var PENDING = 'pending';
var BLOCKED = 'blocked';
var RESOLVED_MODEL = 'resolved_model';
var RESOLVED_MODULE = 'resolved_module';
var INITIALIZED = 'fulfilled';
var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
function Chunk(status, value, reason, response) {
this.status = status;
this.value = value;
this.reason = reason;
this._response = response;
} // We subclass Promise.prototype so that we get other methods like .catch
Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
Chunk.prototype.then = function (resolve, reject) {
var chunk = this; // If we have resolved content, we try to initialize it first which
// might put us back into one of the other states.
switch (chunk.status) {
case RESOLVED_MODEL:
initializeModelChunk(chunk);
break;
case RESOLVED_MODULE:
initializeModuleChunk(chunk);
break;
} // The status might have changed after initialization.
switch (chunk.status) {
case INITIALIZED:
resolve(chunk.value);
break;
case PENDING:
case BLOCKED:
if (resolve) {
if (chunk.value === null) {
chunk.value = [];
}
chunk.value.push(resolve);
}
if (reject) {
if (chunk.reason === null) {
chunk.reason = [];
}
chunk.reason.push(reject);
}
break;
default:
reject(chunk.reason);
break;
}
};