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