react-server-dom-webpack 18.3.0-canary-b7972822b-20230503 → 18.3.0-canary-b00e27342-20230505

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.
Files changed (21) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +1180 -1096
  2. package/cjs/react-server-dom-webpack-client.browser.production.min.js +27 -25
  3. package/cjs/react-server-dom-webpack-client.edge.development.js +722 -3
  4. package/cjs/react-server-dom-webpack-client.edge.production.min.js +24 -18
  5. package/cjs/react-server-dom-webpack-client.node.development.js +722 -3
  6. package/cjs/react-server-dom-webpack-client.node.production.min.js +25 -19
  7. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +722 -3
  8. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +24 -17
  9. package/cjs/react-server-dom-webpack-server.browser.development.js +82 -4
  10. package/cjs/react-server-dom-webpack-server.browser.production.min.js +43 -41
  11. package/cjs/react-server-dom-webpack-server.edge.development.js +82 -4
  12. package/cjs/react-server-dom-webpack-server.edge.production.min.js +49 -47
  13. package/cjs/react-server-dom-webpack-server.node.development.js +82 -4
  14. package/cjs/react-server-dom-webpack-server.node.production.min.js +54 -52
  15. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +82 -4
  16. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +53 -51
  17. package/package.json +3 -3
  18. package/umd/react-server-dom-webpack-client.browser.development.js +1180 -1096
  19. package/umd/react-server-dom-webpack-client.browser.production.min.js +21 -19
  20. package/umd/react-server-dom-webpack-server.browser.development.js +82 -4
  21. package/umd/react-server-dom-webpack-server.browser.production.min.js +41 -40
@@ -214,17 +214,733 @@ function dispatchHint(code, model) {
214
214
  }
215
215
  }
216
216
 
217
- var knownServerReferences = new WeakMap();
217
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
218
+
219
+ function error(format) {
220
+ {
221
+ {
222
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
223
+ args[_key2 - 1] = arguments[_key2];
224
+ }
225
+
226
+ printWarning('error', format, args);
227
+ }
228
+ }
229
+ }
230
+
231
+ function printWarning(level, format, args) {
232
+ // When changing this logic, you might want to also
233
+ // update consoleWithStackDev.www.js as well.
234
+ {
235
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
236
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
237
+
238
+ if (stack !== '') {
239
+ format += '%s';
240
+ args = args.concat([stack]);
241
+ } // eslint-disable-next-line react-internal/safe-string-coercion
242
+
243
+
244
+ var argsWithFormat = args.map(function (item) {
245
+ return String(item);
246
+ }); // Careful: RN currently depends on this prefix
247
+
248
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
249
+ // breaks IE9: https://github.com/facebook/react/issues/13610
250
+ // eslint-disable-next-line react-internal/no-production-logging
251
+
252
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
253
+ }
254
+ }
218
255
 
219
256
  // ATTENTION
220
257
  // When adding new symbols to this file,
221
258
  // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
222
259
  // The Symbol used to tag the ReactElement-like types.
223
260
  var REACT_ELEMENT_TYPE = Symbol.for('react.element');
261
+ var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
262
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
263
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
264
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
265
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
224
266
  var REACT_LAZY_TYPE = Symbol.for('react.lazy');
225
267
  var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
268
+ var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
269
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
270
+ function getIteratorFn(maybeIterable) {
271
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
272
+ return null;
273
+ }
226
274
 
227
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
275
+ var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
276
+
277
+ if (typeof maybeIterator === 'function') {
278
+ return maybeIterator;
279
+ }
280
+
281
+ return null;
282
+ }
283
+
284
+ var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
285
+
286
+ function isArray(a) {
287
+ return isArrayImpl(a);
288
+ }
289
+
290
+ // in case they error.
291
+
292
+ var jsxPropsParents = new WeakMap();
293
+ var jsxChildrenParents = new WeakMap();
294
+
295
+ function isObjectPrototype(object) {
296
+ if (!object) {
297
+ return false;
298
+ }
299
+
300
+ var ObjectPrototype = Object.prototype;
301
+
302
+ if (object === ObjectPrototype) {
303
+ return true;
304
+ } // It might be an object from a different Realm which is
305
+ // still just a plain simple object.
306
+
307
+
308
+ if (Object.getPrototypeOf(object)) {
309
+ return false;
310
+ }
311
+
312
+ var names = Object.getOwnPropertyNames(object);
313
+
314
+ for (var i = 0; i < names.length; i++) {
315
+ if (!(names[i] in ObjectPrototype)) {
316
+ return false;
317
+ }
318
+ }
319
+
320
+ return true;
321
+ }
322
+
323
+ function isSimpleObject(object) {
324
+ if (!isObjectPrototype(Object.getPrototypeOf(object))) {
325
+ return false;
326
+ }
327
+
328
+ var names = Object.getOwnPropertyNames(object);
329
+
330
+ for (var i = 0; i < names.length; i++) {
331
+ var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
332
+
333
+ if (!descriptor) {
334
+ return false;
335
+ }
336
+
337
+ if (!descriptor.enumerable) {
338
+ if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
339
+ // React adds key and ref getters to props objects to issue warnings.
340
+ // Those getters will not be transferred to the client, but that's ok,
341
+ // so we'll special case them.
342
+ continue;
343
+ }
344
+
345
+ return false;
346
+ }
347
+ }
348
+
349
+ return true;
350
+ }
351
+ function objectName(object) {
352
+ // $FlowFixMe[method-unbinding]
353
+ var name = Object.prototype.toString.call(object);
354
+ return name.replace(/^\[object (.*)\]$/, function (m, p0) {
355
+ return p0;
356
+ });
357
+ }
358
+
359
+ function describeKeyForErrorMessage(key) {
360
+ var encodedKey = JSON.stringify(key);
361
+ return '"' + key + '"' === encodedKey ? key : encodedKey;
362
+ }
363
+
364
+ function describeValueForErrorMessage(value) {
365
+ switch (typeof value) {
366
+ case 'string':
367
+ {
368
+ return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
369
+ }
370
+
371
+ case 'object':
372
+ {
373
+ if (isArray(value)) {
374
+ return '[...]';
375
+ }
376
+
377
+ var name = objectName(value);
378
+
379
+ if (name === 'Object') {
380
+ return '{...}';
381
+ }
382
+
383
+ return name;
384
+ }
385
+
386
+ case 'function':
387
+ return 'function';
388
+
389
+ default:
390
+ // eslint-disable-next-line react-internal/safe-string-coercion
391
+ return String(value);
392
+ }
393
+ }
394
+
395
+ function describeElementType(type) {
396
+ if (typeof type === 'string') {
397
+ return type;
398
+ }
399
+
400
+ switch (type) {
401
+ case REACT_SUSPENSE_TYPE:
402
+ return 'Suspense';
403
+
404
+ case REACT_SUSPENSE_LIST_TYPE:
405
+ return 'SuspenseList';
406
+ }
407
+
408
+ if (typeof type === 'object') {
409
+ switch (type.$$typeof) {
410
+ case REACT_FORWARD_REF_TYPE:
411
+ return describeElementType(type.render);
412
+
413
+ case REACT_MEMO_TYPE:
414
+ return describeElementType(type.type);
415
+
416
+ case REACT_LAZY_TYPE:
417
+ {
418
+ var lazyComponent = type;
419
+ var payload = lazyComponent._payload;
420
+ var init = lazyComponent._init;
421
+
422
+ try {
423
+ // Lazy may contain any component type so we recursively resolve it.
424
+ return describeElementType(init(payload));
425
+ } catch (x) {}
426
+ }
427
+ }
428
+ }
429
+
430
+ return '';
431
+ }
432
+
433
+ function describeObjectForErrorMessage(objectOrArray, expandedName) {
434
+ var objKind = objectName(objectOrArray);
435
+
436
+ if (objKind !== 'Object' && objKind !== 'Array') {
437
+ return objKind;
438
+ }
439
+
440
+ var str = '';
441
+ var start = -1;
442
+ var length = 0;
443
+
444
+ if (isArray(objectOrArray)) {
445
+ if (jsxChildrenParents.has(objectOrArray)) {
446
+ // Print JSX Children
447
+ var type = jsxChildrenParents.get(objectOrArray);
448
+ str = '<' + describeElementType(type) + '>';
449
+ var array = objectOrArray;
450
+
451
+ for (var i = 0; i < array.length; i++) {
452
+ var value = array[i];
453
+ var substr = void 0;
454
+
455
+ if (typeof value === 'string') {
456
+ substr = value;
457
+ } else if (typeof value === 'object' && value !== null) {
458
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
459
+ substr = '{' + describeObjectForErrorMessage(value) + '}';
460
+ } else {
461
+ substr = '{' + describeValueForErrorMessage(value) + '}';
462
+ }
463
+
464
+ if ('' + i === expandedName) {
465
+ start = str.length;
466
+ length = substr.length;
467
+ str += substr;
468
+ } else if (substr.length < 15 && str.length + substr.length < 40) {
469
+ str += substr;
470
+ } else {
471
+ str += '{...}';
472
+ }
473
+ }
474
+
475
+ str += '</' + describeElementType(type) + '>';
476
+ } else {
477
+ // Print Array
478
+ str = '[';
479
+ var _array = objectOrArray;
480
+
481
+ for (var _i = 0; _i < _array.length; _i++) {
482
+ if (_i > 0) {
483
+ str += ', ';
484
+ }
485
+
486
+ var _value = _array[_i];
487
+
488
+ var _substr = void 0;
489
+
490
+ if (typeof _value === 'object' && _value !== null) {
491
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
492
+ _substr = describeObjectForErrorMessage(_value);
493
+ } else {
494
+ _substr = describeValueForErrorMessage(_value);
495
+ }
496
+
497
+ if ('' + _i === expandedName) {
498
+ start = str.length;
499
+ length = _substr.length;
500
+ str += _substr;
501
+ } else if (_substr.length < 10 && str.length + _substr.length < 40) {
502
+ str += _substr;
503
+ } else {
504
+ str += '...';
505
+ }
506
+ }
507
+
508
+ str += ']';
509
+ }
510
+ } else {
511
+ if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
512
+ str = '<' + describeElementType(objectOrArray.type) + '/>';
513
+ } else if (jsxPropsParents.has(objectOrArray)) {
514
+ // Print JSX
515
+ var _type = jsxPropsParents.get(objectOrArray);
516
+
517
+ str = '<' + (describeElementType(_type) || '...');
518
+ var object = objectOrArray;
519
+ var names = Object.keys(object);
520
+
521
+ for (var _i2 = 0; _i2 < names.length; _i2++) {
522
+ str += ' ';
523
+ var name = names[_i2];
524
+ str += describeKeyForErrorMessage(name) + '=';
525
+ var _value2 = object[name];
526
+
527
+ var _substr2 = void 0;
528
+
529
+ if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
530
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
531
+ _substr2 = describeObjectForErrorMessage(_value2);
532
+ } else {
533
+ _substr2 = describeValueForErrorMessage(_value2);
534
+ }
535
+
536
+ if (typeof _value2 !== 'string') {
537
+ _substr2 = '{' + _substr2 + '}';
538
+ }
539
+
540
+ if (name === expandedName) {
541
+ start = str.length;
542
+ length = _substr2.length;
543
+ str += _substr2;
544
+ } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
545
+ str += _substr2;
546
+ } else {
547
+ str += '...';
548
+ }
549
+ }
550
+
551
+ str += '>';
552
+ } else {
553
+ // Print Object
554
+ str = '{';
555
+ var _object = objectOrArray;
556
+
557
+ var _names = Object.keys(_object);
558
+
559
+ for (var _i3 = 0; _i3 < _names.length; _i3++) {
560
+ if (_i3 > 0) {
561
+ str += ', ';
562
+ }
563
+
564
+ var _name = _names[_i3];
565
+ str += describeKeyForErrorMessage(_name) + ': ';
566
+ var _value3 = _object[_name];
567
+
568
+ var _substr3 = void 0;
569
+
570
+ if (typeof _value3 === 'object' && _value3 !== null) {
571
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
572
+ _substr3 = describeObjectForErrorMessage(_value3);
573
+ } else {
574
+ _substr3 = describeValueForErrorMessage(_value3);
575
+ }
576
+
577
+ if (_name === expandedName) {
578
+ start = str.length;
579
+ length = _substr3.length;
580
+ str += _substr3;
581
+ } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
582
+ str += _substr3;
583
+ } else {
584
+ str += '...';
585
+ }
586
+ }
587
+
588
+ str += '}';
589
+ }
590
+ }
591
+
592
+ if (expandedName === undefined) {
593
+ return str;
594
+ }
595
+
596
+ if (start > -1 && length > 0) {
597
+ var highlight = ' '.repeat(start) + '^'.repeat(length);
598
+ return '\n ' + str + '\n ' + highlight;
599
+ }
600
+
601
+ return '\n ' + str;
602
+ }
603
+
604
+ var knownServerReferences = new WeakMap(); // Serializable values
605
+ // Thenable<ReactServerValue>
606
+ // function serializeByValueID(id: number): string {
607
+ // return '$' + id.toString(16);
608
+ // }
609
+
610
+ function serializePromiseID(id) {
611
+ return '$@' + id.toString(16);
612
+ }
613
+
614
+ function serializeServerReferenceID(id) {
615
+ return '$F' + id.toString(16);
616
+ }
617
+
618
+ function serializeSymbolReference(name) {
619
+ return '$S' + name;
620
+ }
621
+
622
+ function serializeFormDataReference(id) {
623
+ // Why K? F is "Function". D is "Date". What else?
624
+ return '$K' + id.toString(16);
625
+ }
626
+
627
+ function serializeNumber(number) {
628
+ if (Number.isFinite(number)) {
629
+ if (number === 0 && 1 / number === -Infinity) {
630
+ return '$-0';
631
+ } else {
632
+ return number;
633
+ }
634
+ } else {
635
+ if (number === Infinity) {
636
+ return '$Infinity';
637
+ } else if (number === -Infinity) {
638
+ return '$-Infinity';
639
+ } else {
640
+ return '$NaN';
641
+ }
642
+ }
643
+ }
644
+
645
+ function serializeUndefined() {
646
+ return '$undefined';
647
+ }
648
+
649
+ function serializeDateFromDateJSON(dateJSON) {
650
+ // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
651
+ // We need only tack on a $D prefix.
652
+ return '$D' + dateJSON;
653
+ }
654
+
655
+ function serializeBigInt(n) {
656
+ return '$n' + n.toString(10);
657
+ }
658
+
659
+ function escapeStringValue(value) {
660
+ if (value[0] === '$') {
661
+ // We need to escape $ prefixed strings since we use those to encode
662
+ // references to IDs and as special symbol values.
663
+ return '$' + value;
664
+ } else {
665
+ return value;
666
+ }
667
+ }
668
+
669
+ function processReply(root, formFieldPrefix, resolve, reject) {
670
+ var nextPartId = 1;
671
+ var pendingParts = 0;
672
+ var formData = null;
673
+
674
+ function resolveToJSON(key, value) {
675
+ var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
676
+
677
+ {
678
+ // $FlowFixMe[incompatible-use]
679
+ var originalValue = parent[key];
680
+
681
+ if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
682
+ if (objectName(originalValue) !== 'Object') {
683
+ error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
684
+ } else {
685
+ 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));
686
+ }
687
+ }
688
+ }
689
+
690
+ if (value === null) {
691
+ return null;
692
+ }
693
+
694
+ if (typeof value === 'object') {
695
+ // $FlowFixMe[method-unbinding]
696
+ if (typeof value.then === 'function') {
697
+ // We assume that any object with a .then property is a "Thenable" type,
698
+ // or a Promise type. Either of which can be represented by a Promise.
699
+ if (formData === null) {
700
+ // Upgrade to use FormData to allow us to stream this value.
701
+ formData = new FormData();
702
+ }
703
+
704
+ pendingParts++;
705
+ var promiseId = nextPartId++;
706
+ var thenable = value;
707
+ thenable.then(function (partValue) {
708
+ var partJSON = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
709
+
710
+ var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
711
+
712
+ data.append(formFieldPrefix + promiseId, partJSON);
713
+ pendingParts--;
714
+
715
+ if (pendingParts === 0) {
716
+ resolve(data);
717
+ }
718
+ }, function (reason) {
719
+ // In the future we could consider serializing this as an error
720
+ // that throws on the server instead.
721
+ reject(reason);
722
+ });
723
+ return serializePromiseID(promiseId);
724
+ } // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
725
+
726
+
727
+ if (value instanceof FormData) {
728
+ if (formData === null) {
729
+ // Upgrade to use FormData to allow us to use rich objects as its values.
730
+ formData = new FormData();
731
+ }
732
+
733
+ var data = formData;
734
+ var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
735
+ // These must come first in the form order because we assume that all the
736
+ // fields are available before this is referenced.
737
+
738
+ var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
739
+
740
+ value.forEach(function (originalValue, originalKey) {
741
+ data.append(prefix + originalKey, originalValue);
742
+ });
743
+ return serializeFormDataReference(refId);
744
+ }
745
+
746
+ if (!isArray(value)) {
747
+ var iteratorFn = getIteratorFn(value);
748
+
749
+ if (iteratorFn) {
750
+ return Array.from(value);
751
+ }
752
+ }
753
+
754
+ {
755
+ if (value !== null && !isArray(value)) {
756
+ // Verify that this is a simple plain object.
757
+ if (value.$$typeof === REACT_ELEMENT_TYPE) {
758
+ error('React Element cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
759
+ } else if (value.$$typeof === REACT_LAZY_TYPE) {
760
+ error('React Lazy cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
761
+ } else if (value.$$typeof === REACT_PROVIDER_TYPE) {
762
+ error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
763
+ } else if (objectName(value) !== 'Object') {
764
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
765
+ } else if (!isSimpleObject(value)) {
766
+ 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));
767
+ } else if (Object.getOwnPropertySymbols) {
768
+ var symbols = Object.getOwnPropertySymbols(value);
769
+
770
+ if (symbols.length > 0) {
771
+ 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));
772
+ }
773
+ }
774
+ }
775
+ } // $FlowFixMe[incompatible-return]
776
+
777
+
778
+ return value;
779
+ }
780
+
781
+ if (typeof value === 'string') {
782
+ // TODO: Maybe too clever. If we support URL there's no similar trick.
783
+ if (value[value.length - 1] === 'Z') {
784
+ // Possibly a Date, whose toJSON automatically calls toISOString
785
+ // $FlowFixMe[incompatible-use]
786
+ var _originalValue = parent[key]; // $FlowFixMe[method-unbinding]
787
+
788
+ if (_originalValue instanceof Date) {
789
+ return serializeDateFromDateJSON(value);
790
+ }
791
+ }
792
+
793
+ return escapeStringValue(value);
794
+ }
795
+
796
+ if (typeof value === 'boolean') {
797
+ return value;
798
+ }
799
+
800
+ if (typeof value === 'number') {
801
+ return serializeNumber(value);
802
+ }
803
+
804
+ if (typeof value === 'undefined') {
805
+ return serializeUndefined();
806
+ }
807
+
808
+ if (typeof value === 'function') {
809
+ var metaData = knownServerReferences.get(value);
810
+
811
+ if (metaData !== undefined) {
812
+ var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
813
+
814
+ if (formData === null) {
815
+ // Upgrade to use FormData to allow us to stream this value.
816
+ formData = new FormData();
817
+ } // The reference to this function came from the same client so we can pass it back.
818
+
819
+
820
+ var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
821
+
822
+
823
+ formData.set(formFieldPrefix + _refId, metaDataJSON);
824
+ return serializeServerReferenceID(_refId);
825
+ }
826
+
827
+ throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
828
+ }
829
+
830
+ if (typeof value === 'symbol') {
831
+ // $FlowFixMe[incompatible-type] `description` might be undefined
832
+ var name = value.description;
833
+
834
+ if (Symbol.for(name) !== value) {
835
+ 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
836
+ value.description + ") cannot be found among global symbols."));
837
+ }
838
+
839
+ return serializeSymbolReference(name);
840
+ }
841
+
842
+ if (typeof value === 'bigint') {
843
+ return serializeBigInt(value);
844
+ }
845
+
846
+ throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
847
+ } // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
848
+
849
+
850
+ var json = JSON.stringify(root, resolveToJSON);
851
+
852
+ if (formData === null) {
853
+ // If it's a simple data structure, we just use plain JSON.
854
+ resolve(json);
855
+ } else {
856
+ // Otherwise, we use FormData to let us stream in the result.
857
+ formData.set(formFieldPrefix + '0', json);
858
+
859
+ if (pendingParts === 0) {
860
+ // $FlowFixMe[incompatible-call] this has already been refined.
861
+ resolve(formData);
862
+ }
863
+ }
864
+ }
865
+ var boundCache = new WeakMap();
866
+
867
+ function encodeFormData(reference) {
868
+ var resolve, reject; // We need to have a handle on the thenable so that we can synchronously set
869
+ // its status from processReply, when it can complete synchronously.
870
+
871
+ var thenable = new Promise(function (res, rej) {
872
+ resolve = res;
873
+ reject = rej;
874
+ });
875
+ processReply(reference, '', function (body) {
876
+ if (typeof body === 'string') {
877
+ var data = new FormData();
878
+ data.append('0', body);
879
+ body = data;
880
+ }
881
+
882
+ var fulfilled = thenable;
883
+ fulfilled.status = 'fulfilled';
884
+ fulfilled.value = body;
885
+ resolve(body);
886
+ }, function (e) {
887
+ var rejected = thenable;
888
+ rejected.status = 'rejected';
889
+ rejected.reason = e;
890
+ reject(e);
891
+ });
892
+ return thenable;
893
+ }
894
+
895
+ function encodeFormAction(identifierPrefix) {
896
+ var reference = knownServerReferences.get(this);
897
+
898
+ if (!reference) {
899
+ throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
900
+ }
901
+
902
+ var data = null;
903
+ var name;
904
+ var boundPromise = reference.bound;
905
+
906
+ if (boundPromise !== null) {
907
+ var thenable = boundCache.get(reference);
908
+
909
+ if (!thenable) {
910
+ thenable = encodeFormData(reference);
911
+ boundCache.set(reference, thenable);
912
+ }
913
+
914
+ if (thenable.status === 'rejected') {
915
+ throw thenable.reason;
916
+ } else if (thenable.status !== 'fulfilled') {
917
+ throw thenable;
918
+ }
919
+
920
+ var encodedFormData = thenable.value; // This is hacky but we need the identifier prefix to be added to
921
+ // all fields but the suspense cache would break since we might get
922
+ // a new identifier each time. So we just append it at the end instead.
923
+
924
+ var prefixedData = new FormData(); // $FlowFixMe[prop-missing]
925
+
926
+ encodedFormData.forEach(function (value, key) {
927
+ prefixedData.append('$ACTION_' + identifierPrefix + ':' + key, value);
928
+ });
929
+ data = prefixedData; // We encode the name of the prefix containing the data.
930
+
931
+ name = '$ACTION_REF_' + identifierPrefix;
932
+ } else {
933
+ // This is the simple case so we can just encode the ID.
934
+ name = '$ACTION_ID_' + reference.id;
935
+ }
936
+
937
+ return {
938
+ name: name,
939
+ method: 'POST',
940
+ encType: 'multipart/form-data',
941
+ data: data
942
+ };
943
+ }
228
944
 
229
945
  var ContextRegistry = ReactSharedInternals.ContextRegistry;
230
946
  function getOrCreateServerContext(globalName) {
@@ -627,8 +1343,11 @@ function createServerReferenceProxy(response, metaData) {
627
1343
  return Promise.resolve(p).then(function (bound) {
628
1344
  return callServer(metaData.id, bound.concat(args));
629
1345
  });
630
- };
1346
+ }; // Expose encoder for use by SSR.
1347
+ // TODO: Only expose this in SSR builds and not the browser client.
1348
+
631
1349
 
1350
+ proxy.$$FORM_ACTION = encodeFormAction;
632
1351
  knownServerReferences.set(proxy, metaData);
633
1352
  return proxy;
634
1353
  }