react-server-dom-webpack 18.3.0-next-fa4314841-20230502 → 19.0.0-canary-05797cceb-20240328

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 (42) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +1768 -1188
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +1739 -0
  3. package/cjs/react-server-dom-webpack-client.browser.production.min.js +40 -34
  4. package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -0
  5. package/cjs/react-server-dom-webpack-client.edge.development.js +1755 -221
  6. package/cjs/react-server-dom-webpack-client.edge.production.js +1986 -0
  7. package/cjs/react-server-dom-webpack-client.edge.production.min.js +45 -28
  8. package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -0
  9. package/cjs/react-server-dom-webpack-client.node.development.js +1743 -239
  10. package/cjs/react-server-dom-webpack-client.node.production.js +1942 -0
  11. package/cjs/react-server-dom-webpack-client.node.production.min.js +44 -28
  12. package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -0
  13. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1702 -194
  14. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1895 -0
  15. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +43 -26
  16. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -0
  17. package/cjs/react-server-dom-webpack-node-register.js +12 -18
  18. package/cjs/react-server-dom-webpack-node-register.js.map +1 -0
  19. package/cjs/react-server-dom-webpack-plugin.js +22 -19
  20. package/cjs/react-server-dom-webpack-plugin.js.map +1 -0
  21. package/cjs/react-server-dom-webpack-server.browser.development.js +1588 -808
  22. package/cjs/react-server-dom-webpack-server.browser.production.js +3257 -0
  23. package/cjs/react-server-dom-webpack-server.browser.production.min.js +80 -62
  24. package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -0
  25. package/cjs/react-server-dom-webpack-server.edge.development.js +1583 -811
  26. package/cjs/react-server-dom-webpack-server.edge.production.js +3261 -0
  27. package/cjs/react-server-dom-webpack-server.edge.production.min.js +82 -62
  28. package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -0
  29. package/cjs/react-server-dom-webpack-server.node.development.js +1575 -805
  30. package/cjs/react-server-dom-webpack-server.node.production.js +3464 -0
  31. package/cjs/react-server-dom-webpack-server.node.production.min.js +85 -67
  32. package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -0
  33. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1526 -761
  34. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +3391 -0
  35. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +82 -65
  36. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -0
  37. package/esm/react-server-dom-webpack-node-loader.production.min.js +19 -12
  38. package/package.json +7 -13
  39. package/umd/react-server-dom-webpack-client.browser.development.js +1770 -1189
  40. package/umd/react-server-dom-webpack-client.browser.production.min.js +26 -20
  41. package/umd/react-server-dom-webpack-server.browser.development.js +1589 -808
  42. package/umd/react-server-dom-webpack-server.browser.production.min.js +55 -42
@@ -0,0 +1,1739 @@
1
+ /**
2
+ * @license React
3
+ * react-server-dom-webpack-client.browser.production.min.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ var ReactDOM = require('react-dom');
14
+
15
+ // -----------------------------------------------------------------------------
16
+ const enableBinaryFlight = false;
17
+
18
+ function createStringDecoder() {
19
+ return new TextDecoder();
20
+ }
21
+ const decoderOptions = {
22
+ stream: true
23
+ };
24
+ function readPartialStringChunk(decoder, buffer) {
25
+ return decoder.decode(buffer, decoderOptions);
26
+ }
27
+ function readFinalStringChunk(decoder, buffer) {
28
+ return decoder.decode(buffer);
29
+ }
30
+
31
+ // This is the parsed shape of the wire format which is why it is
32
+ // condensed to only the essentialy information
33
+ const ID = 0;
34
+ const CHUNKS = 1;
35
+ const NAME = 2; // export const ASYNC = 3;
36
+ // This logic is correct because currently only include the 4th tuple member
37
+ // when the module is async. If that changes we will need to actually assert
38
+ // the value is true. We don't index into the 4th slot because flow does not
39
+ // like the potential out of bounds access
40
+
41
+ function isAsyncImport(metadata) {
42
+ return metadata.length === 4;
43
+ }
44
+
45
+ function resolveClientReference(bundlerConfig, metadata) {
46
+ if (bundlerConfig) {
47
+ const moduleExports = bundlerConfig[metadata[ID]];
48
+ let resolvedModuleData = moduleExports[metadata[NAME]];
49
+ let name;
50
+
51
+ if (resolvedModuleData) {
52
+ // The potentially aliased name.
53
+ name = resolvedModuleData.name;
54
+ } else {
55
+ // If we don't have this specific name, we might have the full module.
56
+ resolvedModuleData = moduleExports['*'];
57
+
58
+ if (!resolvedModuleData) {
59
+ 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.');
60
+ }
61
+
62
+ name = metadata[NAME];
63
+ }
64
+
65
+ if (isAsyncImport(metadata)) {
66
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1
67
+ /* async */
68
+ ];
69
+ } else {
70
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
71
+ }
72
+ }
73
+
74
+ return metadata;
75
+ }
76
+ // If they're still pending they're a thenable. This map also exists
77
+ // in Webpack but unfortunately it's not exposed so we have to
78
+ // replicate it in user space. null means that it has already loaded.
79
+
80
+ const chunkCache = new Map();
81
+
82
+ function requireAsyncModule(id) {
83
+ // We've already loaded all the chunks. We can require the module.
84
+ const promise = __webpack_require__(id);
85
+
86
+ if (typeof promise.then !== 'function') {
87
+ // This wasn't a promise after all.
88
+ return null;
89
+ } else if (promise.status === 'fulfilled') {
90
+ // This module was already resolved earlier.
91
+ return null;
92
+ } else {
93
+ // Instrument the Promise to stash the result.
94
+ promise.then(value => {
95
+ const fulfilledThenable = promise;
96
+ fulfilledThenable.status = 'fulfilled';
97
+ fulfilledThenable.value = value;
98
+ }, reason => {
99
+ const rejectedThenable = promise;
100
+ rejectedThenable.status = 'rejected';
101
+ rejectedThenable.reason = reason;
102
+ });
103
+ return promise;
104
+ }
105
+ }
106
+
107
+ function ignoreReject() {// We rely on rejected promises to be handled by another listener.
108
+ } // Start preloading the modules since we might need them soon.
109
+ // This function doesn't suspend.
110
+
111
+
112
+ function preloadModule(metadata) {
113
+ const chunks = metadata[CHUNKS];
114
+ const promises = [];
115
+ let i = 0;
116
+
117
+ while (i < chunks.length) {
118
+ const chunkId = chunks[i++];
119
+ const chunkFilename = chunks[i++];
120
+ const entry = chunkCache.get(chunkId);
121
+
122
+ if (entry === undefined) {
123
+ const thenable = loadChunk(chunkId, chunkFilename);
124
+ promises.push(thenable); // $FlowFixMe[method-unbinding]
125
+
126
+ const resolve = chunkCache.set.bind(chunkCache, chunkId, null);
127
+ thenable.then(resolve, ignoreReject);
128
+ chunkCache.set(chunkId, thenable);
129
+ } else if (entry !== null) {
130
+ promises.push(entry);
131
+ }
132
+ }
133
+
134
+ if (isAsyncImport(metadata)) {
135
+ if (promises.length === 0) {
136
+ return requireAsyncModule(metadata[ID]);
137
+ } else {
138
+ return Promise.all(promises).then(() => {
139
+ return requireAsyncModule(metadata[ID]);
140
+ });
141
+ }
142
+ } else if (promises.length > 0) {
143
+ return Promise.all(promises);
144
+ } else {
145
+ return null;
146
+ }
147
+ } // Actually require the module or suspend if it's not yet ready.
148
+ // Increase priority if necessary.
149
+
150
+ function requireModule(metadata) {
151
+ let moduleExports = __webpack_require__(metadata[ID]);
152
+
153
+ if (isAsyncImport(metadata)) {
154
+ if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
155
+ // This Promise should've been instrumented by preloadModule.
156
+ moduleExports = moduleExports.value;
157
+ } else {
158
+ throw moduleExports.reason;
159
+ }
160
+ }
161
+
162
+ if (metadata[NAME] === '*') {
163
+ // This is a placeholder value that represents that the caller imported this
164
+ // as a CommonJS module as is.
165
+ return moduleExports;
166
+ }
167
+
168
+ if (metadata[NAME] === '') {
169
+ // This is a placeholder value that represents that the caller accessed the
170
+ // default property of this if it was an ESM interop module.
171
+ return moduleExports.__esModule ? moduleExports.default : moduleExports;
172
+ }
173
+
174
+ return moduleExports[metadata[NAME]];
175
+ }
176
+
177
+ const chunkMap = new Map();
178
+ /**
179
+ * We patch the chunk filename function in webpack to insert our own resolution
180
+ * of chunks that come from Flight and may not be known to the webpack runtime
181
+ */
182
+
183
+ const webpackGetChunkFilename = __webpack_require__.u;
184
+
185
+ __webpack_require__.u = function (chunkId) {
186
+ const flightChunk = chunkMap.get(chunkId);
187
+
188
+ if (flightChunk !== undefined) {
189
+ return flightChunk;
190
+ }
191
+
192
+ return webpackGetChunkFilename(chunkId);
193
+ };
194
+
195
+ function loadChunk(chunkId, filename) {
196
+ chunkMap.set(chunkId, filename);
197
+ return __webpack_chunk_load__(chunkId);
198
+ }
199
+
200
+ const ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
201
+
202
+ // This client file is in the shared folder because it applies to both SSR and browser contexts.
203
+ const ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
204
+ function dispatchHint(code, model) {
205
+ const dispatcher = ReactDOMCurrentDispatcher.current;
206
+
207
+ switch (code) {
208
+ case 'D':
209
+ {
210
+ const refined = refineModel(code, model);
211
+ const href = refined;
212
+ dispatcher.prefetchDNS(href);
213
+ return;
214
+ }
215
+
216
+ case 'C':
217
+ {
218
+ const refined = refineModel(code, model);
219
+
220
+ if (typeof refined === 'string') {
221
+ const href = refined;
222
+ dispatcher.preconnect(href);
223
+ } else {
224
+ const href = refined[0];
225
+ const crossOrigin = refined[1];
226
+ dispatcher.preconnect(href, crossOrigin);
227
+ }
228
+
229
+ return;
230
+ }
231
+
232
+ case 'L':
233
+ {
234
+ const refined = refineModel(code, model);
235
+ const href = refined[0];
236
+ const as = refined[1];
237
+
238
+ if (refined.length === 3) {
239
+ const options = refined[2];
240
+ dispatcher.preload(href, as, options);
241
+ } else {
242
+ dispatcher.preload(href, as);
243
+ }
244
+
245
+ return;
246
+ }
247
+
248
+ case 'm':
249
+ {
250
+ const refined = refineModel(code, model);
251
+
252
+ if (typeof refined === 'string') {
253
+ const href = refined;
254
+ dispatcher.preloadModule(href);
255
+ } else {
256
+ const href = refined[0];
257
+ const options = refined[1];
258
+ dispatcher.preloadModule(href, options);
259
+ }
260
+
261
+ return;
262
+ }
263
+
264
+ case 'S':
265
+ {
266
+ const refined = refineModel(code, model);
267
+
268
+ if (typeof refined === 'string') {
269
+ const href = refined;
270
+ dispatcher.preinitStyle(href);
271
+ } else {
272
+ const href = refined[0];
273
+ const precedence = refined[1] === 0 ? undefined : refined[1];
274
+ const options = refined.length === 3 ? refined[2] : undefined;
275
+ dispatcher.preinitStyle(href, precedence, options);
276
+ }
277
+
278
+ return;
279
+ }
280
+
281
+ case 'X':
282
+ {
283
+ const refined = refineModel(code, model);
284
+
285
+ if (typeof refined === 'string') {
286
+ const href = refined;
287
+ dispatcher.preinitScript(href);
288
+ } else {
289
+ const href = refined[0];
290
+ const options = refined[1];
291
+ dispatcher.preinitScript(href, options);
292
+ }
293
+
294
+ return;
295
+ }
296
+
297
+ case 'M':
298
+ {
299
+ const refined = refineModel(code, model);
300
+
301
+ if (typeof refined === 'string') {
302
+ const href = refined;
303
+ dispatcher.preinitModuleScript(href);
304
+ } else {
305
+ const href = refined[0];
306
+ const options = refined[1];
307
+ dispatcher.preinitModuleScript(href, options);
308
+ }
309
+
310
+ return;
311
+ }
312
+ }
313
+ } // Flow is having trouble refining the HintModels so we help it a bit.
314
+ // This should be compiled out in the production build.
315
+
316
+ function refineModel(code, model) {
317
+ return model;
318
+ }
319
+
320
+ // ATTENTION
321
+ // When adding new symbols to this file,
322
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
323
+ // The Symbol used to tag the ReactElement-like types.
324
+ const REACT_ELEMENT_TYPE = Symbol.for('react.element');
325
+ const REACT_LAZY_TYPE = Symbol.for('react.lazy');
326
+ const MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
327
+ const FAUX_ITERATOR_SYMBOL = '@@iterator';
328
+ function getIteratorFn(maybeIterable) {
329
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
330
+ return null;
331
+ }
332
+
333
+ const maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
334
+
335
+ if (typeof maybeIterator === 'function') {
336
+ return maybeIterator;
337
+ }
338
+
339
+ return null;
340
+ }
341
+
342
+ const isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
343
+
344
+ function isArray(a) {
345
+ return isArrayImpl(a);
346
+ }
347
+
348
+ const getPrototypeOf = Object.getPrototypeOf;
349
+
350
+ function createTemporaryReferenceSet() {
351
+ return [];
352
+ }
353
+ function writeTemporaryReference(set, object) {
354
+ // We always create a new entry regardless if we've already written the same
355
+ // object. This ensures that we always generate a deterministic encoding of
356
+ // each slot in the reply for cacheability.
357
+ const newId = set.length;
358
+ set.push(object);
359
+ return newId;
360
+ }
361
+ function readTemporaryReference(set, id) {
362
+ if (id < 0 || id >= set.length) {
363
+ 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.');
364
+ }
365
+
366
+ return set[id];
367
+ }
368
+
369
+ const ObjectPrototype = Object.prototype;
370
+ const knownServerReferences = new WeakMap(); // Serializable values
371
+ // Thenable<ReactServerValue>
372
+
373
+ function serializeByValueID(id) {
374
+ return '$' + id.toString(16);
375
+ }
376
+
377
+ function serializePromiseID(id) {
378
+ return '$@' + id.toString(16);
379
+ }
380
+
381
+ function serializeServerReferenceID(id) {
382
+ return '$F' + id.toString(16);
383
+ }
384
+
385
+ function serializeTemporaryReferenceID(id) {
386
+ return '$T' + id.toString(16);
387
+ }
388
+
389
+ function serializeFormDataReference(id) {
390
+ // Why K? F is "Function". D is "Date". What else?
391
+ return '$K' + id.toString(16);
392
+ }
393
+
394
+ function serializeNumber(number) {
395
+ if (Number.isFinite(number)) {
396
+ if (number === 0 && 1 / number === -Infinity) {
397
+ return '$-0';
398
+ } else {
399
+ return number;
400
+ }
401
+ } else {
402
+ if (number === Infinity) {
403
+ return '$Infinity';
404
+ } else if (number === -Infinity) {
405
+ return '$-Infinity';
406
+ } else {
407
+ return '$NaN';
408
+ }
409
+ }
410
+ }
411
+
412
+ function serializeUndefined() {
413
+ return '$undefined';
414
+ }
415
+
416
+ function serializeDateFromDateJSON(dateJSON) {
417
+ // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
418
+ // We need only tack on a $D prefix.
419
+ return '$D' + dateJSON;
420
+ }
421
+
422
+ function serializeBigInt(n) {
423
+ return '$n' + n.toString(10);
424
+ }
425
+
426
+ function serializeMapID(id) {
427
+ return '$Q' + id.toString(16);
428
+ }
429
+
430
+ function serializeSetID(id) {
431
+ return '$W' + id.toString(16);
432
+ }
433
+
434
+ function escapeStringValue(value) {
435
+ if (value[0] === '$') {
436
+ // We need to escape $ prefixed strings since we use those to encode
437
+ // references to IDs and as special symbol values.
438
+ return '$' + value;
439
+ } else {
440
+ return value;
441
+ }
442
+ }
443
+
444
+ function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
445
+ let nextPartId = 1;
446
+ let pendingParts = 0;
447
+ let formData = null;
448
+
449
+ function resolveToJSON(key, value) {
450
+ const parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
451
+
452
+ if (value === null) {
453
+ return null;
454
+ }
455
+
456
+ if (typeof value === 'object') {
457
+ switch (value.$$typeof) {
458
+ case REACT_ELEMENT_TYPE:
459
+ {
460
+ if (temporaryReferences === undefined) {
461
+ 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.' + (''));
462
+ }
463
+
464
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
465
+ }
466
+
467
+ case REACT_LAZY_TYPE:
468
+ {
469
+ // Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
470
+ const lazy = value;
471
+ const payload = lazy._payload;
472
+ const init = lazy._init;
473
+
474
+ if (formData === null) {
475
+ // Upgrade to use FormData to allow us to stream this value.
476
+ formData = new FormData();
477
+ }
478
+
479
+ pendingParts++;
480
+
481
+ try {
482
+ const resolvedModel = init(payload); // We always outline this as a separate part even though we could inline it
483
+ // because it ensures a more deterministic encoding.
484
+
485
+ const lazyId = nextPartId++;
486
+ const partJSON = JSON.stringify(resolvedModel, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
487
+
488
+ const data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
489
+
490
+ data.append(formFieldPrefix + lazyId, partJSON);
491
+ return serializeByValueID(lazyId);
492
+ } catch (x) {
493
+ if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
494
+ // Suspended
495
+ pendingParts++;
496
+ const lazyId = nextPartId++;
497
+ const thenable = x;
498
+
499
+ const retry = function () {
500
+ // While the first promise resolved, its value isn't necessarily what we'll
501
+ // resolve into because we might suspend again.
502
+ try {
503
+ const partJSON = JSON.stringify(value, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
504
+
505
+ const data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
506
+
507
+ data.append(formFieldPrefix + lazyId, partJSON);
508
+ pendingParts--;
509
+
510
+ if (pendingParts === 0) {
511
+ resolve(data);
512
+ }
513
+ } catch (reason) {
514
+ reject(reason);
515
+ }
516
+ };
517
+
518
+ thenable.then(retry, retry);
519
+ return serializeByValueID(lazyId);
520
+ } else {
521
+ // In the future we could consider serializing this as an error
522
+ // that throws on the server instead.
523
+ reject(x);
524
+ return null;
525
+ }
526
+ } finally {
527
+ pendingParts--;
528
+ }
529
+ }
530
+ } // $FlowFixMe[method-unbinding]
531
+
532
+
533
+ if (typeof value.then === 'function') {
534
+ // We assume that any object with a .then property is a "Thenable" type,
535
+ // or a Promise type. Either of which can be represented by a Promise.
536
+ if (formData === null) {
537
+ // Upgrade to use FormData to allow us to stream this value.
538
+ formData = new FormData();
539
+ }
540
+
541
+ pendingParts++;
542
+ const promiseId = nextPartId++;
543
+ const thenable = value;
544
+ thenable.then(partValue => {
545
+ try {
546
+ const partJSON = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
547
+
548
+ const data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
549
+
550
+ data.append(formFieldPrefix + promiseId, partJSON);
551
+ pendingParts--;
552
+
553
+ if (pendingParts === 0) {
554
+ resolve(data);
555
+ }
556
+ } catch (reason) {
557
+ reject(reason);
558
+ }
559
+ }, reason => {
560
+ // In the future we could consider serializing this as an error
561
+ // that throws on the server instead.
562
+ reject(reason);
563
+ });
564
+ return serializePromiseID(promiseId);
565
+ }
566
+
567
+ if (isArray(value)) {
568
+ // $FlowFixMe[incompatible-return]
569
+ return value;
570
+ } // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
571
+
572
+
573
+ if (value instanceof FormData) {
574
+ if (formData === null) {
575
+ // Upgrade to use FormData to allow us to use rich objects as its values.
576
+ formData = new FormData();
577
+ }
578
+
579
+ const data = formData;
580
+ const refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
581
+ // These must come first in the form order because we assume that all the
582
+ // fields are available before this is referenced.
583
+
584
+ const prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
585
+
586
+ value.forEach((originalValue, originalKey) => {
587
+ data.append(prefix + originalKey, originalValue);
588
+ });
589
+ return serializeFormDataReference(refId);
590
+ }
591
+
592
+ if (value instanceof Map) {
593
+ const partJSON = JSON.stringify(Array.from(value), resolveToJSON);
594
+
595
+ if (formData === null) {
596
+ formData = new FormData();
597
+ }
598
+
599
+ const mapId = nextPartId++;
600
+ formData.append(formFieldPrefix + mapId, partJSON);
601
+ return serializeMapID(mapId);
602
+ }
603
+
604
+ if (value instanceof Set) {
605
+ const partJSON = JSON.stringify(Array.from(value), resolveToJSON);
606
+
607
+ if (formData === null) {
608
+ formData = new FormData();
609
+ }
610
+
611
+ const setId = nextPartId++;
612
+ formData.append(formFieldPrefix + setId, partJSON);
613
+ return serializeSetID(setId);
614
+ }
615
+
616
+ const iteratorFn = getIteratorFn(value);
617
+
618
+ if (iteratorFn) {
619
+ return Array.from(value);
620
+ } // Verify that this is a simple plain object.
621
+
622
+
623
+ const proto = getPrototypeOf(value);
624
+
625
+ if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
626
+ if (temporaryReferences === undefined) {
627
+ throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
628
+ } // We can serialize class instances as temporary references.
629
+
630
+
631
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
632
+ }
633
+
634
+
635
+ return value;
636
+ }
637
+
638
+ if (typeof value === 'string') {
639
+ // TODO: Maybe too clever. If we support URL there's no similar trick.
640
+ if (value[value.length - 1] === 'Z') {
641
+ // Possibly a Date, whose toJSON automatically calls toISOString
642
+ // $FlowFixMe[incompatible-use]
643
+ const originalValue = parent[key];
644
+
645
+ if (originalValue instanceof Date) {
646
+ return serializeDateFromDateJSON(value);
647
+ }
648
+ }
649
+
650
+ return escapeStringValue(value);
651
+ }
652
+
653
+ if (typeof value === 'boolean') {
654
+ return value;
655
+ }
656
+
657
+ if (typeof value === 'number') {
658
+ return serializeNumber(value);
659
+ }
660
+
661
+ if (typeof value === 'undefined') {
662
+ return serializeUndefined();
663
+ }
664
+
665
+ if (typeof value === 'function') {
666
+ const metaData = knownServerReferences.get(value);
667
+
668
+ if (metaData !== undefined) {
669
+ const metaDataJSON = JSON.stringify(metaData, resolveToJSON);
670
+
671
+ if (formData === null) {
672
+ // Upgrade to use FormData to allow us to stream this value.
673
+ formData = new FormData();
674
+ } // The reference to this function came from the same client so we can pass it back.
675
+
676
+
677
+ const refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
678
+
679
+ formData.set(formFieldPrefix + refId, metaDataJSON);
680
+ return serializeServerReferenceID(refId);
681
+ }
682
+
683
+ if (temporaryReferences === undefined) {
684
+ throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
685
+ }
686
+
687
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
688
+ }
689
+
690
+ if (typeof value === 'symbol') {
691
+ if (temporaryReferences === undefined) {
692
+ throw new Error('Symbols cannot be passed to a Server Function without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (''));
693
+ }
694
+
695
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
696
+ }
697
+
698
+ if (typeof value === 'bigint') {
699
+ return serializeBigInt(value);
700
+ }
701
+
702
+ throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
703
+ } // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
704
+
705
+
706
+ const json = JSON.stringify(root, resolveToJSON);
707
+
708
+ if (formData === null) {
709
+ // If it's a simple data structure, we just use plain JSON.
710
+ resolve(json);
711
+ } else {
712
+ // Otherwise, we use FormData to let us stream in the result.
713
+ formData.set(formFieldPrefix + '0', json);
714
+
715
+ if (pendingParts === 0) {
716
+ // $FlowFixMe[incompatible-call] this has already been refined.
717
+ resolve(formData);
718
+ }
719
+ }
720
+ }
721
+
722
+ function registerServerReference(proxy, reference, encodeFormAction) {
723
+
724
+ knownServerReferences.set(proxy, reference);
725
+ } // $FlowFixMe[method-unbinding]
726
+
727
+ function createServerReference(id, callServer, encodeFormAction) {
728
+ const proxy = function () {
729
+ // $FlowFixMe[method-unbinding]
730
+ const args = Array.prototype.slice.call(arguments);
731
+ return callServer(id, args);
732
+ };
733
+
734
+ registerServerReference(proxy, {
735
+ id,
736
+ bound: null
737
+ });
738
+ return proxy;
739
+ }
740
+
741
+ const ROW_ID = 0;
742
+ const ROW_TAG = 1;
743
+ const ROW_LENGTH = 2;
744
+ const ROW_CHUNK_BY_NEWLINE = 3;
745
+ const ROW_CHUNK_BY_LENGTH = 4;
746
+ const PENDING = 'pending';
747
+ const BLOCKED = 'blocked';
748
+ const CYCLIC = 'cyclic';
749
+ const RESOLVED_MODEL = 'resolved_model';
750
+ const RESOLVED_MODULE = 'resolved_module';
751
+ const INITIALIZED = 'fulfilled';
752
+ const ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
753
+
754
+ function Chunk(status, value, reason, response) {
755
+ this.status = status;
756
+ this.value = value;
757
+ this.reason = reason;
758
+ this._response = response;
759
+ } // We subclass Promise.prototype so that we get other methods like .catch
760
+
761
+
762
+ Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
763
+
764
+ Chunk.prototype.then = function (resolve, reject) {
765
+ const chunk = this; // If we have resolved content, we try to initialize it first which
766
+ // might put us back into one of the other states.
767
+
768
+ switch (chunk.status) {
769
+ case RESOLVED_MODEL:
770
+ initializeModelChunk(chunk);
771
+ break;
772
+
773
+ case RESOLVED_MODULE:
774
+ initializeModuleChunk(chunk);
775
+ break;
776
+ } // The status might have changed after initialization.
777
+
778
+
779
+ switch (chunk.status) {
780
+ case INITIALIZED:
781
+ resolve(chunk.value);
782
+ break;
783
+
784
+ case PENDING:
785
+ case BLOCKED:
786
+ case CYCLIC:
787
+ if (resolve) {
788
+ if (chunk.value === null) {
789
+ chunk.value = [];
790
+ }
791
+
792
+ chunk.value.push(resolve);
793
+ }
794
+
795
+ if (reject) {
796
+ if (chunk.reason === null) {
797
+ chunk.reason = [];
798
+ }
799
+
800
+ chunk.reason.push(reject);
801
+ }
802
+
803
+ break;
804
+
805
+ default:
806
+ reject(chunk.reason);
807
+ break;
808
+ }
809
+ };
810
+
811
+ function readChunk(chunk) {
812
+ // If we have resolved content, we try to initialize it first which
813
+ // might put us back into one of the other states.
814
+ switch (chunk.status) {
815
+ case RESOLVED_MODEL:
816
+ initializeModelChunk(chunk);
817
+ break;
818
+
819
+ case RESOLVED_MODULE:
820
+ initializeModuleChunk(chunk);
821
+ break;
822
+ } // The status might have changed after initialization.
823
+
824
+
825
+ switch (chunk.status) {
826
+ case INITIALIZED:
827
+ return chunk.value;
828
+
829
+ case PENDING:
830
+ case BLOCKED:
831
+ case CYCLIC:
832
+ // eslint-disable-next-line no-throw-literal
833
+ throw chunk;
834
+
835
+ default:
836
+ throw chunk.reason;
837
+ }
838
+ }
839
+
840
+ function getRoot(response) {
841
+ const chunk = getChunk(response, 0);
842
+ return chunk;
843
+ }
844
+
845
+ function createPendingChunk(response) {
846
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
847
+ return new Chunk(PENDING, null, null, response);
848
+ }
849
+
850
+ function createBlockedChunk(response) {
851
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
852
+ return new Chunk(BLOCKED, null, null, response);
853
+ }
854
+
855
+ function createErrorChunk(response, error) {
856
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
857
+ return new Chunk(ERRORED, null, error, response);
858
+ }
859
+
860
+ function wakeChunk(listeners, value) {
861
+ for (let i = 0; i < listeners.length; i++) {
862
+ const listener = listeners[i];
863
+ listener(value);
864
+ }
865
+ }
866
+
867
+ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
868
+ switch (chunk.status) {
869
+ case INITIALIZED:
870
+ wakeChunk(resolveListeners, chunk.value);
871
+ break;
872
+
873
+ case PENDING:
874
+ case BLOCKED:
875
+ case CYCLIC:
876
+ chunk.value = resolveListeners;
877
+ chunk.reason = rejectListeners;
878
+ break;
879
+
880
+ case ERRORED:
881
+ if (rejectListeners) {
882
+ wakeChunk(rejectListeners, chunk.reason);
883
+ }
884
+
885
+ break;
886
+ }
887
+ }
888
+
889
+ function triggerErrorOnChunk(chunk, error) {
890
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
891
+ // We already resolved. We didn't expect to see this.
892
+ return;
893
+ }
894
+
895
+ const listeners = chunk.reason;
896
+ const erroredChunk = chunk;
897
+ erroredChunk.status = ERRORED;
898
+ erroredChunk.reason = error;
899
+
900
+ if (listeners !== null) {
901
+ wakeChunk(listeners, error);
902
+ }
903
+ }
904
+
905
+ function createResolvedModelChunk(response, value) {
906
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
907
+ return new Chunk(RESOLVED_MODEL, value, null, response);
908
+ }
909
+
910
+ function createResolvedModuleChunk(response, value) {
911
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
912
+ return new Chunk(RESOLVED_MODULE, value, null, response);
913
+ }
914
+
915
+ function createInitializedTextChunk(response, value) {
916
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
917
+ return new Chunk(INITIALIZED, value, null, response);
918
+ }
919
+
920
+ function resolveModelChunk(chunk, value) {
921
+ if (chunk.status !== PENDING) {
922
+ // We already resolved. We didn't expect to see this.
923
+ return;
924
+ }
925
+
926
+ const resolveListeners = chunk.value;
927
+ const rejectListeners = chunk.reason;
928
+ const resolvedChunk = chunk;
929
+ resolvedChunk.status = RESOLVED_MODEL;
930
+ resolvedChunk.value = value;
931
+
932
+ if (resolveListeners !== null) {
933
+ // This is unfortunate that we're reading this eagerly if
934
+ // we already have listeners attached since they might no
935
+ // longer be rendered or might not be the highest pri.
936
+ initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
937
+
938
+ wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
939
+ }
940
+ }
941
+
942
+ function resolveModuleChunk(chunk, value) {
943
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
944
+ // We already resolved. We didn't expect to see this.
945
+ return;
946
+ }
947
+
948
+ const resolveListeners = chunk.value;
949
+ const rejectListeners = chunk.reason;
950
+ const resolvedChunk = chunk;
951
+ resolvedChunk.status = RESOLVED_MODULE;
952
+ resolvedChunk.value = value;
953
+
954
+ if (resolveListeners !== null) {
955
+ initializeModuleChunk(resolvedChunk);
956
+ wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
957
+ }
958
+ }
959
+
960
+ let initializingChunk = null;
961
+ let initializingChunkBlockedModel = null;
962
+
963
+ function initializeModelChunk(chunk) {
964
+ const prevChunk = initializingChunk;
965
+ const prevBlocked = initializingChunkBlockedModel;
966
+ initializingChunk = chunk;
967
+ initializingChunkBlockedModel = null;
968
+ const resolvedModel = chunk.value; // We go to the CYCLIC state until we've fully resolved this.
969
+ // We do this before parsing in case we try to initialize the same chunk
970
+ // while parsing the model. Such as in a cyclic reference.
971
+
972
+ const cyclicChunk = chunk;
973
+ cyclicChunk.status = CYCLIC;
974
+ cyclicChunk.value = null;
975
+ cyclicChunk.reason = null;
976
+
977
+ try {
978
+ const value = parseModel(chunk._response, resolvedModel);
979
+
980
+ if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
981
+ initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
982
+ // We have to go the BLOCKED state until they're resolved.
983
+
984
+ const blockedChunk = chunk;
985
+ blockedChunk.status = BLOCKED;
986
+ blockedChunk.value = null;
987
+ blockedChunk.reason = null;
988
+ } else {
989
+ const resolveListeners = cyclicChunk.value;
990
+ const initializedChunk = chunk;
991
+ initializedChunk.status = INITIALIZED;
992
+ initializedChunk.value = value;
993
+
994
+ if (resolveListeners !== null) {
995
+ wakeChunk(resolveListeners, value);
996
+ }
997
+ }
998
+ } catch (error) {
999
+ const erroredChunk = chunk;
1000
+ erroredChunk.status = ERRORED;
1001
+ erroredChunk.reason = error;
1002
+ } finally {
1003
+ initializingChunk = prevChunk;
1004
+ initializingChunkBlockedModel = prevBlocked;
1005
+ }
1006
+ }
1007
+
1008
+ function initializeModuleChunk(chunk) {
1009
+ try {
1010
+ const value = requireModule(chunk.value);
1011
+ const initializedChunk = chunk;
1012
+ initializedChunk.status = INITIALIZED;
1013
+ initializedChunk.value = value;
1014
+ } catch (error) {
1015
+ const erroredChunk = chunk;
1016
+ erroredChunk.status = ERRORED;
1017
+ erroredChunk.reason = error;
1018
+ }
1019
+ } // Report that any missing chunks in the model is now going to throw this
1020
+ // error upon read. Also notify any pending promises.
1021
+
1022
+
1023
+ function reportGlobalError(response, error) {
1024
+ response._chunks.forEach(chunk => {
1025
+ // If this chunk was already resolved or errored, it won't
1026
+ // trigger an error but if it wasn't then we need to
1027
+ // because we won't be getting any new data to resolve it.
1028
+ if (chunk.status === PENDING) {
1029
+ triggerErrorOnChunk(chunk, error);
1030
+ }
1031
+ });
1032
+ }
1033
+
1034
+ function createElement(type, key, props) {
1035
+ let element;
1036
+
1037
+ {
1038
+ element = {
1039
+ // This tag allows us to uniquely identify this as a React Element
1040
+ $$typeof: REACT_ELEMENT_TYPE,
1041
+ type,
1042
+ key,
1043
+ ref: null,
1044
+ props,
1045
+ // Record the component responsible for creating this element.
1046
+ _owner: null
1047
+ };
1048
+ }
1049
+
1050
+ return element;
1051
+ }
1052
+
1053
+ function createLazyChunkWrapper(chunk) {
1054
+ const lazyType = {
1055
+ $$typeof: REACT_LAZY_TYPE,
1056
+ _payload: chunk,
1057
+ _init: readChunk
1058
+ };
1059
+
1060
+ return lazyType;
1061
+ }
1062
+
1063
+ function getChunk(response, id) {
1064
+ const chunks = response._chunks;
1065
+ let chunk = chunks.get(id);
1066
+
1067
+ if (!chunk) {
1068
+ chunk = createPendingChunk(response);
1069
+ chunks.set(id, chunk);
1070
+ }
1071
+
1072
+ return chunk;
1073
+ }
1074
+
1075
+ function createModelResolver(chunk, parentObject, key, cyclic) {
1076
+ let blocked;
1077
+
1078
+ if (initializingChunkBlockedModel) {
1079
+ blocked = initializingChunkBlockedModel;
1080
+
1081
+ if (!cyclic) {
1082
+ blocked.deps++;
1083
+ }
1084
+ } else {
1085
+ blocked = initializingChunkBlockedModel = {
1086
+ deps: cyclic ? 0 : 1,
1087
+ value: null
1088
+ };
1089
+ }
1090
+
1091
+ return value => {
1092
+ parentObject[key] = value;
1093
+ blocked.deps--;
1094
+
1095
+ if (blocked.deps === 0) {
1096
+ if (chunk.status !== BLOCKED) {
1097
+ return;
1098
+ }
1099
+
1100
+ const resolveListeners = chunk.value;
1101
+ const initializedChunk = chunk;
1102
+ initializedChunk.status = INITIALIZED;
1103
+ initializedChunk.value = blocked.value;
1104
+
1105
+ if (resolveListeners !== null) {
1106
+ wakeChunk(resolveListeners, blocked.value);
1107
+ }
1108
+ }
1109
+ };
1110
+ }
1111
+
1112
+ function createModelReject(chunk) {
1113
+ return error => triggerErrorOnChunk(chunk, error);
1114
+ }
1115
+
1116
+ function createServerReferenceProxy(response, metaData) {
1117
+ const callServer = response._callServer;
1118
+
1119
+ const proxy = function () {
1120
+ // $FlowFixMe[method-unbinding]
1121
+ const args = Array.prototype.slice.call(arguments);
1122
+ const p = metaData.bound;
1123
+
1124
+ if (!p) {
1125
+ return callServer(metaData.id, args);
1126
+ }
1127
+
1128
+ if (p.status === INITIALIZED) {
1129
+ const bound = p.value;
1130
+ return callServer(metaData.id, bound.concat(args));
1131
+ } // Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
1132
+ // TODO: Remove the wrapper once that's fixed.
1133
+
1134
+
1135
+ return Promise.resolve(p).then(function (bound) {
1136
+ return callServer(metaData.id, bound.concat(args));
1137
+ });
1138
+ };
1139
+
1140
+ registerServerReference(proxy, metaData);
1141
+ return proxy;
1142
+ }
1143
+
1144
+ function getOutlinedModel(response, id) {
1145
+ const chunk = getChunk(response, id);
1146
+
1147
+ switch (chunk.status) {
1148
+ case RESOLVED_MODEL:
1149
+ initializeModelChunk(chunk);
1150
+ break;
1151
+ } // The status might have changed after initialization.
1152
+
1153
+
1154
+ switch (chunk.status) {
1155
+ case INITIALIZED:
1156
+ {
1157
+ return chunk.value;
1158
+ }
1159
+ // We always encode it first in the stream so it won't be pending.
1160
+
1161
+ default:
1162
+ throw chunk.reason;
1163
+ }
1164
+ }
1165
+
1166
+ function parseModelString(response, parentObject, key, value) {
1167
+ if (value[0] === '$') {
1168
+ if (value === '$') {
1169
+ // A very common symbol.
1170
+ return REACT_ELEMENT_TYPE;
1171
+ }
1172
+
1173
+ switch (value[1]) {
1174
+ case '$':
1175
+ {
1176
+ // This was an escaped string value.
1177
+ return value.slice(1);
1178
+ }
1179
+
1180
+ case 'L':
1181
+ {
1182
+ // Lazy node
1183
+ const id = parseInt(value.slice(2), 16);
1184
+ const chunk = getChunk(response, id); // We create a React.lazy wrapper around any lazy values.
1185
+ // When passed into React, we'll know how to suspend on this.
1186
+
1187
+ return createLazyChunkWrapper(chunk);
1188
+ }
1189
+
1190
+ case '@':
1191
+ {
1192
+ // Promise
1193
+ if (value.length === 2) {
1194
+ // Infinite promise that never resolves.
1195
+ return new Promise(() => {});
1196
+ }
1197
+
1198
+ const id = parseInt(value.slice(2), 16);
1199
+ const chunk = getChunk(response, id);
1200
+ return chunk;
1201
+ }
1202
+
1203
+ case 'S':
1204
+ {
1205
+ // Symbol
1206
+ return Symbol.for(value.slice(2));
1207
+ }
1208
+
1209
+ case 'F':
1210
+ {
1211
+ // Server Reference
1212
+ const id = parseInt(value.slice(2), 16);
1213
+ const metadata = getOutlinedModel(response, id);
1214
+ return createServerReferenceProxy(response, metadata);
1215
+ }
1216
+
1217
+ case 'T':
1218
+ {
1219
+ // Temporary Reference
1220
+ const id = parseInt(value.slice(2), 16);
1221
+ const temporaryReferences = response._tempRefs;
1222
+
1223
+ if (temporaryReferences == null) {
1224
+ 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.');
1225
+ }
1226
+
1227
+ return readTemporaryReference(temporaryReferences, id);
1228
+ }
1229
+
1230
+ case 'Q':
1231
+ {
1232
+ // Map
1233
+ const id = parseInt(value.slice(2), 16);
1234
+ const data = getOutlinedModel(response, id);
1235
+ return new Map(data);
1236
+ }
1237
+
1238
+ case 'W':
1239
+ {
1240
+ // Set
1241
+ const id = parseInt(value.slice(2), 16);
1242
+ const data = getOutlinedModel(response, id);
1243
+ return new Set(data);
1244
+ }
1245
+
1246
+ case 'I':
1247
+ {
1248
+ // $Infinity
1249
+ return Infinity;
1250
+ }
1251
+
1252
+ case '-':
1253
+ {
1254
+ // $-0 or $-Infinity
1255
+ if (value === '$-0') {
1256
+ return -0;
1257
+ } else {
1258
+ return -Infinity;
1259
+ }
1260
+ }
1261
+
1262
+ case 'N':
1263
+ {
1264
+ // $NaN
1265
+ return NaN;
1266
+ }
1267
+
1268
+ case 'u':
1269
+ {
1270
+ // matches "$undefined"
1271
+ // Special encoding for `undefined` which can't be serialized as JSON otherwise.
1272
+ return undefined;
1273
+ }
1274
+
1275
+ case 'D':
1276
+ {
1277
+ // Date
1278
+ return new Date(Date.parse(value.slice(2)));
1279
+ }
1280
+
1281
+ case 'n':
1282
+ {
1283
+ // BigInt
1284
+ return BigInt(value.slice(2));
1285
+ }
1286
+
1287
+ case 'E':
1288
+
1289
+ default:
1290
+ {
1291
+ // We assume that anything else is a reference ID.
1292
+ const id = parseInt(value.slice(1), 16);
1293
+ const chunk = getChunk(response, id);
1294
+
1295
+ switch (chunk.status) {
1296
+ case RESOLVED_MODEL:
1297
+ initializeModelChunk(chunk);
1298
+ break;
1299
+
1300
+ case RESOLVED_MODULE:
1301
+ initializeModuleChunk(chunk);
1302
+ break;
1303
+ } // The status might have changed after initialization.
1304
+
1305
+
1306
+ switch (chunk.status) {
1307
+ case INITIALIZED:
1308
+ const chunkValue = chunk.value;
1309
+
1310
+ return chunkValue;
1311
+
1312
+ case PENDING:
1313
+ case BLOCKED:
1314
+ case CYCLIC:
1315
+ const parentChunk = initializingChunk;
1316
+ chunk.then(createModelResolver(parentChunk, parentObject, key, chunk.status === CYCLIC), createModelReject(parentChunk));
1317
+ return null;
1318
+
1319
+ default:
1320
+ throw chunk.reason;
1321
+ }
1322
+ }
1323
+ }
1324
+ }
1325
+
1326
+ return value;
1327
+ }
1328
+
1329
+ function parseModelTuple(response, value) {
1330
+ const tuple = value;
1331
+
1332
+ if (tuple[0] === REACT_ELEMENT_TYPE) {
1333
+ // TODO: Consider having React just directly accept these arrays as elements.
1334
+ // Or even change the ReactElement type to be an array.
1335
+ return createElement(tuple[1], tuple[2], tuple[3]);
1336
+ }
1337
+
1338
+ return value;
1339
+ }
1340
+
1341
+ function missingCall() {
1342
+ throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
1343
+ }
1344
+
1345
+ function createResponse(bundlerConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences) {
1346
+ const chunks = new Map();
1347
+ const response = {
1348
+ _bundlerConfig: bundlerConfig,
1349
+ _moduleLoading: moduleLoading,
1350
+ _callServer: callServer !== undefined ? callServer : missingCall,
1351
+ _encodeFormAction: encodeFormAction,
1352
+ _nonce: nonce,
1353
+ _chunks: chunks,
1354
+ _stringDecoder: createStringDecoder(),
1355
+ _fromJSON: null,
1356
+ _rowState: 0,
1357
+ _rowID: 0,
1358
+ _rowTag: 0,
1359
+ _rowLength: 0,
1360
+ _buffer: [],
1361
+ _tempRefs: temporaryReferences
1362
+ }; // Don't inline this call because it causes closure to outline the call above.
1363
+
1364
+ response._fromJSON = createFromJSONCallback(response);
1365
+ return response;
1366
+ }
1367
+
1368
+ function resolveModel(response, id, model) {
1369
+ const chunks = response._chunks;
1370
+ const chunk = chunks.get(id);
1371
+
1372
+ if (!chunk) {
1373
+ chunks.set(id, createResolvedModelChunk(response, model));
1374
+ } else {
1375
+ resolveModelChunk(chunk, model);
1376
+ }
1377
+ }
1378
+
1379
+ function resolveText(response, id, text) {
1380
+ const chunks = response._chunks; // We assume that we always reference large strings after they've been
1381
+ // emitted.
1382
+
1383
+ chunks.set(id, createInitializedTextChunk(response, text));
1384
+ }
1385
+
1386
+ function resolveModule(response, id, model) {
1387
+ const chunks = response._chunks;
1388
+ const chunk = chunks.get(id);
1389
+ const clientReferenceMetadata = parseModel(response, model);
1390
+ const clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
1391
+ // For now we preload all modules as early as possible since it's likely
1392
+ // that we'll need them.
1393
+
1394
+ const promise = preloadModule(clientReference);
1395
+
1396
+ if (promise) {
1397
+ let blockedChunk;
1398
+
1399
+ if (!chunk) {
1400
+ // Technically, we should just treat promise as the chunk in this
1401
+ // case. Because it'll just behave as any other promise.
1402
+ blockedChunk = createBlockedChunk(response);
1403
+ chunks.set(id, blockedChunk);
1404
+ } else {
1405
+ // This can't actually happen because we don't have any forward
1406
+ // references to modules.
1407
+ blockedChunk = chunk;
1408
+ blockedChunk.status = BLOCKED;
1409
+ }
1410
+
1411
+ promise.then(() => resolveModuleChunk(blockedChunk, clientReference), error => triggerErrorOnChunk(blockedChunk, error));
1412
+ } else {
1413
+ if (!chunk) {
1414
+ chunks.set(id, createResolvedModuleChunk(response, clientReference));
1415
+ } else {
1416
+ // This can't actually happen because we don't have any forward
1417
+ // references to modules.
1418
+ resolveModuleChunk(chunk, clientReference);
1419
+ }
1420
+ }
1421
+ }
1422
+
1423
+ function resolveErrorProd(response, id, digest) {
1424
+
1425
+ const error = new Error('An error occurred in the Server Components render. The specific message is omitted in production' + ' builds to avoid leaking sensitive details. A digest property is included on this error instance which' + ' may provide additional details about the nature of the error.');
1426
+ error.stack = 'Error: ' + error.message;
1427
+ error.digest = digest;
1428
+ const errorWithDigest = error;
1429
+ const chunks = response._chunks;
1430
+ const chunk = chunks.get(id);
1431
+
1432
+ if (!chunk) {
1433
+ chunks.set(id, createErrorChunk(response, errorWithDigest));
1434
+ } else {
1435
+ triggerErrorOnChunk(chunk, errorWithDigest);
1436
+ }
1437
+ }
1438
+
1439
+ function resolveHint(response, code, model) {
1440
+ const hintModel = parseModel(response, model);
1441
+ dispatchHint(code, hintModel);
1442
+ }
1443
+
1444
+ function processFullRow(response, id, tag, buffer, chunk) {
1445
+
1446
+ const stringDecoder = response._stringDecoder;
1447
+ let row = '';
1448
+
1449
+ for (let i = 0; i < buffer.length; i++) {
1450
+ row += readPartialStringChunk(stringDecoder, buffer[i]);
1451
+ }
1452
+
1453
+ row += readFinalStringChunk(stringDecoder, chunk);
1454
+
1455
+ switch (tag) {
1456
+ case 73
1457
+ /* "I" */
1458
+ :
1459
+ {
1460
+ resolveModule(response, id, row);
1461
+ return;
1462
+ }
1463
+
1464
+ case 72
1465
+ /* "H" */
1466
+ :
1467
+ {
1468
+ const code = row[0];
1469
+ resolveHint(response, code, row.slice(1));
1470
+ return;
1471
+ }
1472
+
1473
+ case 69
1474
+ /* "E" */
1475
+ :
1476
+ {
1477
+ const errorInfo = JSON.parse(row);
1478
+
1479
+ {
1480
+ resolveErrorProd(response, id, errorInfo.digest);
1481
+ }
1482
+
1483
+ return;
1484
+ }
1485
+
1486
+ case 84
1487
+ /* "T" */
1488
+ :
1489
+ {
1490
+ resolveText(response, id, row);
1491
+ return;
1492
+ }
1493
+
1494
+ case 68
1495
+ /* "D" */
1496
+ :
1497
+
1498
+ case 87
1499
+ /* "W" */
1500
+ :
1501
+ {
1502
+
1503
+ throw new Error('Failed to read a RSC payload created by a development version of React ' + 'on the server while using a production version on the client. Always use ' + 'matching versions on the server and the client.');
1504
+ }
1505
+
1506
+ case 80
1507
+ /* "P" */
1508
+ :
1509
+ // Fallthrough
1510
+
1511
+ default:
1512
+ /* """ "{" "[" "t" "f" "n" "0" - "9" */
1513
+ {
1514
+ // We assume anything else is JSON.
1515
+ resolveModel(response, id, row);
1516
+ return;
1517
+ }
1518
+ }
1519
+ }
1520
+
1521
+ function processBinaryChunk(response, chunk) {
1522
+ let i = 0;
1523
+ let rowState = response._rowState;
1524
+ let rowID = response._rowID;
1525
+ let rowTag = response._rowTag;
1526
+ let rowLength = response._rowLength;
1527
+ const buffer = response._buffer;
1528
+ const chunkLength = chunk.length;
1529
+
1530
+ while (i < chunkLength) {
1531
+ let lastIdx = -1;
1532
+
1533
+ switch (rowState) {
1534
+ case ROW_ID:
1535
+ {
1536
+ const byte = chunk[i++];
1537
+
1538
+ if (byte === 58
1539
+ /* ":" */
1540
+ ) {
1541
+ // Finished the rowID, next we'll parse the tag.
1542
+ rowState = ROW_TAG;
1543
+ } else {
1544
+ rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
1545
+ }
1546
+
1547
+ continue;
1548
+ }
1549
+
1550
+ case ROW_TAG:
1551
+ {
1552
+ const resolvedRowTag = chunk[i];
1553
+
1554
+ if (resolvedRowTag === 84
1555
+ /* "T" */
1556
+ || enableBinaryFlight
1557
+ /* "V" */
1558
+ ) {
1559
+ rowTag = resolvedRowTag;
1560
+ rowState = ROW_LENGTH;
1561
+ i++;
1562
+ } else if (resolvedRowTag > 64 && resolvedRowTag < 91
1563
+ /* "A"-"Z" */
1564
+ ) {
1565
+ rowTag = resolvedRowTag;
1566
+ rowState = ROW_CHUNK_BY_NEWLINE;
1567
+ i++;
1568
+ } else {
1569
+ rowTag = 0;
1570
+ rowState = ROW_CHUNK_BY_NEWLINE; // This was an unknown tag so it was probably part of the data.
1571
+ }
1572
+
1573
+ continue;
1574
+ }
1575
+
1576
+ case ROW_LENGTH:
1577
+ {
1578
+ const byte = chunk[i++];
1579
+
1580
+ if (byte === 44
1581
+ /* "," */
1582
+ ) {
1583
+ // Finished the rowLength, next we'll buffer up to that length.
1584
+ rowState = ROW_CHUNK_BY_LENGTH;
1585
+ } else {
1586
+ rowLength = rowLength << 4 | (byte > 96 ? byte - 87 : byte - 48);
1587
+ }
1588
+
1589
+ continue;
1590
+ }
1591
+
1592
+ case ROW_CHUNK_BY_NEWLINE:
1593
+ {
1594
+ // We're looking for a newline
1595
+ lastIdx = chunk.indexOf(10
1596
+ /* "\n" */
1597
+ , i);
1598
+ break;
1599
+ }
1600
+
1601
+ case ROW_CHUNK_BY_LENGTH:
1602
+ {
1603
+ // We're looking for the remaining byte length
1604
+ lastIdx = i + rowLength;
1605
+
1606
+ if (lastIdx > chunk.length) {
1607
+ lastIdx = -1;
1608
+ }
1609
+
1610
+ break;
1611
+ }
1612
+ }
1613
+
1614
+ const offset = chunk.byteOffset + i;
1615
+
1616
+ if (lastIdx > -1) {
1617
+ // We found the last chunk of the row
1618
+ const length = lastIdx - i;
1619
+ const lastChunk = new Uint8Array(chunk.buffer, offset, length);
1620
+ processFullRow(response, rowID, rowTag, buffer, lastChunk); // Reset state machine for a new row
1621
+
1622
+ i = lastIdx;
1623
+
1624
+ if (rowState === ROW_CHUNK_BY_NEWLINE) {
1625
+ // If we're trailing by a newline we need to skip it.
1626
+ i++;
1627
+ }
1628
+
1629
+ rowState = ROW_ID;
1630
+ rowTag = 0;
1631
+ rowID = 0;
1632
+ rowLength = 0;
1633
+ buffer.length = 0;
1634
+ } else {
1635
+ // The rest of this row is in a future chunk. We stash the rest of the
1636
+ // current chunk until we can process the full row.
1637
+ const length = chunk.byteLength - i;
1638
+ const remainingSlice = new Uint8Array(chunk.buffer, offset, length);
1639
+ buffer.push(remainingSlice); // Update how many bytes we're still waiting for. If we're looking for
1640
+ // a newline, this doesn't hurt since we'll just ignore it.
1641
+
1642
+ rowLength -= remainingSlice.byteLength;
1643
+ break;
1644
+ }
1645
+ }
1646
+
1647
+ response._rowState = rowState;
1648
+ response._rowID = rowID;
1649
+ response._rowTag = rowTag;
1650
+ response._rowLength = rowLength;
1651
+ }
1652
+
1653
+ function parseModel(response, json) {
1654
+ return JSON.parse(json, response._fromJSON);
1655
+ }
1656
+
1657
+ function createFromJSONCallback(response) {
1658
+ // $FlowFixMe[missing-this-annot]
1659
+ return function (key, value) {
1660
+ if (typeof value === 'string') {
1661
+ // We can't use .bind here because we need the "this" value.
1662
+ return parseModelString(response, this, key, value);
1663
+ }
1664
+
1665
+ if (typeof value === 'object' && value !== null) {
1666
+ return parseModelTuple(response, value);
1667
+ }
1668
+
1669
+ return value;
1670
+ };
1671
+ }
1672
+
1673
+ function close(response) {
1674
+ // In case there are any remaining unresolved chunks, they won't
1675
+ // be resolved now. So we need to issue an error to those.
1676
+ // Ideally we should be able to early bail out if we kept a
1677
+ // ref count of pending chunks.
1678
+ reportGlobalError(response, new Error('Connection closed.'));
1679
+ }
1680
+
1681
+ function createResponseFromOptions(options) {
1682
+ return createResponse(null, null, options && options.callServer ? options.callServer : undefined, undefined, // encodeFormAction
1683
+ undefined, // nonce
1684
+ options && options.temporaryReferences ? options.temporaryReferences : undefined);
1685
+ }
1686
+
1687
+ function startReadingFromStream(response, stream) {
1688
+ const reader = stream.getReader();
1689
+
1690
+ function progress(_ref) {
1691
+ let done = _ref.done,
1692
+ value = _ref.value;
1693
+
1694
+ if (done) {
1695
+ close(response);
1696
+ return;
1697
+ }
1698
+
1699
+ const buffer = value;
1700
+ processBinaryChunk(response, buffer);
1701
+ return reader.read().then(progress).catch(error);
1702
+ }
1703
+
1704
+ function error(e) {
1705
+ reportGlobalError(response, e);
1706
+ }
1707
+
1708
+ reader.read().then(progress).catch(error);
1709
+ }
1710
+
1711
+ function createFromReadableStream(stream, options) {
1712
+ const response = createResponseFromOptions(options);
1713
+ startReadingFromStream(response, stream);
1714
+ return getRoot(response);
1715
+ }
1716
+
1717
+ function createFromFetch(promiseForResponse, options) {
1718
+ const response = createResponseFromOptions(options);
1719
+ promiseForResponse.then(function (r) {
1720
+ startReadingFromStream(response, r.body);
1721
+ }, function (e) {
1722
+ reportGlobalError(response, e);
1723
+ });
1724
+ return getRoot(response);
1725
+ }
1726
+
1727
+ function encodeReply(value, options)
1728
+ /* We don't use URLSearchParams yet but maybe */
1729
+ {
1730
+ return new Promise((resolve, reject) => {
1731
+ processReply(value, '', options && options.temporaryReferences ? options.temporaryReferences : undefined, resolve, reject);
1732
+ });
1733
+ }
1734
+
1735
+ exports.createFromFetch = createFromFetch;
1736
+ exports.createFromReadableStream = createFromReadableStream;
1737
+ exports.createServerReference = createServerReference;
1738
+ exports.createTemporaryReferenceSet = createTemporaryReferenceSet;
1739
+ exports.encodeReply = encodeReply;