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