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