react-server-dom-webpack 18.3.0-next-fa4314841-20230502 → 19.0.0-beta-4508873393-20240430

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 (40) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +1893 -1200
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +931 -0
  3. package/cjs/react-server-dom-webpack-client.edge.development.js +1888 -241
  4. package/cjs/react-server-dom-webpack-client.edge.production.js +1093 -0
  5. package/cjs/react-server-dom-webpack-client.node.development.js +1876 -259
  6. package/cjs/react-server-dom-webpack-client.node.production.js +1070 -0
  7. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1833 -212
  8. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1049 -0
  9. package/cjs/react-server-dom-webpack-node-register.js +59 -10
  10. package/cjs/react-server-dom-webpack-plugin.js +389 -11
  11. package/cjs/react-server-dom-webpack-server.browser.development.js +2187 -937
  12. package/cjs/react-server-dom-webpack-server.browser.production.js +1935 -0
  13. package/cjs/react-server-dom-webpack-server.edge.development.js +2183 -941
  14. package/cjs/react-server-dom-webpack-server.edge.production.js +1956 -0
  15. package/cjs/react-server-dom-webpack-server.node.development.js +2169 -929
  16. package/cjs/react-server-dom-webpack-server.node.production.js +2083 -0
  17. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2116 -881
  18. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +2051 -0
  19. package/client.browser.js +1 -1
  20. package/client.edge.js +1 -1
  21. package/client.node.js +1 -1
  22. package/client.node.unbundled.js +1 -1
  23. package/esm/{react-server-dom-webpack-node-loader.production.min.js → react-server-dom-webpack-node-loader.production.js} +20 -13
  24. package/package.json +8 -15
  25. package/server.browser.js +1 -1
  26. package/server.edge.js +1 -1
  27. package/server.node.js +1 -1
  28. package/server.node.unbundled.js +1 -1
  29. package/cjs/react-server-dom-webpack-client.browser.production.min.js +0 -34
  30. package/cjs/react-server-dom-webpack-client.edge.production.min.js +0 -28
  31. package/cjs/react-server-dom-webpack-client.node.production.min.js +0 -28
  32. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +0 -26
  33. package/cjs/react-server-dom-webpack-server.browser.production.min.js +0 -62
  34. package/cjs/react-server-dom-webpack-server.edge.production.min.js +0 -62
  35. package/cjs/react-server-dom-webpack-server.node.production.min.js +0 -67
  36. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +0 -65
  37. package/umd/react-server-dom-webpack-client.browser.development.js +0 -1731
  38. package/umd/react-server-dom-webpack-client.browser.production.min.js +0 -29
  39. package/umd/react-server-dom-webpack-server.browser.development.js +0 -2904
  40. package/umd/react-server-dom-webpack-server.browser.production.min.js +0 -51
@@ -18,6 +18,9 @@ var util = require('util');
18
18
  var ReactDOM = require('react-dom');
19
19
  var React = require('react');
20
20
 
21
+ // -----------------------------------------------------------------------------
22
+ var enableBinaryFlight = false;
23
+
21
24
  function createStringDecoder() {
22
25
  return new util.TextDecoder();
23
26
  }
@@ -31,14 +34,76 @@ function readFinalStringChunk(decoder, buffer) {
31
34
  return decoder.decode(buffer);
32
35
  }
33
36
 
34
- function parseModel(response, json) {
35
- return JSON.parse(json, response._fromJSON);
37
+ // This flips color using ANSI, then sets a color styling, then resets.
38
+ var badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c '; // Same badge styling as DevTools.
39
+
40
+ var badgeStyle = // We use a fixed background if light-dark is not supported, otherwise
41
+ // we use a transparent background.
42
+ 'background: #e6e6e6;' + 'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' + 'color: #000000;' + 'color: light-dark(#000000, #ffffff);' + 'border-radius: 2px';
43
+ var resetStyle = '';
44
+ var pad = ' ';
45
+ function printToConsole(methodName, args, badgeName) {
46
+ var offset = 0;
47
+
48
+ switch (methodName) {
49
+ case 'dir':
50
+ case 'dirxml':
51
+ case 'groupEnd':
52
+ case 'table':
53
+ {
54
+ // These methods cannot be colorized because they don't take a formatting string.
55
+ // eslint-disable-next-line react-internal/no-production-logging
56
+ console[methodName].apply(console, args);
57
+ return;
58
+ }
59
+
60
+ case 'assert':
61
+ {
62
+ // assert takes formatting options as the second argument.
63
+ offset = 1;
64
+ }
65
+ }
66
+
67
+ var newArgs = args.slice(0);
68
+
69
+ if (typeof newArgs[offset] === 'string') {
70
+ newArgs.splice(offset, 1, badgeFormat + newArgs[offset], badgeStyle, pad + badgeName + pad, resetStyle);
71
+ } else {
72
+ newArgs.splice(offset, 0, badgeFormat, badgeStyle, pad + badgeName + pad, resetStyle);
73
+ } // eslint-disable-next-line react-internal/no-production-logging
74
+
75
+
76
+ console[methodName].apply(console, newArgs);
77
+ return;
36
78
  }
37
79
 
38
- // eslint-disable-next-line no-unused-vars
80
+ // This is the parsed shape of the wire format which is why it is
81
+ // condensed to only the essentialy information
82
+ var ID = 0;
83
+ var CHUNKS = 1;
84
+ var NAME = 2; // export const ASYNC = 3;
85
+ // This logic is correct because currently only include the 4th tuple member
86
+ // when the module is async. If that changes we will need to actually assert
87
+ // the value is true. We don't index into the 4th slot because flow does not
88
+ // like the potential out of bounds access
89
+
90
+ function isAsyncImport(metadata) {
91
+ return metadata.length === 4;
92
+ }
93
+
94
+ // The reason this function needs to defined here in this file instead of just
95
+ // being exported directly from the WebpackDestination... file is because the
96
+ // ClientReferenceMetadata is opaque and we can't unwrap it there.
97
+ // This should get inlined and we could also just implement an unwrapping function
98
+ // though that risks it getting used in places it shouldn't be. This is unfortunate
99
+ // but currently it seems to be the best option we have.
100
+
101
+ function prepareDestinationForModule(moduleLoading, nonce, metadata) {
102
+ prepareDestinationWithChunks(moduleLoading, metadata[CHUNKS], nonce);
103
+ }
39
104
  function resolveClientReference(bundlerConfig, metadata) {
40
- var moduleExports = bundlerConfig[metadata.id];
41
- var resolvedModuleData = moduleExports[metadata.name];
105
+ var moduleExports = bundlerConfig[metadata[ID]];
106
+ var resolvedModuleData = moduleExports[metadata[NAME]];
42
107
  var name;
43
108
 
44
109
  if (resolvedModuleData) {
@@ -49,15 +114,16 @@ function resolveClientReference(bundlerConfig, metadata) {
49
114
  resolvedModuleData = moduleExports['*'];
50
115
 
51
116
  if (!resolvedModuleData) {
52
- 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.');
117
+ 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.');
53
118
  }
54
119
 
55
- name = metadata.name;
120
+ name = metadata[NAME];
56
121
  }
57
122
 
58
123
  return {
59
124
  specifier: resolvedModuleData.specifier,
60
- name: name
125
+ name: name,
126
+ async: isAsyncImport(metadata)
61
127
  };
62
128
  }
63
129
  var asyncModuleCache = new Map();
@@ -73,6 +139,17 @@ function preloadModule(metadata) {
73
139
  } else {
74
140
  // $FlowFixMe[unsupported-syntax]
75
141
  var modulePromise = import(metadata.specifier);
142
+
143
+ if (metadata.async) {
144
+ // If the module is async, it must have been a CJS module.
145
+ // CJS modules are accessed through the default export in
146
+ // Node.js so we have to get the default export to get the
147
+ // full module exports.
148
+ modulePromise = modulePromise.then(function (value) {
149
+ return value.default;
150
+ });
151
+ }
152
+
76
153
  modulePromise.then(function (value) {
77
154
  var fulfilledThenable = modulePromise;
78
155
  fulfilledThenable.status = 'fulfilled';
@@ -113,81 +190,1269 @@ function requireModule(metadata) {
113
190
  return moduleExports[metadata.name];
114
191
  }
115
192
 
116
- var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
193
+ function prepareDestinationWithChunks(moduleLoading, // Chunks are double-indexed [..., idx, filenamex, idy, filenamey, ...]
194
+ chunks, nonce) {
195
+ if (moduleLoading !== null) {
196
+ for (var i = 1; i < chunks.length; i += 2) {
197
+ preinitScriptForSSR(moduleLoading.prefix + chunks[i], nonce, moduleLoading.crossOrigin);
198
+ }
199
+ }
200
+ }
201
+
202
+ var ReactDOMSharedInternals = ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
203
+
204
+ function getCrossOriginString(input) {
205
+ if (typeof input === 'string') {
206
+ return input === 'use-credentials' ? input : '';
207
+ }
208
+
209
+ return undefined;
210
+ }
117
211
 
118
212
  // This client file is in the shared folder because it applies to both SSR and browser contexts.
119
- var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
120
213
  function dispatchHint(code, model) {
121
- var dispatcher = ReactDOMCurrentDispatcher.current;
214
+ var dispatcher = ReactDOMSharedInternals.d;
215
+ /* ReactDOMCurrentDispatcher */
216
+
217
+ switch (code) {
218
+ case 'D':
219
+ {
220
+ var refined = refineModel(code, model);
221
+ var href = refined;
222
+ dispatcher.D(
223
+ /* prefetchDNS */
224
+ href);
225
+ return;
226
+ }
122
227
 
123
- if (dispatcher) {
124
- var href, options;
228
+ case 'C':
229
+ {
230
+ var _refined = refineModel(code, model);
231
+
232
+ if (typeof _refined === 'string') {
233
+ var _href = _refined;
234
+ dispatcher.C(
235
+ /* preconnect */
236
+ _href);
237
+ } else {
238
+ var _href2 = _refined[0];
239
+ var crossOrigin = _refined[1];
240
+ dispatcher.C(
241
+ /* preconnect */
242
+ _href2, crossOrigin);
243
+ }
125
244
 
126
- if (typeof model === 'string') {
127
- href = model;
128
- } else {
129
- href = model[0];
130
- options = model[1];
245
+ return;
246
+ }
247
+
248
+ case 'L':
249
+ {
250
+ var _refined2 = refineModel(code, model);
251
+
252
+ var _href3 = _refined2[0];
253
+ var as = _refined2[1];
254
+
255
+ if (_refined2.length === 3) {
256
+ var options = _refined2[2];
257
+ dispatcher.L(
258
+ /* preload */
259
+ _href3, as, options);
260
+ } else {
261
+ dispatcher.L(
262
+ /* preload */
263
+ _href3, as);
264
+ }
265
+
266
+ return;
267
+ }
268
+
269
+ case 'm':
270
+ {
271
+ var _refined3 = refineModel(code, model);
272
+
273
+ if (typeof _refined3 === 'string') {
274
+ var _href4 = _refined3;
275
+ dispatcher.m(
276
+ /* preloadModule */
277
+ _href4);
278
+ } else {
279
+ var _href5 = _refined3[0];
280
+ var _options = _refined3[1];
281
+ dispatcher.m(
282
+ /* preloadModule */
283
+ _href5, _options);
284
+ }
285
+
286
+ return;
287
+ }
288
+
289
+ case 'X':
290
+ {
291
+ var _refined4 = refineModel(code, model);
292
+
293
+ if (typeof _refined4 === 'string') {
294
+ var _href6 = _refined4;
295
+ dispatcher.X(
296
+ /* preinitScript */
297
+ _href6);
298
+ } else {
299
+ var _href7 = _refined4[0];
300
+ var _options2 = _refined4[1];
301
+ dispatcher.X(
302
+ /* preinitScript */
303
+ _href7, _options2);
304
+ }
305
+
306
+ return;
307
+ }
308
+
309
+ case 'S':
310
+ {
311
+ var _refined5 = refineModel(code, model);
312
+
313
+ if (typeof _refined5 === 'string') {
314
+ var _href8 = _refined5;
315
+ dispatcher.S(
316
+ /* preinitStyle */
317
+ _href8);
318
+ } else {
319
+ var _href9 = _refined5[0];
320
+ var precedence = _refined5[1] === 0 ? undefined : _refined5[1];
321
+
322
+ var _options3 = _refined5.length === 3 ? _refined5[2] : undefined;
323
+
324
+ dispatcher.S(
325
+ /* preinitStyle */
326
+ _href9, precedence, _options3);
327
+ }
328
+
329
+ return;
330
+ }
331
+
332
+ case 'M':
333
+ {
334
+ var _refined6 = refineModel(code, model);
335
+
336
+ if (typeof _refined6 === 'string') {
337
+ var _href10 = _refined6;
338
+ dispatcher.M(
339
+ /* preinitModuleScript */
340
+ _href10);
341
+ } else {
342
+ var _href11 = _refined6[0];
343
+ var _options4 = _refined6[1];
344
+ dispatcher.M(
345
+ /* preinitModuleScript */
346
+ _href11, _options4);
347
+ }
348
+
349
+ return;
350
+ }
351
+ }
352
+ } // Flow is having trouble refining the HintModels so we help it a bit.
353
+ // This should be compiled out in the production build.
354
+
355
+ function refineModel(code, model) {
356
+ return model;
357
+ }
358
+ function preinitScriptForSSR(href, nonce, crossOrigin) {
359
+ ReactDOMSharedInternals.d
360
+ /* ReactDOMCurrentDispatcher */
361
+ .X(
362
+ /* preinitScript */
363
+ href, {
364
+ crossOrigin: getCrossOriginString(crossOrigin),
365
+ nonce: nonce
366
+ });
367
+ }
368
+
369
+ var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
370
+
371
+ function error(format) {
372
+ {
373
+ {
374
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
375
+ args[_key2 - 1] = arguments[_key2];
376
+ }
377
+
378
+ printWarning('error', format, args);
131
379
  }
380
+ }
381
+ }
132
382
 
133
- switch (code) {
134
- case 'D':
135
- {
136
- // $FlowFixMe[prop-missing] options are not refined to their types by code
137
- dispatcher.prefetchDNS(href, options);
138
- return;
383
+ function printWarning(level, format, args) {
384
+ // When changing this logic, you might want to also
385
+ // update consoleWithStackDev.www.js as well.
386
+ {
387
+ var stack = ReactSharedInternals.getStackAddendum();
388
+
389
+ if (stack !== '') {
390
+ format += '%s';
391
+ args = args.concat([stack]);
392
+ } // eslint-disable-next-line react-internal/safe-string-coercion
393
+
394
+
395
+ var argsWithFormat = args.map(function (item) {
396
+ return String(item);
397
+ }); // Careful: RN currently depends on this prefix
398
+
399
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
400
+ // breaks IE9: https://github.com/facebook/react/issues/13610
401
+ // eslint-disable-next-line react-internal/no-production-logging
402
+
403
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
404
+ }
405
+ }
406
+
407
+ var REACT_ELEMENT_TYPE = Symbol.for('react.transitional.element') ;
408
+ var REACT_CONTEXT_TYPE = Symbol.for('react.context');
409
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
410
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
411
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
412
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
413
+ var REACT_LAZY_TYPE = Symbol.for('react.lazy');
414
+ var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
415
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
416
+ function getIteratorFn(maybeIterable) {
417
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
418
+ return null;
419
+ }
420
+
421
+ var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
422
+
423
+ if (typeof maybeIterator === 'function') {
424
+ return maybeIterator;
425
+ }
426
+
427
+ return null;
428
+ }
429
+ var ASYNC_ITERATOR = Symbol.asyncIterator;
430
+
431
+ var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
432
+
433
+ function isArray(a) {
434
+ return isArrayImpl(a);
435
+ }
436
+
437
+ var getPrototypeOf = Object.getPrototypeOf;
438
+
439
+ // in case they error.
440
+
441
+ var jsxPropsParents = new WeakMap();
442
+ var jsxChildrenParents = new WeakMap();
443
+
444
+ function isObjectPrototype(object) {
445
+ if (!object) {
446
+ return false;
447
+ }
448
+
449
+ var ObjectPrototype = Object.prototype;
450
+
451
+ if (object === ObjectPrototype) {
452
+ return true;
453
+ } // It might be an object from a different Realm which is
454
+ // still just a plain simple object.
455
+
456
+
457
+ if (getPrototypeOf(object)) {
458
+ return false;
459
+ }
460
+
461
+ var names = Object.getOwnPropertyNames(object);
462
+
463
+ for (var i = 0; i < names.length; i++) {
464
+ if (!(names[i] in ObjectPrototype)) {
465
+ return false;
466
+ }
467
+ }
468
+
469
+ return true;
470
+ }
471
+
472
+ function isSimpleObject(object) {
473
+ if (!isObjectPrototype(getPrototypeOf(object))) {
474
+ return false;
475
+ }
476
+
477
+ var names = Object.getOwnPropertyNames(object);
478
+
479
+ for (var i = 0; i < names.length; i++) {
480
+ var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
481
+
482
+ if (!descriptor) {
483
+ return false;
484
+ }
485
+
486
+ if (!descriptor.enumerable) {
487
+ if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
488
+ // React adds key and ref getters to props objects to issue warnings.
489
+ // Those getters will not be transferred to the client, but that's ok,
490
+ // so we'll special case them.
491
+ continue;
492
+ }
493
+
494
+ return false;
495
+ }
496
+ }
497
+
498
+ return true;
499
+ }
500
+ function objectName(object) {
501
+ // $FlowFixMe[method-unbinding]
502
+ var name = Object.prototype.toString.call(object);
503
+ return name.replace(/^\[object (.*)\]$/, function (m, p0) {
504
+ return p0;
505
+ });
506
+ }
507
+
508
+ function describeKeyForErrorMessage(key) {
509
+ var encodedKey = JSON.stringify(key);
510
+ return '"' + key + '"' === encodedKey ? key : encodedKey;
511
+ }
512
+
513
+ function describeValueForErrorMessage(value) {
514
+ switch (typeof value) {
515
+ case 'string':
516
+ {
517
+ return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
518
+ }
519
+
520
+ case 'object':
521
+ {
522
+ if (isArray(value)) {
523
+ return '[...]';
139
524
  }
140
525
 
141
- case 'C':
526
+ if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
527
+ return describeClientReference();
528
+ }
529
+
530
+ var name = objectName(value);
531
+
532
+ if (name === 'Object') {
533
+ return '{...}';
534
+ }
535
+
536
+ return name;
537
+ }
538
+
539
+ case 'function':
540
+ {
541
+ if (value.$$typeof === CLIENT_REFERENCE_TAG) {
542
+ return describeClientReference();
543
+ }
544
+
545
+ var _name = value.displayName || value.name;
546
+
547
+ return _name ? 'function ' + _name : 'function';
548
+ }
549
+
550
+ default:
551
+ // eslint-disable-next-line react-internal/safe-string-coercion
552
+ return String(value);
553
+ }
554
+ }
555
+
556
+ function describeElementType(type) {
557
+ if (typeof type === 'string') {
558
+ return type;
559
+ }
560
+
561
+ switch (type) {
562
+ case REACT_SUSPENSE_TYPE:
563
+ return 'Suspense';
564
+
565
+ case REACT_SUSPENSE_LIST_TYPE:
566
+ return 'SuspenseList';
567
+ }
568
+
569
+ if (typeof type === 'object') {
570
+ switch (type.$$typeof) {
571
+ case REACT_FORWARD_REF_TYPE:
572
+ return describeElementType(type.render);
573
+
574
+ case REACT_MEMO_TYPE:
575
+ return describeElementType(type.type);
576
+
577
+ case REACT_LAZY_TYPE:
142
578
  {
143
- // $FlowFixMe[prop-missing] options are not refined to their types by code
144
- dispatcher.preconnect(href, options);
145
- return;
579
+ var lazyComponent = type;
580
+ var payload = lazyComponent._payload;
581
+ var init = lazyComponent._init;
582
+
583
+ try {
584
+ // Lazy may contain any component type so we recursively resolve it.
585
+ return describeElementType(init(payload));
586
+ } catch (x) {}
587
+ }
588
+ }
589
+ }
590
+
591
+ return '';
592
+ }
593
+
594
+ var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
595
+
596
+ function describeClientReference(ref) {
597
+ return 'client';
598
+ }
599
+
600
+ function describeObjectForErrorMessage(objectOrArray, expandedName) {
601
+ var objKind = objectName(objectOrArray);
602
+
603
+ if (objKind !== 'Object' && objKind !== 'Array') {
604
+ return objKind;
605
+ }
606
+
607
+ var str = '';
608
+ var start = -1;
609
+ var length = 0;
610
+
611
+ if (isArray(objectOrArray)) {
612
+ if (jsxChildrenParents.has(objectOrArray)) {
613
+ // Print JSX Children
614
+ var type = jsxChildrenParents.get(objectOrArray);
615
+ str = '<' + describeElementType(type) + '>';
616
+ var array = objectOrArray;
617
+
618
+ for (var i = 0; i < array.length; i++) {
619
+ var value = array[i];
620
+ var substr = void 0;
621
+
622
+ if (typeof value === 'string') {
623
+ substr = value;
624
+ } else if (typeof value === 'object' && value !== null) {
625
+ substr = '{' + describeObjectForErrorMessage(value) + '}';
626
+ } else {
627
+ substr = '{' + describeValueForErrorMessage(value) + '}';
628
+ }
629
+
630
+ if ('' + i === expandedName) {
631
+ start = str.length;
632
+ length = substr.length;
633
+ str += substr;
634
+ } else if (substr.length < 15 && str.length + substr.length < 40) {
635
+ str += substr;
636
+ } else {
637
+ str += '{...}';
638
+ }
639
+ }
640
+
641
+ str += '</' + describeElementType(type) + '>';
642
+ } else {
643
+ // Print Array
644
+ str = '[';
645
+ var _array = objectOrArray;
646
+
647
+ for (var _i = 0; _i < _array.length; _i++) {
648
+ if (_i > 0) {
649
+ str += ', ';
650
+ }
651
+
652
+ var _value = _array[_i];
653
+
654
+ var _substr = void 0;
655
+
656
+ if (typeof _value === 'object' && _value !== null) {
657
+ _substr = describeObjectForErrorMessage(_value);
658
+ } else {
659
+ _substr = describeValueForErrorMessage(_value);
660
+ }
661
+
662
+ if ('' + _i === expandedName) {
663
+ start = str.length;
664
+ length = _substr.length;
665
+ str += _substr;
666
+ } else if (_substr.length < 10 && str.length + _substr.length < 40) {
667
+ str += _substr;
668
+ } else {
669
+ str += '...';
670
+ }
671
+ }
672
+
673
+ str += ']';
674
+ }
675
+ } else {
676
+ if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
677
+ str = '<' + describeElementType(objectOrArray.type) + '/>';
678
+ } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
679
+ return describeClientReference();
680
+ } else if (jsxPropsParents.has(objectOrArray)) {
681
+ // Print JSX
682
+ var _type = jsxPropsParents.get(objectOrArray);
683
+
684
+ str = '<' + (describeElementType(_type) || '...');
685
+ var object = objectOrArray;
686
+ var names = Object.keys(object);
687
+
688
+ for (var _i2 = 0; _i2 < names.length; _i2++) {
689
+ str += ' ';
690
+ var name = names[_i2];
691
+ str += describeKeyForErrorMessage(name) + '=';
692
+ var _value2 = object[name];
693
+
694
+ var _substr2 = void 0;
695
+
696
+ if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
697
+ _substr2 = describeObjectForErrorMessage(_value2);
698
+ } else {
699
+ _substr2 = describeValueForErrorMessage(_value2);
700
+ }
701
+
702
+ if (typeof _value2 !== 'string') {
703
+ _substr2 = '{' + _substr2 + '}';
704
+ }
705
+
706
+ if (name === expandedName) {
707
+ start = str.length;
708
+ length = _substr2.length;
709
+ str += _substr2;
710
+ } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
711
+ str += _substr2;
712
+ } else {
713
+ str += '...';
714
+ }
715
+ }
716
+
717
+ str += '>';
718
+ } else {
719
+ // Print Object
720
+ str = '{';
721
+ var _object = objectOrArray;
722
+
723
+ var _names = Object.keys(_object);
724
+
725
+ for (var _i3 = 0; _i3 < _names.length; _i3++) {
726
+ if (_i3 > 0) {
727
+ str += ', ';
728
+ }
729
+
730
+ var _name2 = _names[_i3];
731
+ str += describeKeyForErrorMessage(_name2) + ': ';
732
+ var _value3 = _object[_name2];
733
+
734
+ var _substr3 = void 0;
735
+
736
+ if (typeof _value3 === 'object' && _value3 !== null) {
737
+ _substr3 = describeObjectForErrorMessage(_value3);
738
+ } else {
739
+ _substr3 = describeValueForErrorMessage(_value3);
740
+ }
741
+
742
+ if (_name2 === expandedName) {
743
+ start = str.length;
744
+ length = _substr3.length;
745
+ str += _substr3;
746
+ } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
747
+ str += _substr3;
748
+ } else {
749
+ str += '...';
750
+ }
751
+ }
752
+
753
+ str += '}';
754
+ }
755
+ }
756
+
757
+ if (expandedName === undefined) {
758
+ return str;
759
+ }
760
+
761
+ if (start > -1 && length > 0) {
762
+ var highlight = ' '.repeat(start) + '^'.repeat(length);
763
+ return '\n ' + str + '\n ' + highlight;
764
+ }
765
+
766
+ return '\n ' + str;
767
+ }
768
+
769
+ function writeTemporaryReference(set, object) {
770
+ // We always create a new entry regardless if we've already written the same
771
+ // object. This ensures that we always generate a deterministic encoding of
772
+ // each slot in the reply for cacheability.
773
+ var newId = set.length;
774
+ set.push(object);
775
+ return newId;
776
+ }
777
+ function readTemporaryReference(set, id) {
778
+ if (id < 0 || id >= set.length) {
779
+ throw new Error("The RSC response contained a reference that doesn't exist in the temporary reference set. " + 'Always pass the matching set that was used to create the reply when parsing its response.');
780
+ }
781
+
782
+ return set[id];
783
+ }
784
+
785
+ var ObjectPrototype = Object.prototype;
786
+ var knownServerReferences = new WeakMap(); // Serializable values
787
+ // Thenable<ReactServerValue>
788
+
789
+ function serializeByValueID(id) {
790
+ return '$' + id.toString(16);
791
+ }
792
+
793
+ function serializePromiseID(id) {
794
+ return '$@' + id.toString(16);
795
+ }
796
+
797
+ function serializeServerReferenceID(id) {
798
+ return '$F' + id.toString(16);
799
+ }
800
+
801
+ function serializeTemporaryReferenceID(id) {
802
+ return '$T' + id.toString(16);
803
+ }
804
+
805
+ function serializeFormDataReference(id) {
806
+ // Why K? F is "Function". D is "Date". What else?
807
+ return '$K' + id.toString(16);
808
+ }
809
+
810
+ function serializeNumber(number) {
811
+ if (Number.isFinite(number)) {
812
+ if (number === 0 && 1 / number === -Infinity) {
813
+ return '$-0';
814
+ } else {
815
+ return number;
816
+ }
817
+ } else {
818
+ if (number === Infinity) {
819
+ return '$Infinity';
820
+ } else if (number === -Infinity) {
821
+ return '$-Infinity';
822
+ } else {
823
+ return '$NaN';
824
+ }
825
+ }
826
+ }
827
+
828
+ function serializeUndefined() {
829
+ return '$undefined';
830
+ }
831
+
832
+ function serializeDateFromDateJSON(dateJSON) {
833
+ // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
834
+ // We need only tack on a $D prefix.
835
+ return '$D' + dateJSON;
836
+ }
837
+
838
+ function serializeBigInt(n) {
839
+ return '$n' + n.toString(10);
840
+ }
841
+
842
+ function serializeMapID(id) {
843
+ return '$Q' + id.toString(16);
844
+ }
845
+
846
+ function serializeSetID(id) {
847
+ return '$W' + id.toString(16);
848
+ }
849
+
850
+ function serializeIteratorID(id) {
851
+ return '$i' + id.toString(16);
852
+ }
853
+
854
+ function escapeStringValue(value) {
855
+ if (value[0] === '$') {
856
+ // We need to escape $ prefixed strings since we use those to encode
857
+ // references to IDs and as special symbol values.
858
+ return '$' + value;
859
+ } else {
860
+ return value;
861
+ }
862
+ }
863
+
864
+ function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
865
+ var nextPartId = 1;
866
+ var pendingParts = 0;
867
+ var formData = null;
868
+
869
+ function resolveToJSON(key, value) {
870
+ var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
871
+
872
+ {
873
+ // $FlowFixMe[incompatible-use]
874
+ var originalValue = parent[key];
875
+
876
+ if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
877
+ if (objectName(originalValue) !== 'Object') {
878
+ error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
879
+ } else {
880
+ 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));
881
+ }
882
+ }
883
+ }
884
+
885
+ if (value === null) {
886
+ return null;
887
+ }
888
+
889
+ if (typeof value === 'object') {
890
+ switch (value.$$typeof) {
891
+ case REACT_ELEMENT_TYPE:
892
+ {
893
+ if (temporaryReferences === undefined) {
894
+ throw new Error('React Element cannot be passed to Server Functions from the Client without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
895
+ }
896
+
897
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
898
+ }
899
+
900
+ case REACT_LAZY_TYPE:
901
+ {
902
+ // Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
903
+ var lazy = value;
904
+ var payload = lazy._payload;
905
+ var init = lazy._init;
906
+
907
+ if (formData === null) {
908
+ // Upgrade to use FormData to allow us to stream this value.
909
+ formData = new FormData();
910
+ }
911
+
912
+ pendingParts++;
913
+
914
+ try {
915
+ var resolvedModel = init(payload); // We always outline this as a separate part even though we could inline it
916
+ // because it ensures a more deterministic encoding.
917
+
918
+ var lazyId = nextPartId++;
919
+ var partJSON = JSON.stringify(resolvedModel, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
920
+
921
+ var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
922
+
923
+ data.append(formFieldPrefix + lazyId, partJSON);
924
+ return serializeByValueID(lazyId);
925
+ } catch (x) {
926
+ if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
927
+ // Suspended
928
+ pendingParts++;
929
+
930
+ var _lazyId = nextPartId++;
931
+
932
+ var thenable = x;
933
+
934
+ var retry = function () {
935
+ // While the first promise resolved, its value isn't necessarily what we'll
936
+ // resolve into because we might suspend again.
937
+ try {
938
+ var _partJSON = JSON.stringify(value, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
939
+
940
+
941
+ var _data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
942
+
943
+ _data.append(formFieldPrefix + _lazyId, _partJSON);
944
+
945
+ pendingParts--;
946
+
947
+ if (pendingParts === 0) {
948
+ resolve(_data);
949
+ }
950
+ } catch (reason) {
951
+ reject(reason);
952
+ }
953
+ };
954
+
955
+ thenable.then(retry, retry);
956
+ return serializeByValueID(_lazyId);
957
+ } else {
958
+ // In the future we could consider serializing this as an error
959
+ // that throws on the server instead.
960
+ reject(x);
961
+ return null;
962
+ }
963
+ } finally {
964
+ pendingParts--;
965
+ }
966
+ }
967
+ } // $FlowFixMe[method-unbinding]
968
+
969
+
970
+ if (typeof value.then === 'function') {
971
+ // We assume that any object with a .then property is a "Thenable" type,
972
+ // or a Promise type. Either of which can be represented by a Promise.
973
+ if (formData === null) {
974
+ // Upgrade to use FormData to allow us to stream this value.
975
+ formData = new FormData();
976
+ }
977
+
978
+ pendingParts++;
979
+ var promiseId = nextPartId++;
980
+ var _thenable = value;
981
+
982
+ _thenable.then(function (partValue) {
983
+ try {
984
+ var _partJSON2 = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
985
+
986
+
987
+ var _data2 = formData; // eslint-disable-next-line react-internal/safe-string-coercion
988
+
989
+ _data2.append(formFieldPrefix + promiseId, _partJSON2);
990
+
991
+ pendingParts--;
992
+
993
+ if (pendingParts === 0) {
994
+ resolve(_data2);
995
+ }
996
+ } catch (reason) {
997
+ reject(reason);
998
+ }
999
+ }, function (reason) {
1000
+ // In the future we could consider serializing this as an error
1001
+ // that throws on the server instead.
1002
+ reject(reason);
1003
+ });
1004
+
1005
+ return serializePromiseID(promiseId);
1006
+ }
1007
+
1008
+ if (isArray(value)) {
1009
+ // $FlowFixMe[incompatible-return]
1010
+ return value;
1011
+ } // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
1012
+
1013
+
1014
+ if (value instanceof FormData) {
1015
+ if (formData === null) {
1016
+ // Upgrade to use FormData to allow us to use rich objects as its values.
1017
+ formData = new FormData();
1018
+ }
1019
+
1020
+ var _data3 = formData;
1021
+ var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
1022
+ // These must come first in the form order because we assume that all the
1023
+ // fields are available before this is referenced.
1024
+
1025
+ var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
1026
+
1027
+ value.forEach(function (originalValue, originalKey) {
1028
+ _data3.append(prefix + originalKey, originalValue);
1029
+ });
1030
+ return serializeFormDataReference(refId);
1031
+ }
1032
+
1033
+ if (value instanceof Map) {
1034
+ var _partJSON3 = JSON.stringify(Array.from(value), resolveToJSON);
1035
+
1036
+ if (formData === null) {
1037
+ formData = new FormData();
1038
+ }
1039
+
1040
+ var mapId = nextPartId++;
1041
+ formData.append(formFieldPrefix + mapId, _partJSON3);
1042
+ return serializeMapID(mapId);
1043
+ }
1044
+
1045
+ if (value instanceof Set) {
1046
+ var _partJSON4 = JSON.stringify(Array.from(value), resolveToJSON);
1047
+
1048
+ if (formData === null) {
1049
+ formData = new FormData();
1050
+ }
1051
+
1052
+ var setId = nextPartId++;
1053
+ formData.append(formFieldPrefix + setId, _partJSON4);
1054
+ return serializeSetID(setId);
1055
+ }
1056
+
1057
+ var iteratorFn = getIteratorFn(value);
1058
+
1059
+ if (iteratorFn) {
1060
+ var iterator = iteratorFn.call(value);
1061
+
1062
+ if (iterator === value) {
1063
+ // Iterator, not Iterable
1064
+ var _partJSON5 = JSON.stringify(Array.from(iterator), resolveToJSON);
1065
+
1066
+ if (formData === null) {
1067
+ formData = new FormData();
1068
+ }
1069
+
1070
+ var iteratorId = nextPartId++;
1071
+ formData.append(formFieldPrefix + iteratorId, _partJSON5);
1072
+ return serializeIteratorID(iteratorId);
1073
+ }
1074
+
1075
+ return Array.from(iterator);
1076
+ } // Verify that this is a simple plain object.
1077
+
1078
+
1079
+ var proto = getPrototypeOf(value);
1080
+
1081
+ if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
1082
+ if (temporaryReferences === undefined) {
1083
+ throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
1084
+ } // We can serialize class instances as temporary references.
1085
+
1086
+
1087
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1088
+ }
1089
+
1090
+ {
1091
+ if (value.$$typeof === (REACT_CONTEXT_TYPE )) {
1092
+ error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
1093
+ } else if (objectName(value) !== 'Object') {
1094
+ error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
1095
+ } else if (!isSimpleObject(value)) {
1096
+ error('Only plain objects can be passed to Server Functions from the Client. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
1097
+ } else if (Object.getOwnPropertySymbols) {
1098
+ var symbols = Object.getOwnPropertySymbols(value);
1099
+
1100
+ if (symbols.length > 0) {
1101
+ error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
1102
+ }
146
1103
  }
1104
+ } // $FlowFixMe[incompatible-return]
1105
+
1106
+
1107
+ return value;
1108
+ }
1109
+
1110
+ if (typeof value === 'string') {
1111
+ // TODO: Maybe too clever. If we support URL there's no similar trick.
1112
+ if (value[value.length - 1] === 'Z') {
1113
+ // Possibly a Date, whose toJSON automatically calls toISOString
1114
+ // $FlowFixMe[incompatible-use]
1115
+ var _originalValue = parent[key];
1116
+
1117
+ if (_originalValue instanceof Date) {
1118
+ return serializeDateFromDateJSON(value);
1119
+ }
1120
+ }
1121
+
1122
+ return escapeStringValue(value);
1123
+ }
1124
+
1125
+ if (typeof value === 'boolean') {
1126
+ return value;
1127
+ }
1128
+
1129
+ if (typeof value === 'number') {
1130
+ return serializeNumber(value);
1131
+ }
1132
+
1133
+ if (typeof value === 'undefined') {
1134
+ return serializeUndefined();
1135
+ }
1136
+
1137
+ if (typeof value === 'function') {
1138
+ var metaData = knownServerReferences.get(value);
1139
+
1140
+ if (metaData !== undefined) {
1141
+ var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
1142
+
1143
+ if (formData === null) {
1144
+ // Upgrade to use FormData to allow us to stream this value.
1145
+ formData = new FormData();
1146
+ } // The reference to this function came from the same client so we can pass it back.
1147
+
1148
+
1149
+ var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
1150
+
1151
+
1152
+ formData.set(formFieldPrefix + _refId, metaDataJSON);
1153
+ return serializeServerReferenceID(_refId);
1154
+ }
1155
+
1156
+ if (temporaryReferences === undefined) {
1157
+ throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
1158
+ }
1159
+
1160
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1161
+ }
1162
+
1163
+ if (typeof value === 'symbol') {
1164
+ if (temporaryReferences === undefined) {
1165
+ throw new Error('Symbols cannot be passed to a Server Function without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
1166
+ }
1167
+
1168
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1169
+ }
1170
+
1171
+ if (typeof value === 'bigint') {
1172
+ return serializeBigInt(value);
1173
+ }
1174
+
1175
+ throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
1176
+ } // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
1177
+
1178
+
1179
+ var json = JSON.stringify(root, resolveToJSON);
1180
+
1181
+ if (formData === null) {
1182
+ // If it's a simple data structure, we just use plain JSON.
1183
+ resolve(json);
1184
+ } else {
1185
+ // Otherwise, we use FormData to let us stream in the result.
1186
+ formData.set(formFieldPrefix + '0', json);
1187
+
1188
+ if (pendingParts === 0) {
1189
+ // $FlowFixMe[incompatible-call] this has already been refined.
1190
+ resolve(formData);
1191
+ }
1192
+ }
1193
+ }
1194
+ var boundCache = new WeakMap();
1195
+
1196
+ function encodeFormData(reference) {
1197
+ var resolve, reject; // We need to have a handle on the thenable so that we can synchronously set
1198
+ // its status from processReply, when it can complete synchronously.
1199
+
1200
+ var thenable = new Promise(function (res, rej) {
1201
+ resolve = res;
1202
+ reject = rej;
1203
+ });
1204
+ processReply(reference, '', undefined, // TODO: This means React Elements can't be used as state in progressive enhancement.
1205
+ function (body) {
1206
+ if (typeof body === 'string') {
1207
+ var data = new FormData();
1208
+ data.append('0', body);
1209
+ body = data;
1210
+ }
1211
+
1212
+ var fulfilled = thenable;
1213
+ fulfilled.status = 'fulfilled';
1214
+ fulfilled.value = body;
1215
+ resolve(body);
1216
+ }, function (e) {
1217
+ var rejected = thenable;
1218
+ rejected.status = 'rejected';
1219
+ rejected.reason = e;
1220
+ reject(e);
1221
+ });
1222
+ return thenable;
1223
+ }
1224
+
1225
+ function defaultEncodeFormAction(identifierPrefix) {
1226
+ var reference = knownServerReferences.get(this);
1227
+
1228
+ if (!reference) {
1229
+ throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
1230
+ }
1231
+
1232
+ var data = null;
1233
+ var name;
1234
+ var boundPromise = reference.bound;
1235
+
1236
+ if (boundPromise !== null) {
1237
+ var thenable = boundCache.get(reference);
1238
+
1239
+ if (!thenable) {
1240
+ thenable = encodeFormData(reference);
1241
+ boundCache.set(reference, thenable);
1242
+ }
1243
+
1244
+ if (thenable.status === 'rejected') {
1245
+ throw thenable.reason;
1246
+ } else if (thenable.status !== 'fulfilled') {
1247
+ throw thenable;
1248
+ }
1249
+
1250
+ var encodedFormData = thenable.value; // This is hacky but we need the identifier prefix to be added to
1251
+ // all fields but the suspense cache would break since we might get
1252
+ // a new identifier each time. So we just append it at the end instead.
1253
+
1254
+ var prefixedData = new FormData(); // $FlowFixMe[prop-missing]
1255
+
1256
+ encodedFormData.forEach(function (value, key) {
1257
+ prefixedData.append('$ACTION_' + identifierPrefix + ':' + key, value);
1258
+ });
1259
+ data = prefixedData; // We encode the name of the prefix containing the data.
1260
+
1261
+ name = '$ACTION_REF_' + identifierPrefix;
1262
+ } else {
1263
+ // This is the simple case so we can just encode the ID.
1264
+ name = '$ACTION_ID_' + reference.id;
1265
+ }
1266
+
1267
+ return {
1268
+ name: name,
1269
+ method: 'POST',
1270
+ encType: 'multipart/form-data',
1271
+ data: data
1272
+ };
1273
+ }
1274
+
1275
+ function customEncodeFormAction(proxy, identifierPrefix, encodeFormAction) {
1276
+ var reference = knownServerReferences.get(proxy);
1277
+
1278
+ if (!reference) {
1279
+ throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
1280
+ }
1281
+
1282
+ var boundPromise = reference.bound;
1283
+
1284
+ if (boundPromise === null) {
1285
+ boundPromise = Promise.resolve([]);
1286
+ }
1287
+
1288
+ return encodeFormAction(reference.id, boundPromise);
1289
+ }
1290
+
1291
+ function isSignatureEqual(referenceId, numberOfBoundArgs) {
1292
+ var reference = knownServerReferences.get(this);
1293
+
1294
+ if (!reference) {
1295
+ throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
1296
+ }
1297
+
1298
+ if (reference.id !== referenceId) {
1299
+ // These are different functions.
1300
+ return false;
1301
+ } // Now check if the number of bound arguments is the same.
1302
+
1303
+
1304
+ var boundPromise = reference.bound;
1305
+
1306
+ if (boundPromise === null) {
1307
+ // No bound arguments.
1308
+ return numberOfBoundArgs === 0;
1309
+ } // Unwrap the bound arguments array by suspending, if necessary. As with
1310
+ // encodeFormData, this means isSignatureEqual can only be called while React
1311
+ // is rendering.
1312
+
1313
+
1314
+ switch (boundPromise.status) {
1315
+ case 'fulfilled':
1316
+ {
1317
+ var boundArgs = boundPromise.value;
1318
+ return boundArgs.length === numberOfBoundArgs;
1319
+ }
1320
+
1321
+ case 'pending':
1322
+ {
1323
+ throw boundPromise;
1324
+ }
1325
+
1326
+ case 'rejected':
1327
+ {
1328
+ throw boundPromise.reason;
1329
+ }
1330
+
1331
+ default:
1332
+ {
1333
+ if (typeof boundPromise.status === 'string') ; else {
1334
+ var pendingThenable = boundPromise;
1335
+ pendingThenable.status = 'pending';
1336
+ pendingThenable.then(function (boundArgs) {
1337
+ var fulfilledThenable = boundPromise;
1338
+ fulfilledThenable.status = 'fulfilled';
1339
+ fulfilledThenable.value = boundArgs;
1340
+ }, function (error) {
1341
+ var rejectedThenable = boundPromise;
1342
+ rejectedThenable.status = 'rejected';
1343
+ rejectedThenable.reason = error;
1344
+ });
1345
+ }
1346
+
1347
+ throw boundPromise;
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ function registerServerReference(proxy, reference, encodeFormAction) {
1353
+ // Expose encoder for use by SSR, as well as a special bind that can be used to
1354
+ // keep server capabilities.
1355
+ {
1356
+ // Only expose this in builds that would actually use it. Not needed on the client.
1357
+ var $$FORM_ACTION = encodeFormAction === undefined ? defaultEncodeFormAction : function (identifierPrefix) {
1358
+ return customEncodeFormAction(this, identifierPrefix, encodeFormAction);
1359
+ };
1360
+ Object.defineProperties(proxy, {
1361
+ $$FORM_ACTION: {
1362
+ value: $$FORM_ACTION
1363
+ },
1364
+ $$IS_SIGNATURE_EQUAL: {
1365
+ value: isSignatureEqual
1366
+ },
1367
+ bind: {
1368
+ value: bind
1369
+ }
1370
+ });
1371
+ }
1372
+
1373
+ knownServerReferences.set(proxy, reference);
1374
+ } // $FlowFixMe[method-unbinding]
1375
+
1376
+ var FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
1377
+
1378
+ var ArraySlice = Array.prototype.slice;
1379
+
1380
+ function bind() {
1381
+ // $FlowFixMe[unsupported-syntax]
1382
+ var newFn = FunctionBind.apply(this, arguments);
1383
+ var reference = knownServerReferences.get(this);
1384
+
1385
+ if (reference) {
1386
+ {
1387
+ var thisBind = arguments[0];
147
1388
 
148
- case 'L':
149
- {
150
- // $FlowFixMe[prop-missing] options are not refined to their types by code
151
- // $FlowFixMe[incompatible-call] options are not refined to their types by code
152
- dispatcher.preload(href, options);
153
- return;
154
- }
1389
+ if (thisBind != null) {
1390
+ // This doesn't warn in browser environments since it's not instrumented outside
1391
+ // usedWithSSR. This makes this an SSR only warning which we don't generally do.
1392
+ // TODO: Consider a DEV only instrumentation in the browser.
1393
+ error('Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().');
1394
+ }
1395
+ }
155
1396
 
156
- case 'I':
157
- {
158
- // $FlowFixMe[prop-missing] options are not refined to their types by code
159
- // $FlowFixMe[incompatible-call] options are not refined to their types by code
160
- dispatcher.preinit(href, options);
161
- return;
1397
+ var args = ArraySlice.call(arguments, 1);
1398
+ var boundPromise = null;
1399
+
1400
+ if (reference.bound !== null) {
1401
+ boundPromise = Promise.resolve(reference.bound).then(function (boundArgs) {
1402
+ return boundArgs.concat(args);
1403
+ });
1404
+ } else {
1405
+ boundPromise = Promise.resolve(args);
1406
+ } // Expose encoder for use by SSR, as well as a special bind that can be used to
1407
+ // keep server capabilities.
1408
+
1409
+
1410
+ {
1411
+ // Only expose this in builds that would actually use it. Not needed on the client.
1412
+ Object.defineProperties(newFn, {
1413
+ $$FORM_ACTION: {
1414
+ value: this.$$FORM_ACTION
1415
+ },
1416
+ $$IS_SIGNATURE_EQUAL: {
1417
+ value: isSignatureEqual
1418
+ },
1419
+ bind: {
1420
+ value: bind
162
1421
  }
1422
+ });
163
1423
  }
164
- }
165
- }
166
-
167
- var knownServerReferences = new WeakMap();
168
1424
 
169
- // ATTENTION
170
- // When adding new symbols to this file,
171
- // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
172
- // The Symbol used to tag the ReactElement-like types.
173
- var REACT_ELEMENT_TYPE = Symbol.for('react.element');
174
- var REACT_LAZY_TYPE = Symbol.for('react.lazy');
175
- var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
1425
+ knownServerReferences.set(newFn, {
1426
+ id: reference.id,
1427
+ bound: boundPromise
1428
+ });
1429
+ }
176
1430
 
177
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1431
+ return newFn;
1432
+ }
178
1433
 
179
- var ContextRegistry = ReactSharedInternals.ContextRegistry;
180
- function getOrCreateServerContext(globalName) {
181
- if (!ContextRegistry[globalName]) {
182
- ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
183
- REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
184
- }
1434
+ function createServerReference$1(id, callServer, encodeFormAction) {
1435
+ var proxy = function () {
1436
+ // $FlowFixMe[method-unbinding]
1437
+ var args = Array.prototype.slice.call(arguments);
1438
+ return callServer(id, args);
1439
+ };
185
1440
 
186
- return ContextRegistry[globalName];
1441
+ registerServerReference(proxy, {
1442
+ id: id,
1443
+ bound: null
1444
+ }, encodeFormAction);
1445
+ return proxy;
187
1446
  }
188
1447
 
1448
+ var ROW_ID = 0;
1449
+ var ROW_TAG = 1;
1450
+ var ROW_LENGTH = 2;
1451
+ var ROW_CHUNK_BY_NEWLINE = 3;
1452
+ var ROW_CHUNK_BY_LENGTH = 4;
189
1453
  var PENDING = 'pending';
190
1454
  var BLOCKED = 'blocked';
1455
+ var CYCLIC = 'cyclic';
191
1456
  var RESOLVED_MODEL = 'resolved_model';
192
1457
  var RESOLVED_MODULE = 'resolved_module';
193
1458
  var INITIALIZED = 'fulfilled';
@@ -198,6 +1463,10 @@ function Chunk(status, value, reason, response) {
198
1463
  this.value = value;
199
1464
  this.reason = reason;
200
1465
  this._response = response;
1466
+
1467
+ {
1468
+ this._debugInfo = null;
1469
+ }
201
1470
  } // We subclass Promise.prototype so that we get other methods like .catch
202
1471
 
203
1472
 
@@ -225,6 +1494,7 @@ Chunk.prototype.then = function (resolve, reject) {
225
1494
 
226
1495
  case PENDING:
227
1496
  case BLOCKED:
1497
+ case CYCLIC:
228
1498
  if (resolve) {
229
1499
  if (chunk.value === null) {
230
1500
  chunk.value = [];
@@ -244,7 +1514,10 @@ Chunk.prototype.then = function (resolve, reject) {
244
1514
  break;
245
1515
 
246
1516
  default:
247
- reject(chunk.reason);
1517
+ if (reject) {
1518
+ reject(chunk.reason);
1519
+ }
1520
+
248
1521
  break;
249
1522
  }
250
1523
  };
@@ -269,6 +1542,7 @@ function readChunk(chunk) {
269
1542
 
270
1543
  case PENDING:
271
1544
  case BLOCKED:
1545
+ case CYCLIC:
272
1546
  // eslint-disable-next-line no-throw-literal
273
1547
  throw chunk;
274
1548
 
@@ -312,6 +1586,7 @@ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
312
1586
 
313
1587
  case PENDING:
314
1588
  case BLOCKED:
1589
+ case CYCLIC:
315
1590
  chunk.value = resolveListeners;
316
1591
  chunk.reason = rejectListeners;
317
1592
  break;
@@ -327,7 +1602,7 @@ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
327
1602
 
328
1603
  function triggerErrorOnChunk(chunk, error) {
329
1604
  if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
330
- // We already resolved. We didn't expect to see this.
1605
+
331
1606
  return;
332
1607
  }
333
1608
 
@@ -351,9 +1626,14 @@ function createResolvedModuleChunk(response, value) {
351
1626
  return new Chunk(RESOLVED_MODULE, value, null, response);
352
1627
  }
353
1628
 
1629
+ function createInitializedTextChunk(response, value) {
1630
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1631
+ return new Chunk(INITIALIZED, value, null, response);
1632
+ }
1633
+
354
1634
  function resolveModelChunk(chunk, value) {
355
1635
  if (chunk.status !== PENDING) {
356
- // We already resolved. We didn't expect to see this.
1636
+
357
1637
  return;
358
1638
  }
359
1639
 
@@ -399,9 +1679,17 @@ function initializeModelChunk(chunk) {
399
1679
  var prevBlocked = initializingChunkBlockedModel;
400
1680
  initializingChunk = chunk;
401
1681
  initializingChunkBlockedModel = null;
1682
+ var resolvedModel = chunk.value; // We go to the CYCLIC state until we've fully resolved this.
1683
+ // We do this before parsing in case we try to initialize the same chunk
1684
+ // while parsing the model. Such as in a cyclic reference.
1685
+
1686
+ var cyclicChunk = chunk;
1687
+ cyclicChunk.status = CYCLIC;
1688
+ cyclicChunk.value = null;
1689
+ cyclicChunk.reason = null;
402
1690
 
403
1691
  try {
404
- var value = parseModel(chunk._response, chunk.value);
1692
+ var value = parseModel(chunk._response, resolvedModel);
405
1693
 
406
1694
  if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
407
1695
  initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
@@ -412,9 +1700,14 @@ function initializeModelChunk(chunk) {
412
1700
  blockedChunk.value = null;
413
1701
  blockedChunk.reason = null;
414
1702
  } else {
1703
+ var resolveListeners = cyclicChunk.value;
415
1704
  var initializedChunk = chunk;
416
1705
  initializedChunk.status = INITIALIZED;
417
1706
  initializedChunk.value = value;
1707
+
1708
+ if (resolveListeners !== null) {
1709
+ wakeChunk(resolveListeners, value);
1710
+ }
418
1711
  }
419
1712
  } catch (error) {
420
1713
  var erroredChunk = chunk;
@@ -452,18 +1745,30 @@ function reportGlobalError(response, error) {
452
1745
  });
453
1746
  }
454
1747
 
455
- function createElement(type, key, props) {
456
- var element = {
457
- // This tag allows us to uniquely identify this as a React Element
458
- $$typeof: REACT_ELEMENT_TYPE,
459
- // Built-in properties that belong on the element
460
- type: type,
461
- key: key,
462
- ref: null,
463
- props: props,
464
- // Record the component responsible for creating this element.
465
- _owner: null
466
- };
1748
+ function nullRefGetter() {
1749
+ {
1750
+ return null;
1751
+ }
1752
+ }
1753
+
1754
+ function createElement(type, key, props, owner) // DEV-only
1755
+ {
1756
+ var element;
1757
+
1758
+ {
1759
+ // `ref` is non-enumerable in dev
1760
+ element = {
1761
+ $$typeof: REACT_ELEMENT_TYPE,
1762
+ type: type,
1763
+ key: key,
1764
+ props: props,
1765
+ _owner: owner
1766
+ };
1767
+ Object.defineProperty(element, 'ref', {
1768
+ enumerable: false,
1769
+ get: nullRefGetter
1770
+ });
1771
+ }
467
1772
 
468
1773
  {
469
1774
  // We don't really need to add any of these but keeping them for good measure.
@@ -476,17 +1781,12 @@ function createElement(type, key, props) {
476
1781
  writable: true,
477
1782
  value: true // This element has already been validated on the server.
478
1783
 
479
- });
480
- Object.defineProperty(element, '_self', {
481
- configurable: false,
482
- enumerable: false,
483
- writable: false,
484
- value: null
485
- });
486
- Object.defineProperty(element, '_source', {
1784
+ }); // debugInfo contains Server Component debug information.
1785
+
1786
+ Object.defineProperty(element, '_debugInfo', {
487
1787
  configurable: false,
488
1788
  enumerable: false,
489
- writable: false,
1789
+ writable: true,
490
1790
  value: null
491
1791
  });
492
1792
  }
@@ -500,6 +1800,13 @@ function createLazyChunkWrapper(chunk) {
500
1800
  _payload: chunk,
501
1801
  _init: readChunk
502
1802
  };
1803
+
1804
+ {
1805
+ // Ensure we have a live array to track future debug info.
1806
+ var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
1807
+ lazyType._debugInfo = chunkDebugInfo;
1808
+ }
1809
+
503
1810
  return lazyType;
504
1811
  }
505
1812
 
@@ -515,21 +1822,30 @@ function getChunk(response, id) {
515
1822
  return chunk;
516
1823
  }
517
1824
 
518
- function createModelResolver(chunk, parentObject, key) {
1825
+ function createModelResolver(chunk, parentObject, key, cyclic, response, map) {
519
1826
  var blocked;
520
1827
 
521
1828
  if (initializingChunkBlockedModel) {
522
1829
  blocked = initializingChunkBlockedModel;
523
- blocked.deps++;
1830
+
1831
+ if (!cyclic) {
1832
+ blocked.deps++;
1833
+ }
524
1834
  } else {
525
1835
  blocked = initializingChunkBlockedModel = {
526
- deps: 1,
1836
+ deps: cyclic ? 0 : 1,
527
1837
  value: null
528
1838
  };
529
1839
  }
530
1840
 
531
1841
  return function (value) {
532
- parentObject[key] = value;
1842
+ parentObject[key] = map(response, value); // If this is the root object for a model reference, where `blocked.value`
1843
+ // is a stale `null`, the resolved value can be used directly.
1844
+
1845
+ if (key === '' && blocked.value === null) {
1846
+ blocked.value = parentObject[key];
1847
+ }
1848
+
533
1849
  blocked.deps--;
534
1850
 
535
1851
  if (blocked.deps === 0) {
@@ -579,10 +1895,89 @@ function createServerReferenceProxy(response, metaData) {
579
1895
  });
580
1896
  };
581
1897
 
582
- knownServerReferences.set(proxy, metaData);
1898
+ registerServerReference(proxy, metaData, response._encodeFormAction);
583
1899
  return proxy;
584
1900
  }
585
1901
 
1902
+ function getOutlinedModel(response, id, parentObject, key, map) {
1903
+ var chunk = getChunk(response, id);
1904
+
1905
+ switch (chunk.status) {
1906
+ case RESOLVED_MODEL:
1907
+ initializeModelChunk(chunk);
1908
+ break;
1909
+
1910
+ case RESOLVED_MODULE:
1911
+ initializeModuleChunk(chunk);
1912
+ break;
1913
+ } // The status might have changed after initialization.
1914
+
1915
+
1916
+ switch (chunk.status) {
1917
+ case INITIALIZED:
1918
+ var chunkValue = map(response, chunk.value);
1919
+
1920
+ if (chunk._debugInfo) {
1921
+ // If we have a direct reference to an object that was rendered by a synchronous
1922
+ // server component, it might have some debug info about how it was rendered.
1923
+ // We forward this to the underlying object. This might be a React Element or
1924
+ // an Array fragment.
1925
+ // If this was a string / number return value we lose the debug info. We choose
1926
+ // that tradeoff to allow sync server components to return plain values and not
1927
+ // use them as React Nodes necessarily. We could otherwise wrap them in a Lazy.
1928
+ if (typeof chunkValue === 'object' && chunkValue !== null && (Array.isArray(chunkValue) || typeof chunkValue[ASYNC_ITERATOR] === 'function' || chunkValue.$$typeof === REACT_ELEMENT_TYPE) && !chunkValue._debugInfo) {
1929
+ // We should maybe use a unique symbol for arrays but this is a React owned array.
1930
+ // $FlowFixMe[prop-missing]: This should be added to elements.
1931
+ Object.defineProperty(chunkValue, '_debugInfo', {
1932
+ configurable: false,
1933
+ enumerable: false,
1934
+ writable: true,
1935
+ value: chunk._debugInfo
1936
+ });
1937
+ }
1938
+ }
1939
+
1940
+ return chunkValue;
1941
+
1942
+ case PENDING:
1943
+ case BLOCKED:
1944
+ case CYCLIC:
1945
+ var parentChunk = initializingChunk;
1946
+ chunk.then(createModelResolver(parentChunk, parentObject, key, chunk.status === CYCLIC, response, map), createModelReject(parentChunk));
1947
+ return null;
1948
+
1949
+ default:
1950
+ throw chunk.reason;
1951
+ }
1952
+ }
1953
+
1954
+ function createMap(response, model) {
1955
+ return new Map(model);
1956
+ }
1957
+
1958
+ function createSet(response, model) {
1959
+ return new Set(model);
1960
+ }
1961
+
1962
+ function createFormData(response, model) {
1963
+ var formData = new FormData();
1964
+
1965
+ for (var i = 0; i < model.length; i++) {
1966
+ formData.append(model[i][0], model[i][1]);
1967
+ }
1968
+
1969
+ return formData;
1970
+ }
1971
+
1972
+ function extractIterator(response, model) {
1973
+ // $FlowFixMe[incompatible-use]: This uses raw Symbols because we're extracting from a native array.
1974
+ return model[Symbol.iterator]();
1975
+ }
1976
+
1977
+ function createModel(response, model) {
1978
+ return model;
1979
+ }
1980
+
586
1981
  function parseModelString(response, parentObject, key, value) {
587
1982
  if (value[0] === '$') {
588
1983
  if (value === '$') {
@@ -610,6 +2005,11 @@ function parseModelString(response, parentObject, key, value) {
610
2005
  case '@':
611
2006
  {
612
2007
  // Promise
2008
+ if (value.length === 2) {
2009
+ // Infinite promise that never resolves.
2010
+ return new Promise(function () {});
2011
+ }
2012
+
613
2013
  var _id = parseInt(value.slice(2), 16);
614
2014
 
615
2015
  var _chunk = getChunk(response, _id);
@@ -623,37 +2023,64 @@ function parseModelString(response, parentObject, key, value) {
623
2023
  return Symbol.for(value.slice(2));
624
2024
  }
625
2025
 
626
- case 'P':
627
- {
628
- // Server Context Provider
629
- return getOrCreateServerContext(value.slice(2)).Provider;
630
- }
631
-
632
2026
  case 'F':
633
2027
  {
634
2028
  // Server Reference
635
2029
  var _id2 = parseInt(value.slice(2), 16);
636
2030
 
637
- var _chunk2 = getChunk(response, _id2);
638
-
639
- switch (_chunk2.status) {
640
- case RESOLVED_MODEL:
641
- initializeModelChunk(_chunk2);
642
- break;
643
- } // The status might have changed after initialization.
2031
+ return getOutlinedModel(response, _id2, parentObject, key, createServerReferenceProxy);
2032
+ }
644
2033
 
2034
+ case 'T':
2035
+ {
2036
+ // Temporary Reference
2037
+ var _id3 = parseInt(value.slice(2), 16);
645
2038
 
646
- switch (_chunk2.status) {
647
- case INITIALIZED:
648
- {
649
- var metadata = _chunk2.value;
650
- return createServerReferenceProxy(response, metadata);
651
- }
652
- // We always encode it first in the stream so it won't be pending.
2039
+ var temporaryReferences = response._tempRefs;
653
2040
 
654
- default:
655
- throw _chunk2.reason;
2041
+ if (temporaryReferences == null) {
2042
+ throw new Error('Missing a temporary reference set but the RSC response returned a temporary reference. ' + 'Pass a temporaryReference option with the set that was used with the reply.');
656
2043
  }
2044
+
2045
+ return readTemporaryReference(temporaryReferences, _id3);
2046
+ }
2047
+
2048
+ case 'Q':
2049
+ {
2050
+ // Map
2051
+ var _id4 = parseInt(value.slice(2), 16);
2052
+
2053
+ return getOutlinedModel(response, _id4, parentObject, key, createMap);
2054
+ }
2055
+
2056
+ case 'W':
2057
+ {
2058
+ // Set
2059
+ var _id5 = parseInt(value.slice(2), 16);
2060
+
2061
+ return getOutlinedModel(response, _id5, parentObject, key, createSet);
2062
+ }
2063
+
2064
+ case 'B':
2065
+ {
2066
+
2067
+ return undefined;
2068
+ }
2069
+
2070
+ case 'K':
2071
+ {
2072
+ // FormData
2073
+ var _id7 = parseInt(value.slice(2), 16);
2074
+
2075
+ return getOutlinedModel(response, _id7, parentObject, key, createFormData);
2076
+ }
2077
+
2078
+ case 'i':
2079
+ {
2080
+ // Iterator
2081
+ var _id8 = parseInt(value.slice(2), 16);
2082
+
2083
+ return getOutlinedModel(response, _id8, parentObject, key, extractIterator);
657
2084
  }
658
2085
 
659
2086
  case 'I':
@@ -697,52 +2124,43 @@ function parseModelString(response, parentObject, key, value) {
697
2124
  return BigInt(value.slice(2));
698
2125
  }
699
2126
 
700
- default:
2127
+ case 'E':
701
2128
  {
702
- // We assume that anything else is a reference ID.
703
- var _id3 = parseInt(value.slice(1), 16);
704
-
705
- var _chunk3 = getChunk(response, _id3);
706
-
707
- switch (_chunk3.status) {
708
- case RESOLVED_MODEL:
709
- initializeModelChunk(_chunk3);
710
- break;
711
-
712
- case RESOLVED_MODULE:
713
- initializeModuleChunk(_chunk3);
714
- break;
715
- } // The status might have changed after initialization.
2129
+ {
2130
+ // In DEV mode we allow indirect eval to produce functions for logging.
2131
+ // This should not compile to eval() because then it has local scope access.
2132
+ try {
2133
+ // eslint-disable-next-line no-eval
2134
+ return (0, eval)(value.slice(2));
2135
+ } catch (x) {
2136
+ // We currently use this to express functions so we fail parsing it,
2137
+ // let's just return a blank function as a place holder.
2138
+ return function () {};
2139
+ }
2140
+ } // Fallthrough
716
2141
 
2142
+ }
717
2143
 
718
- switch (_chunk3.status) {
719
- case INITIALIZED:
720
- return _chunk3.value;
721
-
722
- case PENDING:
723
- case BLOCKED:
724
- var parentChunk = initializingChunk;
725
-
726
- _chunk3.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
727
-
728
- return null;
2144
+ default:
2145
+ {
2146
+ // We assume that anything else is a reference ID.
2147
+ var _id9 = parseInt(value.slice(1), 16);
729
2148
 
730
- default:
731
- throw _chunk3.reason;
732
- }
2149
+ return getOutlinedModel(response, _id9, parentObject, key, createModel);
733
2150
  }
734
2151
  }
735
2152
  }
736
2153
 
737
2154
  return value;
738
2155
  }
2156
+
739
2157
  function parseModelTuple(response, value) {
740
2158
  var tuple = value;
741
2159
 
742
2160
  if (tuple[0] === REACT_ELEMENT_TYPE) {
743
2161
  // TODO: Consider having React just directly accept these arrays as elements.
744
2162
  // Or even change the ReactElement type to be an array.
745
- return createElement(tuple[1], tuple[2], tuple[3]);
2163
+ return createElement(tuple[1], tuple[2], tuple[3], tuple[4] );
746
2164
  }
747
2165
 
748
2166
  return value;
@@ -752,15 +2170,29 @@ function missingCall() {
752
2170
  throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
753
2171
  }
754
2172
 
755
- function createResponse$1(bundlerConfig, callServer) {
2173
+ function createResponse(bundlerConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences) {
756
2174
  var chunks = new Map();
757
2175
  var response = {
758
2176
  _bundlerConfig: bundlerConfig,
2177
+ _moduleLoading: moduleLoading,
759
2178
  _callServer: callServer !== undefined ? callServer : missingCall,
760
- _chunks: chunks
761
- };
2179
+ _encodeFormAction: encodeFormAction,
2180
+ _nonce: nonce,
2181
+ _chunks: chunks,
2182
+ _stringDecoder: createStringDecoder(),
2183
+ _fromJSON: null,
2184
+ _rowState: 0,
2185
+ _rowID: 0,
2186
+ _rowTag: 0,
2187
+ _rowLength: 0,
2188
+ _buffer: [],
2189
+ _tempRefs: temporaryReferences
2190
+ }; // Don't inline this call because it causes closure to outline the call above.
2191
+
2192
+ response._fromJSON = createFromJSONCallback(response);
762
2193
  return response;
763
2194
  }
2195
+
764
2196
  function resolveModel(response, id, model) {
765
2197
  var chunks = response._chunks;
766
2198
  var chunk = chunks.get(id);
@@ -771,11 +2203,19 @@ function resolveModel(response, id, model) {
771
2203
  resolveModelChunk(chunk, model);
772
2204
  }
773
2205
  }
2206
+
2207
+ function resolveText(response, id, text) {
2208
+ var chunks = response._chunks;
2209
+
2210
+ chunks.set(id, createInitializedTextChunk(response, text));
2211
+ }
2212
+
774
2213
  function resolveModule(response, id, model) {
775
2214
  var chunks = response._chunks;
776
2215
  var chunk = chunks.get(id);
777
2216
  var clientReferenceMetadata = parseModel(response, model);
778
- var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
2217
+ var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
2218
+ prepareDestinationForModule(response._moduleLoading, response._nonce, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
779
2219
  // For now we preload all modules as early as possible since it's likely
780
2220
  // that we'll need them.
781
2221
 
@@ -811,6 +2251,7 @@ function resolveModule(response, id, model) {
811
2251
  }
812
2252
  }
813
2253
  }
2254
+
814
2255
  function resolveErrorDev(response, id, digest, message, stack) {
815
2256
 
816
2257
 
@@ -827,47 +2268,65 @@ function resolveErrorDev(response, id, digest, message, stack) {
827
2268
  triggerErrorOnChunk(chunk, errorWithDigest);
828
2269
  }
829
2270
  }
2271
+
830
2272
  function resolveHint(response, code, model) {
831
2273
  var hintModel = parseModel(response, model);
832
2274
  dispatchHint(code, hintModel);
833
2275
  }
834
- function close(response) {
835
- // In case there are any remaining unresolved chunks, they won't
836
- // be resolved now. So we need to issue an error to those.
837
- // Ideally we should be able to early bail out if we kept a
838
- // ref count of pending chunks.
839
- reportGlobalError(response, new Error('Connection closed.'));
2276
+
2277
+ function resolveDebugInfo(response, id, debugInfo) {
2278
+
2279
+ var chunk = getChunk(response, id);
2280
+ var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
2281
+ chunkDebugInfo.push(debugInfo);
840
2282
  }
841
2283
 
842
- function processFullRow(response, row) {
843
- if (row === '') {
844
- return;
2284
+ function resolveConsoleEntry(response, value) {
2285
+
2286
+ var payload = parseModel(response, value);
2287
+ var methodName = payload[0]; // TODO: Restore the fake stack before logging.
2288
+ // const stackTrace = payload[1];
2289
+ // const owner = payload[2];
2290
+
2291
+ var env = payload[3];
2292
+ var args = payload.slice(4);
2293
+ printToConsole(methodName, args, env);
2294
+ }
2295
+
2296
+ function processFullRow(response, id, tag, buffer, chunk) {
2297
+
2298
+ var stringDecoder = response._stringDecoder;
2299
+ var row = '';
2300
+
2301
+ for (var i = 0; i < buffer.length; i++) {
2302
+ row += readPartialStringChunk(stringDecoder, buffer[i]);
845
2303
  }
846
2304
 
847
- var colon = row.indexOf(':', 0);
848
- var id = parseInt(row.slice(0, colon), 16);
849
- var tag = row[colon + 1]; // When tags that are not text are added, check them here before
850
- // parsing the row as text.
851
- // switch (tag) {
852
- // }
2305
+ row += readFinalStringChunk(stringDecoder, chunk);
853
2306
 
854
2307
  switch (tag) {
855
- case 'I':
2308
+ case 73
2309
+ /* "I" */
2310
+ :
856
2311
  {
857
- resolveModule(response, id, row.slice(colon + 2));
2312
+ resolveModule(response, id, row);
858
2313
  return;
859
2314
  }
860
2315
 
861
- case 'H':
2316
+ case 72
2317
+ /* "H" */
2318
+ :
862
2319
  {
863
- var code = row[colon + 2];
864
- resolveHint(response, code, row.slice(colon + 3));
2320
+ var code = row[0];
2321
+ resolveHint(response, code, row.slice(1));
865
2322
  return;
866
2323
  }
867
2324
 
868
- case 'E':
2325
+ case 69
2326
+ /* "E" */
2327
+ :
869
2328
  {
870
- var errorInfo = JSON.parse(row.slice(colon + 2));
2329
+ var errorInfo = JSON.parse(row);
871
2330
 
872
2331
  {
873
2332
  resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
@@ -876,42 +2335,215 @@ function processFullRow(response, row) {
876
2335
  return;
877
2336
  }
878
2337
 
2338
+ case 84
2339
+ /* "T" */
2340
+ :
2341
+ {
2342
+ resolveText(response, id, row);
2343
+ return;
2344
+ }
2345
+
2346
+ case 68
2347
+ /* "D" */
2348
+ :
2349
+ {
2350
+ {
2351
+ var debugInfo = parseModel(response, row);
2352
+ resolveDebugInfo(response, id, debugInfo);
2353
+ return;
2354
+ } // Fallthrough to share the error with Console entries.
2355
+
2356
+ }
2357
+
2358
+ case 87
2359
+ /* "W" */
2360
+ :
2361
+ {
2362
+ {
2363
+ resolveConsoleEntry(response, row);
2364
+ return;
2365
+ }
2366
+ }
2367
+
2368
+ case 82
2369
+ /* "R" */
2370
+ :
2371
+ // Fallthrough
2372
+
2373
+ case 114
2374
+ /* "r" */
2375
+ :
2376
+ // Fallthrough
2377
+
2378
+ case 88
2379
+ /* "X" */
2380
+ :
2381
+ // Fallthrough
2382
+
2383
+ case 120
2384
+ /* "x" */
2385
+ :
2386
+ // Fallthrough
2387
+
2388
+ case 67
2389
+ /* "C" */
2390
+ :
2391
+ // Fallthrough
2392
+
2393
+ case 80
2394
+ /* "P" */
2395
+ :
2396
+ // Fallthrough
2397
+
879
2398
  default:
2399
+ /* """ "{" "[" "t" "f" "n" "0" - "9" */
880
2400
  {
881
2401
  // We assume anything else is JSON.
882
- resolveModel(response, id, row.slice(colon + 1));
2402
+ resolveModel(response, id, row);
883
2403
  return;
884
2404
  }
885
2405
  }
886
2406
  }
887
2407
 
888
- function processStringChunk(response, chunk, offset) {
889
- var linebreak = chunk.indexOf('\n', offset);
2408
+ function processBinaryChunk(response, chunk) {
2409
+ var i = 0;
2410
+ var rowState = response._rowState;
2411
+ var rowID = response._rowID;
2412
+ var rowTag = response._rowTag;
2413
+ var rowLength = response._rowLength;
2414
+ var buffer = response._buffer;
2415
+ var chunkLength = chunk.length;
2416
+
2417
+ while (i < chunkLength) {
2418
+ var lastIdx = -1;
2419
+
2420
+ switch (rowState) {
2421
+ case ROW_ID:
2422
+ {
2423
+ var byte = chunk[i++];
2424
+
2425
+ if (byte === 58
2426
+ /* ":" */
2427
+ ) {
2428
+ // Finished the rowID, next we'll parse the tag.
2429
+ rowState = ROW_TAG;
2430
+ } else {
2431
+ rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
2432
+ }
890
2433
 
891
- while (linebreak > -1) {
892
- var fullrow = response._partialRow + chunk.slice(offset, linebreak);
893
- processFullRow(response, fullrow);
894
- response._partialRow = '';
895
- offset = linebreak + 1;
896
- linebreak = chunk.indexOf('\n', offset);
897
- }
2434
+ continue;
2435
+ }
898
2436
 
899
- response._partialRow += chunk.slice(offset);
900
- }
901
- function processBinaryChunk(response, chunk) {
2437
+ case ROW_TAG:
2438
+ {
2439
+ var resolvedRowTag = chunk[i];
2440
+
2441
+ if (resolvedRowTag === 84
2442
+ /* "T" */
2443
+ || enableBinaryFlight
2444
+ /* "V" */
2445
+ ) {
2446
+ rowTag = resolvedRowTag;
2447
+ rowState = ROW_LENGTH;
2448
+ i++;
2449
+ } else if (resolvedRowTag > 64 && resolvedRowTag < 91 ||
2450
+ /* "A"-"Z" */
2451
+ resolvedRowTag === 114
2452
+ /* "r" */
2453
+ || resolvedRowTag === 120
2454
+ /* "x" */
2455
+ ) {
2456
+ rowTag = resolvedRowTag;
2457
+ rowState = ROW_CHUNK_BY_NEWLINE;
2458
+ i++;
2459
+ } else {
2460
+ rowTag = 0;
2461
+ rowState = ROW_CHUNK_BY_NEWLINE; // This was an unknown tag so it was probably part of the data.
2462
+ }
902
2463
 
903
- var stringDecoder = response._stringDecoder;
904
- var linebreak = chunk.indexOf(10); // newline
2464
+ continue;
2465
+ }
2466
+
2467
+ case ROW_LENGTH:
2468
+ {
2469
+ var _byte = chunk[i++];
2470
+
2471
+ if (_byte === 44
2472
+ /* "," */
2473
+ ) {
2474
+ // Finished the rowLength, next we'll buffer up to that length.
2475
+ rowState = ROW_CHUNK_BY_LENGTH;
2476
+ } else {
2477
+ rowLength = rowLength << 4 | (_byte > 96 ? _byte - 87 : _byte - 48);
2478
+ }
2479
+
2480
+ continue;
2481
+ }
2482
+
2483
+ case ROW_CHUNK_BY_NEWLINE:
2484
+ {
2485
+ // We're looking for a newline
2486
+ lastIdx = chunk.indexOf(10
2487
+ /* "\n" */
2488
+ , i);
2489
+ break;
2490
+ }
2491
+
2492
+ case ROW_CHUNK_BY_LENGTH:
2493
+ {
2494
+ // We're looking for the remaining byte length
2495
+ lastIdx = i + rowLength;
2496
+
2497
+ if (lastIdx > chunk.length) {
2498
+ lastIdx = -1;
2499
+ }
2500
+
2501
+ break;
2502
+ }
2503
+ }
2504
+
2505
+ var offset = chunk.byteOffset + i;
2506
+
2507
+ if (lastIdx > -1) {
2508
+ // We found the last chunk of the row
2509
+ var length = lastIdx - i;
2510
+ var lastChunk = new Uint8Array(chunk.buffer, offset, length);
2511
+ processFullRow(response, rowID, rowTag, buffer, lastChunk); // Reset state machine for a new row
2512
+
2513
+ i = lastIdx;
2514
+
2515
+ if (rowState === ROW_CHUNK_BY_NEWLINE) {
2516
+ // If we're trailing by a newline we need to skip it.
2517
+ i++;
2518
+ }
2519
+
2520
+ rowState = ROW_ID;
2521
+ rowTag = 0;
2522
+ rowID = 0;
2523
+ rowLength = 0;
2524
+ buffer.length = 0;
2525
+ } else {
2526
+ // The rest of this row is in a future chunk. We stash the rest of the
2527
+ // current chunk until we can process the full row.
2528
+ var _length = chunk.byteLength - i;
2529
+
2530
+ var remainingSlice = new Uint8Array(chunk.buffer, offset, _length);
2531
+ buffer.push(remainingSlice); // Update how many bytes we're still waiting for. If we're looking for
2532
+ // a newline, this doesn't hurt since we'll just ignore it.
905
2533
 
906
- while (linebreak > -1) {
907
- var fullrow = response._partialRow + readFinalStringChunk(stringDecoder, chunk.subarray(0, linebreak));
908
- processFullRow(response, fullrow);
909
- response._partialRow = '';
910
- chunk = chunk.subarray(linebreak + 1);
911
- linebreak = chunk.indexOf(10); // newline
2534
+ rowLength -= remainingSlice.byteLength;
2535
+ break;
2536
+ }
912
2537
  }
913
2538
 
914
- response._partialRow += readPartialStringChunk(stringDecoder, chunk);
2539
+ response._rowState = rowState;
2540
+ response._rowID = rowID;
2541
+ response._rowTag = rowTag;
2542
+ response._rowLength = rowLength;
2543
+ }
2544
+
2545
+ function parseModel(response, json) {
2546
+ return JSON.parse(json, response._fromJSON);
915
2547
  }
916
2548
 
917
2549
  function createFromJSONCallback(response) {
@@ -930,20 +2562,12 @@ function createFromJSONCallback(response) {
930
2562
  };
931
2563
  }
932
2564
 
933
- function createResponse(bundlerConfig, callServer) {
934
- // NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.
935
- // It should be inlined to one object literal but minor changes can break it.
936
- var stringDecoder = createStringDecoder() ;
937
- var response = createResponse$1(bundlerConfig, callServer);
938
- response._partialRow = '';
939
-
940
- {
941
- response._stringDecoder = stringDecoder;
942
- } // Don't inline this call because it causes closure to outline the call above.
943
-
944
-
945
- response._fromJSON = createFromJSONCallback(response);
946
- return response;
2565
+ function close(response) {
2566
+ // In case there are any remaining unresolved chunks, they won't
2567
+ // be resolved now. So we need to issue an error to those.
2568
+ // Ideally we should be able to early bail out if we kept a
2569
+ // ref count of pending chunks.
2570
+ reportGlobalError(response, new Error('Connection closed.'));
947
2571
  }
948
2572
 
949
2573
  function noServerCall() {
@@ -951,17 +2575,14 @@ function noServerCall() {
951
2575
  }
952
2576
 
953
2577
  function createServerReference(id, callServer) {
954
- return noServerCall;
2578
+ return createServerReference$1(id, noServerCall);
955
2579
  }
956
2580
 
957
- function createFromNodeStream(stream, moduleMap) {
958
- var response = createResponse(moduleMap, noServerCall);
2581
+ function createFromNodeStream(stream, ssrManifest, options) {
2582
+ var response = createResponse(ssrManifest.moduleMap, ssrManifest.moduleLoading, noServerCall, options ? options.encodeFormAction : undefined, options && typeof options.nonce === 'string' ? options.nonce : undefined, undefined // TODO: If encodeReply is supported, this should support temporaryReferences
2583
+ );
959
2584
  stream.on('data', function (chunk) {
960
- if (typeof chunk === 'string') {
961
- processStringChunk(response, chunk, 0);
962
- } else {
963
- processBinaryChunk(response, chunk);
964
- }
2585
+ processBinaryChunk(response, chunk);
965
2586
  });
966
2587
  stream.on('error', function (error) {
967
2588
  reportGlobalError(response, error);