react-server-dom-webpack 18.3.0-next-fa4314841-20230502 → 19.0.0-canary-2b036d3f1-20240327

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
@@ -7,12 +7,16 @@
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
+
10
11
  (function (global, factory) {
11
12
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react-dom'), require('react')) :
12
13
  typeof define === 'function' && define.amd ? define(['exports', 'react-dom', 'react'], factory) :
13
14
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactServerDOMClient = {}, global.ReactDOM, global.React));
14
15
  })(this, (function (exports, ReactDOM, React) { 'use strict';
15
16
 
17
+ // -----------------------------------------------------------------------------
18
+ var enableBinaryFlight = false;
19
+
16
20
  function createStringDecoder() {
17
21
  return new TextDecoder();
18
22
  }
@@ -26,15 +30,66 @@
26
30
  return decoder.decode(buffer);
27
31
  }
28
32
 
29
- function parseModel(response, json) {
30
- return JSON.parse(json, response._fromJSON);
33
+ var badgeFormat = '%c%s%c '; // Same badge styling as DevTools.
34
+
35
+ var badgeStyle = // We use a fixed background if light-dark is not supported, otherwise
36
+ // we use a transparent background.
37
+ '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';
38
+ var resetStyle = '';
39
+ var pad = ' ';
40
+ function printToConsole(methodName, args, badgeName) {
41
+ var offset = 0;
42
+
43
+ switch (methodName) {
44
+ case 'dir':
45
+ case 'dirxml':
46
+ case 'groupEnd':
47
+ case 'table':
48
+ {
49
+ // These methods cannot be colorized because they don't take a formatting string.
50
+ // eslint-disable-next-line react-internal/no-production-logging
51
+ console[methodName].apply(console, args);
52
+ return;
53
+ }
54
+
55
+ case 'assert':
56
+ {
57
+ // assert takes formatting options as the second argument.
58
+ offset = 1;
59
+ }
60
+ }
61
+
62
+ var newArgs = args.slice(0);
63
+
64
+ if (typeof newArgs[offset] === 'string') {
65
+ newArgs.splice(offset, 1, badgeFormat + newArgs[offset], badgeStyle, pad + badgeName + pad, resetStyle);
66
+ } else {
67
+ newArgs.splice(offset, 0, badgeFormat, badgeStyle, pad + badgeName + pad, resetStyle);
68
+ } // eslint-disable-next-line react-internal/no-production-logging
69
+
70
+
71
+ console[methodName].apply(console, newArgs);
72
+ return;
73
+ }
74
+
75
+ // This is the parsed shape of the wire format which is why it is
76
+ // condensed to only the essentialy information
77
+ var ID = 0;
78
+ var CHUNKS = 1;
79
+ var NAME = 2; // export const ASYNC = 3;
80
+ // This logic is correct because currently only include the 4th tuple member
81
+ // when the module is async. If that changes we will need to actually assert
82
+ // the value is true. We don't index into the 4th slot because flow does not
83
+ // like the potential out of bounds access
84
+
85
+ function isAsyncImport(metadata) {
86
+ return metadata.length === 4;
31
87
  }
32
88
 
33
- // eslint-disable-next-line no-unused-vars
34
89
  function resolveClientReference(bundlerConfig, metadata) {
35
90
  if (bundlerConfig) {
36
- var moduleExports = bundlerConfig[metadata.id];
37
- var resolvedModuleData = moduleExports[metadata.name];
91
+ var moduleExports = bundlerConfig[metadata[ID]];
92
+ var resolvedModuleData = moduleExports[metadata[NAME]];
38
93
  var name;
39
94
 
40
95
  if (resolvedModuleData) {
@@ -45,18 +100,19 @@
45
100
  resolvedModuleData = moduleExports['*'];
46
101
 
47
102
  if (!resolvedModuleData) {
48
- 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.');
103
+ 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.');
49
104
  }
50
105
 
51
- name = metadata.name;
106
+ name = metadata[NAME];
52
107
  }
53
108
 
54
- return {
55
- id: resolvedModuleData.id,
56
- chunks: resolvedModuleData.chunks,
57
- name: name,
58
- async: !!metadata.async
59
- };
109
+ if (isAsyncImport(metadata)) {
110
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1
111
+ /* async */
112
+ ];
113
+ } else {
114
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
115
+ }
60
116
  }
61
117
 
62
118
  return metadata;
@@ -66,7 +122,31 @@
66
122
  // replicate it in user space. null means that it has already loaded.
67
123
 
68
124
  var chunkCache = new Map();
69
- var asyncModuleCache = new Map();
125
+
126
+ function requireAsyncModule(id) {
127
+ // We've already loaded all the chunks. We can require the module.
128
+ var promise = __webpack_require__(id);
129
+
130
+ if (typeof promise.then !== 'function') {
131
+ // This wasn't a promise after all.
132
+ return null;
133
+ } else if (promise.status === 'fulfilled') {
134
+ // This module was already resolved earlier.
135
+ return null;
136
+ } else {
137
+ // Instrument the Promise to stash the result.
138
+ promise.then(function (value) {
139
+ var fulfilledThenable = promise;
140
+ fulfilledThenable.status = 'fulfilled';
141
+ fulfilledThenable.value = value;
142
+ }, function (reason) {
143
+ var rejectedThenable = promise;
144
+ rejectedThenable.status = 'rejected';
145
+ rejectedThenable.reason = reason;
146
+ });
147
+ return promise;
148
+ }
149
+ }
70
150
 
71
151
  function ignoreReject() {// We rely on rejected promises to be handled by another listener.
72
152
  } // Start preloading the modules since we might need them soon.
@@ -74,16 +154,17 @@
74
154
 
75
155
 
76
156
  function preloadModule(metadata) {
77
- var chunks = metadata.chunks;
157
+ var chunks = metadata[CHUNKS];
78
158
  var promises = [];
159
+ var i = 0;
79
160
 
80
- for (var i = 0; i < chunks.length; i++) {
81
- var chunkId = chunks[i];
161
+ while (i < chunks.length) {
162
+ var chunkId = chunks[i++];
163
+ var chunkFilename = chunks[i++];
82
164
  var entry = chunkCache.get(chunkId);
83
165
 
84
166
  if (entry === undefined) {
85
- var thenable = __webpack_chunk_load__(chunkId);
86
-
167
+ var thenable = loadChunk(chunkId, chunkFilename);
87
168
  promises.push(thenable); // $FlowFixMe[method-unbinding]
88
169
 
89
170
  var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
@@ -94,30 +175,13 @@
94
175
  }
95
176
  }
96
177
 
97
- if (metadata.async) {
98
- var existingPromise = asyncModuleCache.get(metadata.id);
99
-
100
- if (existingPromise) {
101
- if (existingPromise.status === 'fulfilled') {
102
- return null;
103
- }
104
-
105
- return existingPromise;
178
+ if (isAsyncImport(metadata)) {
179
+ if (promises.length === 0) {
180
+ return requireAsyncModule(metadata[ID]);
106
181
  } else {
107
- var modulePromise = Promise.all(promises).then(function () {
108
- return __webpack_require__(metadata.id);
182
+ return Promise.all(promises).then(function () {
183
+ return requireAsyncModule(metadata[ID]);
109
184
  });
110
- modulePromise.then(function (value) {
111
- var fulfilledThenable = modulePromise;
112
- fulfilledThenable.status = 'fulfilled';
113
- fulfilledThenable.value = value;
114
- }, function (reason) {
115
- var rejectedThenable = modulePromise;
116
- rejectedThenable.status = 'rejected';
117
- rejectedThenable.reason = reason;
118
- });
119
- asyncModuleCache.set(metadata.id, modulePromise);
120
- return modulePromise;
121
185
  }
122
186
  } else if (promises.length > 0) {
123
187
  return Promise.all(promises);
@@ -128,101 +192,215 @@
128
192
  // Increase priority if necessary.
129
193
 
130
194
  function requireModule(metadata) {
131
- var moduleExports;
132
-
133
- if (metadata.async) {
134
- // We assume that preloadModule has been called before, which
135
- // should have added something to the module cache.
136
- var promise = asyncModuleCache.get(metadata.id);
195
+ var moduleExports = __webpack_require__(metadata[ID]);
137
196
 
138
- if (promise.status === 'fulfilled') {
139
- moduleExports = promise.value;
197
+ if (isAsyncImport(metadata)) {
198
+ if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
199
+ // This Promise should've been instrumented by preloadModule.
200
+ moduleExports = moduleExports.value;
140
201
  } else {
141
- throw promise.reason;
202
+ throw moduleExports.reason;
142
203
  }
143
- } else {
144
- moduleExports = __webpack_require__(metadata.id);
145
204
  }
146
205
 
147
- if (metadata.name === '*') {
206
+ if (metadata[NAME] === '*') {
148
207
  // This is a placeholder value that represents that the caller imported this
149
208
  // as a CommonJS module as is.
150
209
  return moduleExports;
151
210
  }
152
211
 
153
- if (metadata.name === '') {
212
+ if (metadata[NAME] === '') {
154
213
  // This is a placeholder value that represents that the caller accessed the
155
214
  // default property of this if it was an ESM interop module.
156
215
  return moduleExports.__esModule ? moduleExports.default : moduleExports;
157
216
  }
158
217
 
159
- return moduleExports[metadata.name];
218
+ return moduleExports[metadata[NAME]];
219
+ }
220
+
221
+ var chunkMap = new Map();
222
+ /**
223
+ * We patch the chunk filename function in webpack to insert our own resolution
224
+ * of chunks that come from Flight and may not be known to the webpack runtime
225
+ */
226
+
227
+ var webpackGetChunkFilename = __webpack_require__.u;
228
+
229
+ __webpack_require__.u = function (chunkId) {
230
+ var flightChunk = chunkMap.get(chunkId);
231
+
232
+ if (flightChunk !== undefined) {
233
+ return flightChunk;
234
+ }
235
+
236
+ return webpackGetChunkFilename(chunkId);
237
+ };
238
+
239
+ function loadChunk(chunkId, filename) {
240
+ chunkMap.set(chunkId, filename);
241
+ return __webpack_chunk_load__(chunkId);
160
242
  }
161
243
 
162
244
  var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
163
245
 
164
246
  // This client file is in the shared folder because it applies to both SSR and browser contexts.
165
- var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
247
+ var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
166
248
  function dispatchHint(code, model) {
167
249
  var dispatcher = ReactDOMCurrentDispatcher.current;
168
250
 
169
- if (dispatcher) {
170
- var href, options;
251
+ switch (code) {
252
+ case 'D':
253
+ {
254
+ var refined = refineModel(code, model);
255
+ var href = refined;
256
+ dispatcher.prefetchDNS(href);
257
+ return;
258
+ }
171
259
 
172
- if (typeof model === 'string') {
173
- href = model;
174
- } else {
175
- href = model[0];
176
- options = model[1];
177
- }
260
+ case 'C':
261
+ {
262
+ var _refined = refineModel(code, model);
178
263
 
179
- switch (code) {
180
- case 'D':
181
- {
182
- // $FlowFixMe[prop-missing] options are not refined to their types by code
183
- dispatcher.prefetchDNS(href, options);
184
- return;
264
+ if (typeof _refined === 'string') {
265
+ var _href = _refined;
266
+ dispatcher.preconnect(_href);
267
+ } else {
268
+ var _href2 = _refined[0];
269
+ var crossOrigin = _refined[1];
270
+ dispatcher.preconnect(_href2, crossOrigin);
185
271
  }
186
272
 
187
- case 'C':
188
- {
189
- // $FlowFixMe[prop-missing] options are not refined to their types by code
190
- dispatcher.preconnect(href, options);
191
- return;
273
+ return;
274
+ }
275
+
276
+ case 'L':
277
+ {
278
+ var _refined2 = refineModel(code, model);
279
+
280
+ var _href3 = _refined2[0];
281
+ var as = _refined2[1];
282
+
283
+ if (_refined2.length === 3) {
284
+ var options = _refined2[2];
285
+ dispatcher.preload(_href3, as, options);
286
+ } else {
287
+ dispatcher.preload(_href3, as);
192
288
  }
193
289
 
194
- case 'L':
195
- {
196
- // $FlowFixMe[prop-missing] options are not refined to their types by code
197
- // $FlowFixMe[incompatible-call] options are not refined to their types by code
198
- dispatcher.preload(href, options);
199
- return;
290
+ return;
291
+ }
292
+
293
+ case 'm':
294
+ {
295
+ var _refined3 = refineModel(code, model);
296
+
297
+ if (typeof _refined3 === 'string') {
298
+ var _href4 = _refined3;
299
+ dispatcher.preloadModule(_href4);
300
+ } else {
301
+ var _href5 = _refined3[0];
302
+ var _options = _refined3[1];
303
+ dispatcher.preloadModule(_href5, _options);
200
304
  }
201
305
 
202
- case 'I':
203
- {
204
- // $FlowFixMe[prop-missing] options are not refined to their types by code
205
- // $FlowFixMe[incompatible-call] options are not refined to their types by code
206
- dispatcher.preinit(href, options);
207
- return;
306
+ return;
307
+ }
308
+
309
+ case 'S':
310
+ {
311
+ var _refined4 = refineModel(code, model);
312
+
313
+ if (typeof _refined4 === 'string') {
314
+ var _href6 = _refined4;
315
+ dispatcher.preinitStyle(_href6);
316
+ } else {
317
+ var _href7 = _refined4[0];
318
+ var precedence = _refined4[1] === 0 ? undefined : _refined4[1];
319
+
320
+ var _options2 = _refined4.length === 3 ? _refined4[2] : undefined;
321
+
322
+ dispatcher.preinitStyle(_href7, precedence, _options2);
323
+ }
324
+
325
+ return;
326
+ }
327
+
328
+ case 'X':
329
+ {
330
+ var _refined5 = refineModel(code, model);
331
+
332
+ if (typeof _refined5 === 'string') {
333
+ var _href8 = _refined5;
334
+ dispatcher.preinitScript(_href8);
335
+ } else {
336
+ var _href9 = _refined5[0];
337
+ var _options3 = _refined5[1];
338
+ dispatcher.preinitScript(_href9, _options3);
339
+ }
340
+
341
+ return;
342
+ }
343
+
344
+ case 'M':
345
+ {
346
+ var _refined6 = refineModel(code, model);
347
+
348
+ if (typeof _refined6 === 'string') {
349
+ var _href10 = _refined6;
350
+ dispatcher.preinitModuleScript(_href10);
351
+ } else {
352
+ var _href11 = _refined6[0];
353
+ var _options4 = _refined6[1];
354
+ dispatcher.preinitModuleScript(_href11, _options4);
208
355
  }
356
+
357
+ return;
358
+ }
359
+ }
360
+ } // Flow is having trouble refining the HintModels so we help it a bit.
361
+ // This should be compiled out in the production build.
362
+
363
+ function refineModel(code, model) {
364
+ return model;
365
+ }
366
+
367
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
368
+
369
+ function error(format) {
370
+ {
371
+ {
372
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
373
+ args[_key2 - 1] = arguments[_key2];
374
+ }
375
+
376
+ printWarning('error', format, args);
209
377
  }
210
378
  }
211
379
  }
212
380
 
213
- var knownServerReferences = new WeakMap();
214
- function createServerReference(id, callServer) {
215
- var proxy = function () {
216
- // $FlowFixMe[method-unbinding]
217
- var args = Array.prototype.slice.call(arguments);
218
- return callServer(id, args);
219
- };
381
+ function printWarning(level, format, args) {
382
+ // When changing this logic, you might want to also
383
+ // update consoleWithStackDev.www.js as well.
384
+ {
385
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
386
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
220
387
 
221
- knownServerReferences.set(proxy, {
222
- id: id,
223
- bound: null
224
- });
225
- return proxy;
388
+ if (stack !== '') {
389
+ format += '%s';
390
+ args = args.concat([stack]);
391
+ } // eslint-disable-next-line react-internal/safe-string-coercion
392
+
393
+
394
+ var argsWithFormat = args.map(function (item) {
395
+ return String(item);
396
+ }); // Careful: RN currently depends on this prefix
397
+
398
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
399
+ // breaks IE9: https://github.com/facebook/react/issues/13610
400
+ // eslint-disable-next-line react-internal/no-production-logging
401
+
402
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
403
+ }
226
404
  }
227
405
 
228
406
  // ATTENTION
@@ -230,13 +408,12 @@
230
408
  // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
231
409
  // The Symbol used to tag the ReactElement-like types.
232
410
  var REACT_ELEMENT_TYPE = Symbol.for('react.element');
233
- var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
411
+ var REACT_PROVIDER_TYPE = Symbol.for('react.provider'); // TODO: Delete with enableRenderableContext
234
412
  var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
235
413
  var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
236
414
  var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
237
415
  var REACT_MEMO_TYPE = Symbol.for('react.memo');
238
416
  var REACT_LAZY_TYPE = Symbol.for('react.lazy');
239
- var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
240
417
  var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
241
418
  var FAUX_ITERATOR_SYMBOL = '@@iterator';
242
419
  function getIteratorFn(maybeIterable) {
@@ -253,1398 +430,1829 @@
253
430
  return null;
254
431
  }
255
432
 
256
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
257
-
258
- var ContextRegistry = ReactSharedInternals.ContextRegistry;
259
- function getOrCreateServerContext(globalName) {
260
- if (!ContextRegistry[globalName]) {
261
- ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
262
- REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
263
- }
433
+ var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
264
434
 
265
- return ContextRegistry[globalName];
435
+ function isArray(a) {
436
+ return isArrayImpl(a);
266
437
  }
267
438
 
268
- var PENDING = 'pending';
269
- var BLOCKED = 'blocked';
270
- var RESOLVED_MODEL = 'resolved_model';
271
- var RESOLVED_MODULE = 'resolved_module';
272
- var INITIALIZED = 'fulfilled';
273
- var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
274
-
275
- function Chunk(status, value, reason, response) {
276
- this.status = status;
277
- this.value = value;
278
- this.reason = reason;
279
- this._response = response;
280
- } // We subclass Promise.prototype so that we get other methods like .catch
281
-
282
-
283
- Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
439
+ var getPrototypeOf = Object.getPrototypeOf;
284
440
 
285
- Chunk.prototype.then = function (resolve, reject) {
286
- var chunk = this; // If we have resolved content, we try to initialize it first which
287
- // might put us back into one of the other states.
441
+ // in case they error.
288
442
 
289
- switch (chunk.status) {
290
- case RESOLVED_MODEL:
291
- initializeModelChunk(chunk);
292
- break;
443
+ var jsxPropsParents = new WeakMap();
444
+ var jsxChildrenParents = new WeakMap();
293
445
 
294
- case RESOLVED_MODULE:
295
- initializeModuleChunk(chunk);
296
- break;
297
- } // The status might have changed after initialization.
446
+ function isObjectPrototype(object) {
447
+ if (!object) {
448
+ return false;
449
+ }
298
450
 
451
+ var ObjectPrototype = Object.prototype;
299
452
 
300
- switch (chunk.status) {
301
- case INITIALIZED:
302
- resolve(chunk.value);
303
- break;
453
+ if (object === ObjectPrototype) {
454
+ return true;
455
+ } // It might be an object from a different Realm which is
456
+ // still just a plain simple object.
304
457
 
305
- case PENDING:
306
- case BLOCKED:
307
- if (resolve) {
308
- if (chunk.value === null) {
309
- chunk.value = [];
310
- }
311
458
 
312
- chunk.value.push(resolve);
313
- }
459
+ if (getPrototypeOf(object)) {
460
+ return false;
461
+ }
314
462
 
315
- if (reject) {
316
- if (chunk.reason === null) {
317
- chunk.reason = [];
318
- }
463
+ var names = Object.getOwnPropertyNames(object);
319
464
 
320
- chunk.reason.push(reject);
321
- }
465
+ for (var i = 0; i < names.length; i++) {
466
+ if (!(names[i] in ObjectPrototype)) {
467
+ return false;
468
+ }
469
+ }
322
470
 
323
- break;
471
+ return true;
472
+ }
324
473
 
325
- default:
326
- reject(chunk.reason);
327
- break;
474
+ function isSimpleObject(object) {
475
+ if (!isObjectPrototype(getPrototypeOf(object))) {
476
+ return false;
328
477
  }
329
- };
330
-
331
- function readChunk(chunk) {
332
- // If we have resolved content, we try to initialize it first which
333
- // might put us back into one of the other states.
334
- switch (chunk.status) {
335
- case RESOLVED_MODEL:
336
- initializeModelChunk(chunk);
337
- break;
338
478
 
339
- case RESOLVED_MODULE:
340
- initializeModuleChunk(chunk);
341
- break;
342
- } // The status might have changed after initialization.
479
+ var names = Object.getOwnPropertyNames(object);
343
480
 
481
+ for (var i = 0; i < names.length; i++) {
482
+ var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
344
483
 
345
- switch (chunk.status) {
346
- case INITIALIZED:
347
- return chunk.value;
484
+ if (!descriptor) {
485
+ return false;
486
+ }
348
487
 
349
- case PENDING:
350
- case BLOCKED:
351
- // eslint-disable-next-line no-throw-literal
352
- throw chunk;
488
+ if (!descriptor.enumerable) {
489
+ if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
490
+ // React adds key and ref getters to props objects to issue warnings.
491
+ // Those getters will not be transferred to the client, but that's ok,
492
+ // so we'll special case them.
493
+ continue;
494
+ }
353
495
 
354
- default:
355
- throw chunk.reason;
496
+ return false;
497
+ }
356
498
  }
357
- }
358
499
 
359
- function getRoot(response) {
360
- var chunk = getChunk(response, 0);
361
- return chunk;
500
+ return true;
362
501
  }
363
-
364
- function createPendingChunk(response) {
365
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
366
- return new Chunk(PENDING, null, null, response);
502
+ function objectName(object) {
503
+ // $FlowFixMe[method-unbinding]
504
+ var name = Object.prototype.toString.call(object);
505
+ return name.replace(/^\[object (.*)\]$/, function (m, p0) {
506
+ return p0;
507
+ });
367
508
  }
368
509
 
369
- function createBlockedChunk(response) {
370
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
371
- return new Chunk(BLOCKED, null, null, response);
510
+ function describeKeyForErrorMessage(key) {
511
+ var encodedKey = JSON.stringify(key);
512
+ return '"' + key + '"' === encodedKey ? key : encodedKey;
372
513
  }
373
514
 
374
- function createErrorChunk(response, error) {
375
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
376
- return new Chunk(ERRORED, null, error, response);
377
- }
515
+ function describeValueForErrorMessage(value) {
516
+ switch (typeof value) {
517
+ case 'string':
518
+ {
519
+ return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
520
+ }
378
521
 
379
- function wakeChunk(listeners, value) {
380
- for (var i = 0; i < listeners.length; i++) {
381
- var listener = listeners[i];
382
- listener(value);
383
- }
384
- }
522
+ case 'object':
523
+ {
524
+ if (isArray(value)) {
525
+ return '[...]';
526
+ }
385
527
 
386
- function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
387
- switch (chunk.status) {
388
- case INITIALIZED:
389
- wakeChunk(resolveListeners, chunk.value);
390
- break;
528
+ if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
529
+ return describeClientReference();
530
+ }
391
531
 
392
- case PENDING:
393
- case BLOCKED:
394
- chunk.value = resolveListeners;
395
- chunk.reason = rejectListeners;
396
- break;
532
+ var name = objectName(value);
397
533
 
398
- case ERRORED:
399
- if (rejectListeners) {
400
- wakeChunk(rejectListeners, chunk.reason);
534
+ if (name === 'Object') {
535
+ return '{...}';
536
+ }
537
+
538
+ return name;
401
539
  }
402
540
 
403
- break;
404
- }
405
- }
541
+ case 'function':
542
+ {
543
+ if (value.$$typeof === CLIENT_REFERENCE_TAG) {
544
+ return describeClientReference();
545
+ }
406
546
 
407
- function triggerErrorOnChunk(chunk, error) {
408
- if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
409
- // We already resolved. We didn't expect to see this.
410
- return;
411
- }
547
+ var _name = value.displayName || value.name;
412
548
 
413
- var listeners = chunk.reason;
414
- var erroredChunk = chunk;
415
- erroredChunk.status = ERRORED;
416
- erroredChunk.reason = error;
549
+ return _name ? 'function ' + _name : 'function';
550
+ }
417
551
 
418
- if (listeners !== null) {
419
- wakeChunk(listeners, error);
552
+ default:
553
+ // eslint-disable-next-line react-internal/safe-string-coercion
554
+ return String(value);
420
555
  }
421
556
  }
422
557
 
423
- function createResolvedModelChunk(response, value) {
424
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
425
- return new Chunk(RESOLVED_MODEL, value, null, response);
426
- }
558
+ function describeElementType(type) {
559
+ if (typeof type === 'string') {
560
+ return type;
561
+ }
427
562
 
428
- function createResolvedModuleChunk(response, value) {
429
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
430
- return new Chunk(RESOLVED_MODULE, value, null, response);
431
- }
563
+ switch (type) {
564
+ case REACT_SUSPENSE_TYPE:
565
+ return 'Suspense';
432
566
 
433
- function resolveModelChunk(chunk, value) {
434
- if (chunk.status !== PENDING) {
435
- // We already resolved. We didn't expect to see this.
436
- return;
567
+ case REACT_SUSPENSE_LIST_TYPE:
568
+ return 'SuspenseList';
437
569
  }
438
570
 
439
- var resolveListeners = chunk.value;
440
- var rejectListeners = chunk.reason;
441
- var resolvedChunk = chunk;
442
- resolvedChunk.status = RESOLVED_MODEL;
443
- resolvedChunk.value = value;
571
+ if (typeof type === 'object') {
572
+ switch (type.$$typeof) {
573
+ case REACT_FORWARD_REF_TYPE:
574
+ return describeElementType(type.render);
444
575
 
445
- if (resolveListeners !== null) {
446
- // This is unfortunate that we're reading this eagerly if
447
- // we already have listeners attached since they might no
448
- // longer be rendered or might not be the highest pri.
449
- initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
576
+ case REACT_MEMO_TYPE:
577
+ return describeElementType(type.type);
450
578
 
451
- wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
579
+ case REACT_LAZY_TYPE:
580
+ {
581
+ var lazyComponent = type;
582
+ var payload = lazyComponent._payload;
583
+ var init = lazyComponent._init;
584
+
585
+ try {
586
+ // Lazy may contain any component type so we recursively resolve it.
587
+ return describeElementType(init(payload));
588
+ } catch (x) {}
589
+ }
590
+ }
452
591
  }
592
+
593
+ return '';
453
594
  }
454
595
 
455
- function resolveModuleChunk(chunk, value) {
456
- if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
457
- // We already resolved. We didn't expect to see this.
458
- return;
459
- }
596
+ var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
460
597
 
461
- var resolveListeners = chunk.value;
462
- var rejectListeners = chunk.reason;
463
- var resolvedChunk = chunk;
464
- resolvedChunk.status = RESOLVED_MODULE;
465
- resolvedChunk.value = value;
598
+ function describeClientReference(ref) {
599
+ return 'client';
600
+ }
466
601
 
467
- if (resolveListeners !== null) {
468
- initializeModuleChunk(resolvedChunk);
469
- wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
602
+ function describeObjectForErrorMessage(objectOrArray, expandedName) {
603
+ var objKind = objectName(objectOrArray);
604
+
605
+ if (objKind !== 'Object' && objKind !== 'Array') {
606
+ return objKind;
470
607
  }
471
- }
472
608
 
473
- var initializingChunk = null;
474
- var initializingChunkBlockedModel = null;
609
+ var str = '';
610
+ var start = -1;
611
+ var length = 0;
475
612
 
476
- function initializeModelChunk(chunk) {
477
- var prevChunk = initializingChunk;
478
- var prevBlocked = initializingChunkBlockedModel;
479
- initializingChunk = chunk;
480
- initializingChunkBlockedModel = null;
613
+ if (isArray(objectOrArray)) {
614
+ if (jsxChildrenParents.has(objectOrArray)) {
615
+ // Print JSX Children
616
+ var type = jsxChildrenParents.get(objectOrArray);
617
+ str = '<' + describeElementType(type) + '>';
618
+ var array = objectOrArray;
481
619
 
482
- try {
483
- var value = parseModel(chunk._response, chunk.value);
620
+ for (var i = 0; i < array.length; i++) {
621
+ var value = array[i];
622
+ var substr = void 0;
484
623
 
485
- if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
486
- initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
487
- // We have to go the BLOCKED state until they're resolved.
624
+ if (typeof value === 'string') {
625
+ substr = value;
626
+ } else if (typeof value === 'object' && value !== null) {
627
+ substr = '{' + describeObjectForErrorMessage(value) + '}';
628
+ } else {
629
+ substr = '{' + describeValueForErrorMessage(value) + '}';
630
+ }
488
631
 
489
- var blockedChunk = chunk;
490
- blockedChunk.status = BLOCKED;
491
- blockedChunk.value = null;
492
- blockedChunk.reason = null;
632
+ if ('' + i === expandedName) {
633
+ start = str.length;
634
+ length = substr.length;
635
+ str += substr;
636
+ } else if (substr.length < 15 && str.length + substr.length < 40) {
637
+ str += substr;
638
+ } else {
639
+ str += '{...}';
640
+ }
641
+ }
642
+
643
+ str += '</' + describeElementType(type) + '>';
493
644
  } else {
494
- var initializedChunk = chunk;
495
- initializedChunk.status = INITIALIZED;
496
- initializedChunk.value = value;
497
- }
498
- } catch (error) {
499
- var erroredChunk = chunk;
500
- erroredChunk.status = ERRORED;
501
- erroredChunk.reason = error;
502
- } finally {
503
- initializingChunk = prevChunk;
504
- initializingChunkBlockedModel = prevBlocked;
505
- }
506
- }
645
+ // Print Array
646
+ str = '[';
647
+ var _array = objectOrArray;
507
648
 
508
- function initializeModuleChunk(chunk) {
509
- try {
510
- var value = requireModule(chunk.value);
511
- var initializedChunk = chunk;
512
- initializedChunk.status = INITIALIZED;
513
- initializedChunk.value = value;
514
- } catch (error) {
515
- var erroredChunk = chunk;
516
- erroredChunk.status = ERRORED;
517
- erroredChunk.reason = error;
518
- }
519
- } // Report that any missing chunks in the model is now going to throw this
520
- // error upon read. Also notify any pending promises.
649
+ for (var _i = 0; _i < _array.length; _i++) {
650
+ if (_i > 0) {
651
+ str += ', ';
652
+ }
521
653
 
654
+ var _value = _array[_i];
522
655
 
523
- function reportGlobalError(response, error) {
524
- response._chunks.forEach(function (chunk) {
525
- // If this chunk was already resolved or errored, it won't
526
- // trigger an error but if it wasn't then we need to
527
- // because we won't be getting any new data to resolve it.
528
- if (chunk.status === PENDING) {
529
- triggerErrorOnChunk(chunk, error);
530
- }
531
- });
532
- }
656
+ var _substr = void 0;
533
657
 
534
- function createElement(type, key, props) {
535
- var element = {
536
- // This tag allows us to uniquely identify this as a React Element
537
- $$typeof: REACT_ELEMENT_TYPE,
538
- // Built-in properties that belong on the element
539
- type: type,
540
- key: key,
541
- ref: null,
542
- props: props,
543
- // Record the component responsible for creating this element.
544
- _owner: null
545
- };
658
+ if (typeof _value === 'object' && _value !== null) {
659
+ _substr = describeObjectForErrorMessage(_value);
660
+ } else {
661
+ _substr = describeValueForErrorMessage(_value);
662
+ }
546
663
 
547
- {
548
- // We don't really need to add any of these but keeping them for good measure.
549
- // Unfortunately, _store is enumerable in jest matchers so for equality to
550
- // work, I need to keep it or make _store non-enumerable in the other file.
551
- element._store = {};
552
- Object.defineProperty(element._store, 'validated', {
553
- configurable: false,
554
- enumerable: false,
555
- writable: true,
556
- value: true // This element has already been validated on the server.
664
+ if ('' + _i === expandedName) {
665
+ start = str.length;
666
+ length = _substr.length;
667
+ str += _substr;
668
+ } else if (_substr.length < 10 && str.length + _substr.length < 40) {
669
+ str += _substr;
670
+ } else {
671
+ str += '...';
672
+ }
673
+ }
557
674
 
558
- });
559
- Object.defineProperty(element, '_self', {
560
- configurable: false,
561
- enumerable: false,
562
- writable: false,
563
- value: null
564
- });
565
- Object.defineProperty(element, '_source', {
566
- configurable: false,
567
- enumerable: false,
568
- writable: false,
569
- value: null
570
- });
675
+ str += ']';
676
+ }
677
+ } else {
678
+ if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
679
+ str = '<' + describeElementType(objectOrArray.type) + '/>';
680
+ } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
681
+ return describeClientReference();
682
+ } else if (jsxPropsParents.has(objectOrArray)) {
683
+ // Print JSX
684
+ var _type = jsxPropsParents.get(objectOrArray);
685
+
686
+ str = '<' + (describeElementType(_type) || '...');
687
+ var object = objectOrArray;
688
+ var names = Object.keys(object);
689
+
690
+ for (var _i2 = 0; _i2 < names.length; _i2++) {
691
+ str += ' ';
692
+ var name = names[_i2];
693
+ str += describeKeyForErrorMessage(name) + '=';
694
+ var _value2 = object[name];
695
+
696
+ var _substr2 = void 0;
697
+
698
+ if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
699
+ _substr2 = describeObjectForErrorMessage(_value2);
700
+ } else {
701
+ _substr2 = describeValueForErrorMessage(_value2);
702
+ }
703
+
704
+ if (typeof _value2 !== 'string') {
705
+ _substr2 = '{' + _substr2 + '}';
706
+ }
707
+
708
+ if (name === expandedName) {
709
+ start = str.length;
710
+ length = _substr2.length;
711
+ str += _substr2;
712
+ } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
713
+ str += _substr2;
714
+ } else {
715
+ str += '...';
716
+ }
717
+ }
718
+
719
+ str += '>';
720
+ } else {
721
+ // Print Object
722
+ str = '{';
723
+ var _object = objectOrArray;
724
+
725
+ var _names = Object.keys(_object);
726
+
727
+ for (var _i3 = 0; _i3 < _names.length; _i3++) {
728
+ if (_i3 > 0) {
729
+ str += ', ';
730
+ }
731
+
732
+ var _name2 = _names[_i3];
733
+ str += describeKeyForErrorMessage(_name2) + ': ';
734
+ var _value3 = _object[_name2];
735
+
736
+ var _substr3 = void 0;
737
+
738
+ if (typeof _value3 === 'object' && _value3 !== null) {
739
+ _substr3 = describeObjectForErrorMessage(_value3);
740
+ } else {
741
+ _substr3 = describeValueForErrorMessage(_value3);
742
+ }
743
+
744
+ if (_name2 === expandedName) {
745
+ start = str.length;
746
+ length = _substr3.length;
747
+ str += _substr3;
748
+ } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
749
+ str += _substr3;
750
+ } else {
751
+ str += '...';
752
+ }
753
+ }
754
+
755
+ str += '}';
756
+ }
571
757
  }
572
758
 
573
- return element;
759
+ if (expandedName === undefined) {
760
+ return str;
761
+ }
762
+
763
+ if (start > -1 && length > 0) {
764
+ var highlight = ' '.repeat(start) + '^'.repeat(length);
765
+ return '\n ' + str + '\n ' + highlight;
766
+ }
767
+
768
+ return '\n ' + str;
574
769
  }
575
770
 
576
- function createLazyChunkWrapper(chunk) {
577
- var lazyType = {
578
- $$typeof: REACT_LAZY_TYPE,
579
- _payload: chunk,
580
- _init: readChunk
581
- };
582
- return lazyType;
771
+ function createTemporaryReferenceSet() {
772
+ return [];
773
+ }
774
+ function writeTemporaryReference(set, object) {
775
+ // We always create a new entry regardless if we've already written the same
776
+ // object. This ensures that we always generate a deterministic encoding of
777
+ // each slot in the reply for cacheability.
778
+ var newId = set.length;
779
+ set.push(object);
780
+ return newId;
781
+ }
782
+ function readTemporaryReference(set, id) {
783
+ if (id < 0 || id >= set.length) {
784
+ 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.');
785
+ }
786
+
787
+ return set[id];
788
+ }
789
+
790
+ var ObjectPrototype = Object.prototype;
791
+ var knownServerReferences = new WeakMap(); // Serializable values
792
+ // Thenable<ReactServerValue>
793
+
794
+ function serializeByValueID(id) {
795
+ return '$' + id.toString(16);
796
+ }
797
+
798
+ function serializePromiseID(id) {
799
+ return '$@' + id.toString(16);
800
+ }
801
+
802
+ function serializeServerReferenceID(id) {
803
+ return '$F' + id.toString(16);
804
+ }
805
+
806
+ function serializeTemporaryReferenceID(id) {
807
+ return '$T' + id.toString(16);
808
+ }
809
+
810
+ function serializeFormDataReference(id) {
811
+ // Why K? F is "Function". D is "Date". What else?
812
+ return '$K' + id.toString(16);
813
+ }
814
+
815
+ function serializeNumber(number) {
816
+ if (Number.isFinite(number)) {
817
+ if (number === 0 && 1 / number === -Infinity) {
818
+ return '$-0';
819
+ } else {
820
+ return number;
821
+ }
822
+ } else {
823
+ if (number === Infinity) {
824
+ return '$Infinity';
825
+ } else if (number === -Infinity) {
826
+ return '$-Infinity';
827
+ } else {
828
+ return '$NaN';
829
+ }
830
+ }
831
+ }
832
+
833
+ function serializeUndefined() {
834
+ return '$undefined';
835
+ }
836
+
837
+ function serializeDateFromDateJSON(dateJSON) {
838
+ // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
839
+ // We need only tack on a $D prefix.
840
+ return '$D' + dateJSON;
841
+ }
842
+
843
+ function serializeBigInt(n) {
844
+ return '$n' + n.toString(10);
845
+ }
846
+
847
+ function serializeMapID(id) {
848
+ return '$Q' + id.toString(16);
849
+ }
850
+
851
+ function serializeSetID(id) {
852
+ return '$W' + id.toString(16);
853
+ }
854
+
855
+ function escapeStringValue(value) {
856
+ if (value[0] === '$') {
857
+ // We need to escape $ prefixed strings since we use those to encode
858
+ // references to IDs and as special symbol values.
859
+ return '$' + value;
860
+ } else {
861
+ return value;
862
+ }
583
863
  }
584
864
 
585
- function getChunk(response, id) {
586
- var chunks = response._chunks;
587
- var chunk = chunks.get(id);
865
+ function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
866
+ var nextPartId = 1;
867
+ var pendingParts = 0;
868
+ var formData = null;
869
+
870
+ function resolveToJSON(key, value) {
871
+ var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
872
+
873
+ {
874
+ // $FlowFixMe[incompatible-use]
875
+ var originalValue = parent[key];
876
+
877
+ if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
878
+ if (objectName(originalValue) !== 'Object') {
879
+ error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
880
+ } else {
881
+ 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));
882
+ }
883
+ }
884
+ }
885
+
886
+ if (value === null) {
887
+ return null;
888
+ }
889
+
890
+ if (typeof value === 'object') {
891
+ switch (value.$$typeof) {
892
+ case REACT_ELEMENT_TYPE:
893
+ {
894
+ if (temporaryReferences === undefined) {
895
+ 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) ));
896
+ }
897
+
898
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
899
+ }
900
+
901
+ case REACT_LAZY_TYPE:
902
+ {
903
+ // Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
904
+ var lazy = value;
905
+ var payload = lazy._payload;
906
+ var init = lazy._init;
907
+
908
+ if (formData === null) {
909
+ // Upgrade to use FormData to allow us to stream this value.
910
+ formData = new FormData();
911
+ }
912
+
913
+ pendingParts++;
914
+
915
+ try {
916
+ var resolvedModel = init(payload); // We always outline this as a separate part even though we could inline it
917
+ // because it ensures a more deterministic encoding.
918
+
919
+ var lazyId = nextPartId++;
920
+ var partJSON = JSON.stringify(resolvedModel, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
921
+
922
+ var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
923
+
924
+ data.append(formFieldPrefix + lazyId, partJSON);
925
+ return serializeByValueID(lazyId);
926
+ } catch (x) {
927
+ if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
928
+ // Suspended
929
+ pendingParts++;
930
+
931
+ var _lazyId = nextPartId++;
932
+
933
+ var thenable = x;
934
+
935
+ var retry = function () {
936
+ // While the first promise resolved, its value isn't necessarily what we'll
937
+ // resolve into because we might suspend again.
938
+ try {
939
+ var _partJSON = JSON.stringify(value, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
940
+
941
+
942
+ var _data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
943
+
944
+ _data.append(formFieldPrefix + _lazyId, _partJSON);
945
+
946
+ pendingParts--;
947
+
948
+ if (pendingParts === 0) {
949
+ resolve(_data);
950
+ }
951
+ } catch (reason) {
952
+ reject(reason);
953
+ }
954
+ };
955
+
956
+ thenable.then(retry, retry);
957
+ return serializeByValueID(_lazyId);
958
+ } else {
959
+ // In the future we could consider serializing this as an error
960
+ // that throws on the server instead.
961
+ reject(x);
962
+ return null;
963
+ }
964
+ } finally {
965
+ pendingParts--;
966
+ }
967
+ }
968
+ } // $FlowFixMe[method-unbinding]
969
+
970
+
971
+ if (typeof value.then === 'function') {
972
+ // We assume that any object with a .then property is a "Thenable" type,
973
+ // or a Promise type. Either of which can be represented by a Promise.
974
+ if (formData === null) {
975
+ // Upgrade to use FormData to allow us to stream this value.
976
+ formData = new FormData();
977
+ }
978
+
979
+ pendingParts++;
980
+ var promiseId = nextPartId++;
981
+ var _thenable = value;
982
+
983
+ _thenable.then(function (partValue) {
984
+ try {
985
+ var _partJSON2 = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
986
+
987
+
988
+ var _data2 = formData; // eslint-disable-next-line react-internal/safe-string-coercion
989
+
990
+ _data2.append(formFieldPrefix + promiseId, _partJSON2);
991
+
992
+ pendingParts--;
993
+
994
+ if (pendingParts === 0) {
995
+ resolve(_data2);
996
+ }
997
+ } catch (reason) {
998
+ reject(reason);
999
+ }
1000
+ }, function (reason) {
1001
+ // In the future we could consider serializing this as an error
1002
+ // that throws on the server instead.
1003
+ reject(reason);
1004
+ });
1005
+
1006
+ return serializePromiseID(promiseId);
1007
+ }
1008
+
1009
+ if (isArray(value)) {
1010
+ // $FlowFixMe[incompatible-return]
1011
+ return value;
1012
+ } // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
1013
+
1014
+
1015
+ if (value instanceof FormData) {
1016
+ if (formData === null) {
1017
+ // Upgrade to use FormData to allow us to use rich objects as its values.
1018
+ formData = new FormData();
1019
+ }
1020
+
1021
+ var _data3 = formData;
1022
+ var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
1023
+ // These must come first in the form order because we assume that all the
1024
+ // fields are available before this is referenced.
1025
+
1026
+ var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
1027
+
1028
+ value.forEach(function (originalValue, originalKey) {
1029
+ _data3.append(prefix + originalKey, originalValue);
1030
+ });
1031
+ return serializeFormDataReference(refId);
1032
+ }
1033
+
1034
+ if (value instanceof Map) {
1035
+ var _partJSON3 = JSON.stringify(Array.from(value), resolveToJSON);
1036
+
1037
+ if (formData === null) {
1038
+ formData = new FormData();
1039
+ }
1040
+
1041
+ var mapId = nextPartId++;
1042
+ formData.append(formFieldPrefix + mapId, _partJSON3);
1043
+ return serializeMapID(mapId);
1044
+ }
1045
+
1046
+ if (value instanceof Set) {
1047
+ var _partJSON4 = JSON.stringify(Array.from(value), resolveToJSON);
1048
+
1049
+ if (formData === null) {
1050
+ formData = new FormData();
1051
+ }
1052
+
1053
+ var setId = nextPartId++;
1054
+ formData.append(formFieldPrefix + setId, _partJSON4);
1055
+ return serializeSetID(setId);
1056
+ }
1057
+
1058
+ var iteratorFn = getIteratorFn(value);
1059
+
1060
+ if (iteratorFn) {
1061
+ return Array.from(value);
1062
+ } // Verify that this is a simple plain object.
1063
+
1064
+
1065
+ var proto = getPrototypeOf(value);
1066
+
1067
+ if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
1068
+ if (temporaryReferences === undefined) {
1069
+ throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
1070
+ } // We can serialize class instances as temporary references.
1071
+
1072
+
1073
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1074
+ }
1075
+
1076
+ {
1077
+ if (value.$$typeof === (REACT_PROVIDER_TYPE)) {
1078
+ error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
1079
+ } else if (objectName(value) !== 'Object') {
1080
+ error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
1081
+ } else if (!isSimpleObject(value)) {
1082
+ 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));
1083
+ } else if (Object.getOwnPropertySymbols) {
1084
+ var symbols = Object.getOwnPropertySymbols(value);
1085
+
1086
+ if (symbols.length > 0) {
1087
+ 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));
1088
+ }
1089
+ }
1090
+ } // $FlowFixMe[incompatible-return]
1091
+
1092
+
1093
+ return value;
1094
+ }
1095
+
1096
+ if (typeof value === 'string') {
1097
+ // TODO: Maybe too clever. If we support URL there's no similar trick.
1098
+ if (value[value.length - 1] === 'Z') {
1099
+ // Possibly a Date, whose toJSON automatically calls toISOString
1100
+ // $FlowFixMe[incompatible-use]
1101
+ var _originalValue = parent[key];
1102
+
1103
+ if (_originalValue instanceof Date) {
1104
+ return serializeDateFromDateJSON(value);
1105
+ }
1106
+ }
1107
+
1108
+ return escapeStringValue(value);
1109
+ }
1110
+
1111
+ if (typeof value === 'boolean') {
1112
+ return value;
1113
+ }
1114
+
1115
+ if (typeof value === 'number') {
1116
+ return serializeNumber(value);
1117
+ }
1118
+
1119
+ if (typeof value === 'undefined') {
1120
+ return serializeUndefined();
1121
+ }
588
1122
 
589
- if (!chunk) {
590
- chunk = createPendingChunk(response);
591
- chunks.set(id, chunk);
592
- }
1123
+ if (typeof value === 'function') {
1124
+ var metaData = knownServerReferences.get(value);
593
1125
 
594
- return chunk;
595
- }
1126
+ if (metaData !== undefined) {
1127
+ var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
596
1128
 
597
- function createModelResolver(chunk, parentObject, key) {
598
- var blocked;
1129
+ if (formData === null) {
1130
+ // Upgrade to use FormData to allow us to stream this value.
1131
+ formData = new FormData();
1132
+ } // The reference to this function came from the same client so we can pass it back.
599
1133
 
600
- if (initializingChunkBlockedModel) {
601
- blocked = initializingChunkBlockedModel;
602
- blocked.deps++;
603
- } else {
604
- blocked = initializingChunkBlockedModel = {
605
- deps: 1,
606
- value: null
607
- };
608
- }
609
1134
 
610
- return function (value) {
611
- parentObject[key] = value;
612
- blocked.deps--;
1135
+ var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
613
1136
 
614
- if (blocked.deps === 0) {
615
- if (chunk.status !== BLOCKED) {
616
- return;
617
- }
618
1137
 
619
- var resolveListeners = chunk.value;
620
- var initializedChunk = chunk;
621
- initializedChunk.status = INITIALIZED;
622
- initializedChunk.value = blocked.value;
1138
+ formData.set(formFieldPrefix + _refId, metaDataJSON);
1139
+ return serializeServerReferenceID(_refId);
1140
+ }
623
1141
 
624
- if (resolveListeners !== null) {
625
- wakeChunk(resolveListeners, blocked.value);
1142
+ if (temporaryReferences === undefined) {
1143
+ throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
626
1144
  }
627
- }
628
- };
629
- }
630
1145
 
631
- function createModelReject(chunk) {
632
- return function (error) {
633
- return triggerErrorOnChunk(chunk, error);
634
- };
635
- }
1146
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1147
+ }
636
1148
 
637
- function createServerReferenceProxy(response, metaData) {
638
- var callServer = response._callServer;
1149
+ if (typeof value === 'symbol') {
1150
+ if (temporaryReferences === undefined) {
1151
+ 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) ));
1152
+ }
639
1153
 
640
- var proxy = function () {
641
- // $FlowFixMe[method-unbinding]
642
- var args = Array.prototype.slice.call(arguments);
643
- var p = metaData.bound;
1154
+ return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1155
+ }
644
1156
 
645
- if (!p) {
646
- return callServer(metaData.id, args);
1157
+ if (typeof value === 'bigint') {
1158
+ return serializeBigInt(value);
647
1159
  }
648
1160
 
649
- if (p.status === INITIALIZED) {
650
- var bound = p.value;
651
- return callServer(metaData.id, bound.concat(args));
652
- } // Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
653
- // TODO: Remove the wrapper once that's fixed.
1161
+ throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
1162
+ } // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
654
1163
 
655
1164
 
656
- return Promise.resolve(p).then(function (bound) {
657
- return callServer(metaData.id, bound.concat(args));
658
- });
659
- };
1165
+ var json = JSON.stringify(root, resolveToJSON);
660
1166
 
661
- knownServerReferences.set(proxy, metaData);
662
- return proxy;
663
- }
1167
+ if (formData === null) {
1168
+ // If it's a simple data structure, we just use plain JSON.
1169
+ resolve(json);
1170
+ } else {
1171
+ // Otherwise, we use FormData to let us stream in the result.
1172
+ formData.set(formFieldPrefix + '0', json);
664
1173
 
665
- function parseModelString(response, parentObject, key, value) {
666
- if (value[0] === '$') {
667
- if (value === '$') {
668
- // A very common symbol.
669
- return REACT_ELEMENT_TYPE;
1174
+ if (pendingParts === 0) {
1175
+ // $FlowFixMe[incompatible-call] this has already been refined.
1176
+ resolve(formData);
670
1177
  }
1178
+ }
1179
+ }
671
1180
 
672
- switch (value[1]) {
673
- case '$':
674
- {
675
- // This was an escaped string value.
676
- return value.slice(1);
677
- }
678
-
679
- case 'L':
680
- {
681
- // Lazy node
682
- var id = parseInt(value.slice(2), 16);
683
- var chunk = getChunk(response, id); // We create a React.lazy wrapper around any lazy values.
684
- // When passed into React, we'll know how to suspend on this.
685
-
686
- return createLazyChunkWrapper(chunk);
687
- }
688
-
689
- case '@':
690
- {
691
- // Promise
692
- var _id = parseInt(value.slice(2), 16);
1181
+ function registerServerReference(proxy, reference, encodeFormAction) {
693
1182
 
694
- var _chunk = getChunk(response, _id);
1183
+ knownServerReferences.set(proxy, reference);
1184
+ } // $FlowFixMe[method-unbinding]
695
1185
 
696
- return _chunk;
697
- }
1186
+ function createServerReference(id, callServer, encodeFormAction) {
1187
+ var proxy = function () {
1188
+ // $FlowFixMe[method-unbinding]
1189
+ var args = Array.prototype.slice.call(arguments);
1190
+ return callServer(id, args);
1191
+ };
698
1192
 
699
- case 'S':
700
- {
701
- // Symbol
702
- return Symbol.for(value.slice(2));
703
- }
1193
+ registerServerReference(proxy, {
1194
+ id: id,
1195
+ bound: null
1196
+ });
1197
+ return proxy;
1198
+ }
704
1199
 
705
- case 'P':
706
- {
707
- // Server Context Provider
708
- return getOrCreateServerContext(value.slice(2)).Provider;
709
- }
1200
+ var ROW_ID = 0;
1201
+ var ROW_TAG = 1;
1202
+ var ROW_LENGTH = 2;
1203
+ var ROW_CHUNK_BY_NEWLINE = 3;
1204
+ var ROW_CHUNK_BY_LENGTH = 4;
1205
+ var PENDING = 'pending';
1206
+ var BLOCKED = 'blocked';
1207
+ var CYCLIC = 'cyclic';
1208
+ var RESOLVED_MODEL = 'resolved_model';
1209
+ var RESOLVED_MODULE = 'resolved_module';
1210
+ var INITIALIZED = 'fulfilled';
1211
+ var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
710
1212
 
711
- case 'F':
712
- {
713
- // Server Reference
714
- var _id2 = parseInt(value.slice(2), 16);
1213
+ function Chunk(status, value, reason, response) {
1214
+ this.status = status;
1215
+ this.value = value;
1216
+ this.reason = reason;
1217
+ this._response = response;
715
1218
 
716
- var _chunk2 = getChunk(response, _id2);
1219
+ {
1220
+ this._debugInfo = null;
1221
+ }
1222
+ } // We subclass Promise.prototype so that we get other methods like .catch
717
1223
 
718
- switch (_chunk2.status) {
719
- case RESOLVED_MODEL:
720
- initializeModelChunk(_chunk2);
721
- break;
722
- } // The status might have changed after initialization.
723
1224
 
1225
+ Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
724
1226
 
725
- switch (_chunk2.status) {
726
- case INITIALIZED:
727
- {
728
- var metadata = _chunk2.value;
729
- return createServerReferenceProxy(response, metadata);
730
- }
731
- // We always encode it first in the stream so it won't be pending.
1227
+ Chunk.prototype.then = function (resolve, reject) {
1228
+ var chunk = this; // If we have resolved content, we try to initialize it first which
1229
+ // might put us back into one of the other states.
732
1230
 
733
- default:
734
- throw _chunk2.reason;
735
- }
736
- }
1231
+ switch (chunk.status) {
1232
+ case RESOLVED_MODEL:
1233
+ initializeModelChunk(chunk);
1234
+ break;
737
1235
 
738
- case 'I':
739
- {
740
- // $Infinity
741
- return Infinity;
742
- }
1236
+ case RESOLVED_MODULE:
1237
+ initializeModuleChunk(chunk);
1238
+ break;
1239
+ } // The status might have changed after initialization.
743
1240
 
744
- case '-':
745
- {
746
- // $-0 or $-Infinity
747
- if (value === '$-0') {
748
- return -0;
749
- } else {
750
- return -Infinity;
751
- }
752
- }
753
1241
 
754
- case 'N':
755
- {
756
- // $NaN
757
- return NaN;
758
- }
1242
+ switch (chunk.status) {
1243
+ case INITIALIZED:
1244
+ resolve(chunk.value);
1245
+ break;
759
1246
 
760
- case 'u':
761
- {
762
- // matches "$undefined"
763
- // Special encoding for `undefined` which can't be serialized as JSON otherwise.
764
- return undefined;
1247
+ case PENDING:
1248
+ case BLOCKED:
1249
+ case CYCLIC:
1250
+ if (resolve) {
1251
+ if (chunk.value === null) {
1252
+ chunk.value = [];
765
1253
  }
766
1254
 
767
- case 'D':
768
- {
769
- // Date
770
- return new Date(Date.parse(value.slice(2)));
771
- }
1255
+ chunk.value.push(resolve);
1256
+ }
772
1257
 
773
- case 'n':
774
- {
775
- // BigInt
776
- return BigInt(value.slice(2));
1258
+ if (reject) {
1259
+ if (chunk.reason === null) {
1260
+ chunk.reason = [];
777
1261
  }
778
1262
 
779
- default:
780
- {
781
- // We assume that anything else is a reference ID.
782
- var _id3 = parseInt(value.slice(1), 16);
783
-
784
- var _chunk3 = getChunk(response, _id3);
1263
+ chunk.reason.push(reject);
1264
+ }
785
1265
 
786
- switch (_chunk3.status) {
787
- case RESOLVED_MODEL:
788
- initializeModelChunk(_chunk3);
789
- break;
1266
+ break;
790
1267
 
791
- case RESOLVED_MODULE:
792
- initializeModuleChunk(_chunk3);
793
- break;
794
- } // The status might have changed after initialization.
1268
+ default:
1269
+ reject(chunk.reason);
1270
+ break;
1271
+ }
1272
+ };
795
1273
 
1274
+ function readChunk(chunk) {
1275
+ // If we have resolved content, we try to initialize it first which
1276
+ // might put us back into one of the other states.
1277
+ switch (chunk.status) {
1278
+ case RESOLVED_MODEL:
1279
+ initializeModelChunk(chunk);
1280
+ break;
796
1281
 
797
- switch (_chunk3.status) {
798
- case INITIALIZED:
799
- return _chunk3.value;
1282
+ case RESOLVED_MODULE:
1283
+ initializeModuleChunk(chunk);
1284
+ break;
1285
+ } // The status might have changed after initialization.
800
1286
 
801
- case PENDING:
802
- case BLOCKED:
803
- var parentChunk = initializingChunk;
804
1287
 
805
- _chunk3.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
1288
+ switch (chunk.status) {
1289
+ case INITIALIZED:
1290
+ return chunk.value;
806
1291
 
807
- return null;
1292
+ case PENDING:
1293
+ case BLOCKED:
1294
+ case CYCLIC:
1295
+ // eslint-disable-next-line no-throw-literal
1296
+ throw chunk;
808
1297
 
809
- default:
810
- throw _chunk3.reason;
811
- }
812
- }
813
- }
1298
+ default:
1299
+ throw chunk.reason;
814
1300
  }
815
-
816
- return value;
817
1301
  }
818
- function parseModelTuple(response, value) {
819
- var tuple = value;
820
1302
 
821
- if (tuple[0] === REACT_ELEMENT_TYPE) {
822
- // TODO: Consider having React just directly accept these arrays as elements.
823
- // Or even change the ReactElement type to be an array.
824
- return createElement(tuple[1], tuple[2], tuple[3]);
825
- }
1303
+ function getRoot(response) {
1304
+ var chunk = getChunk(response, 0);
1305
+ return chunk;
1306
+ }
826
1307
 
827
- return value;
1308
+ function createPendingChunk(response) {
1309
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1310
+ return new Chunk(PENDING, null, null, response);
828
1311
  }
829
1312
 
830
- function missingCall() {
831
- throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
1313
+ function createBlockedChunk(response) {
1314
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1315
+ return new Chunk(BLOCKED, null, null, response);
832
1316
  }
833
1317
 
834
- function createResponse$1(bundlerConfig, callServer) {
835
- var chunks = new Map();
836
- var response = {
837
- _bundlerConfig: bundlerConfig,
838
- _callServer: callServer !== undefined ? callServer : missingCall,
839
- _chunks: chunks
840
- };
841
- return response;
1318
+ function createErrorChunk(response, error) {
1319
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1320
+ return new Chunk(ERRORED, null, error, response);
842
1321
  }
843
- function resolveModel(response, id, model) {
844
- var chunks = response._chunks;
845
- var chunk = chunks.get(id);
846
1322
 
847
- if (!chunk) {
848
- chunks.set(id, createResolvedModelChunk(response, model));
849
- } else {
850
- resolveModelChunk(chunk, model);
1323
+ function wakeChunk(listeners, value) {
1324
+ for (var i = 0; i < listeners.length; i++) {
1325
+ var listener = listeners[i];
1326
+ listener(value);
851
1327
  }
852
1328
  }
853
- function resolveModule(response, id, model) {
854
- var chunks = response._chunks;
855
- var chunk = chunks.get(id);
856
- var clientReferenceMetadata = parseModel(response, model);
857
- var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
858
- // For now we preload all modules as early as possible since it's likely
859
- // that we'll need them.
860
1329
 
861
- var promise = preloadModule(clientReference);
1330
+ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
1331
+ switch (chunk.status) {
1332
+ case INITIALIZED:
1333
+ wakeChunk(resolveListeners, chunk.value);
1334
+ break;
862
1335
 
863
- if (promise) {
864
- var blockedChunk;
1336
+ case PENDING:
1337
+ case BLOCKED:
1338
+ case CYCLIC:
1339
+ chunk.value = resolveListeners;
1340
+ chunk.reason = rejectListeners;
1341
+ break;
865
1342
 
866
- if (!chunk) {
867
- // Technically, we should just treat promise as the chunk in this
868
- // case. Because it'll just behave as any other promise.
869
- blockedChunk = createBlockedChunk(response);
870
- chunks.set(id, blockedChunk);
871
- } else {
872
- // This can't actually happen because we don't have any forward
873
- // references to modules.
874
- blockedChunk = chunk;
875
- blockedChunk.status = BLOCKED;
876
- }
1343
+ case ERRORED:
1344
+ if (rejectListeners) {
1345
+ wakeChunk(rejectListeners, chunk.reason);
1346
+ }
877
1347
 
878
- promise.then(function () {
879
- return resolveModuleChunk(blockedChunk, clientReference);
880
- }, function (error) {
881
- return triggerErrorOnChunk(blockedChunk, error);
882
- });
883
- } else {
884
- if (!chunk) {
885
- chunks.set(id, createResolvedModuleChunk(response, clientReference));
886
- } else {
887
- // This can't actually happen because we don't have any forward
888
- // references to modules.
889
- resolveModuleChunk(chunk, clientReference);
890
- }
1348
+ break;
891
1349
  }
892
1350
  }
893
- function resolveErrorDev(response, id, digest, message, stack) {
894
1351
 
1352
+ function triggerErrorOnChunk(chunk, error) {
1353
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
1354
+ // We already resolved. We didn't expect to see this.
1355
+ return;
1356
+ }
895
1357
 
896
- var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
897
- error.stack = stack;
898
- error.digest = digest;
899
- var errorWithDigest = error;
900
- var chunks = response._chunks;
901
- var chunk = chunks.get(id);
1358
+ var listeners = chunk.reason;
1359
+ var erroredChunk = chunk;
1360
+ erroredChunk.status = ERRORED;
1361
+ erroredChunk.reason = error;
902
1362
 
903
- if (!chunk) {
904
- chunks.set(id, createErrorChunk(response, errorWithDigest));
905
- } else {
906
- triggerErrorOnChunk(chunk, errorWithDigest);
1363
+ if (listeners !== null) {
1364
+ wakeChunk(listeners, error);
907
1365
  }
908
1366
  }
909
- function resolveHint(response, code, model) {
910
- var hintModel = parseModel(response, model);
911
- dispatchHint(code, hintModel);
1367
+
1368
+ function createResolvedModelChunk(response, value) {
1369
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1370
+ return new Chunk(RESOLVED_MODEL, value, null, response);
912
1371
  }
913
- function close(response) {
914
- // In case there are any remaining unresolved chunks, they won't
915
- // be resolved now. So we need to issue an error to those.
916
- // Ideally we should be able to early bail out if we kept a
917
- // ref count of pending chunks.
918
- reportGlobalError(response, new Error('Connection closed.'));
1372
+
1373
+ function createResolvedModuleChunk(response, value) {
1374
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1375
+ return new Chunk(RESOLVED_MODULE, value, null, response);
1376
+ }
1377
+
1378
+ function createInitializedTextChunk(response, value) {
1379
+ // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1380
+ return new Chunk(INITIALIZED, value, null, response);
919
1381
  }
920
1382
 
921
- function processFullRow(response, row) {
922
- if (row === '') {
1383
+ function resolveModelChunk(chunk, value) {
1384
+ if (chunk.status !== PENDING) {
1385
+ // We already resolved. We didn't expect to see this.
923
1386
  return;
924
1387
  }
925
1388
 
926
- var colon = row.indexOf(':', 0);
927
- var id = parseInt(row.slice(0, colon), 16);
928
- var tag = row[colon + 1]; // When tags that are not text are added, check them here before
929
- // parsing the row as text.
930
- // switch (tag) {
931
- // }
932
-
933
- switch (tag) {
934
- case 'I':
935
- {
936
- resolveModule(response, id, row.slice(colon + 2));
937
- return;
938
- }
1389
+ var resolveListeners = chunk.value;
1390
+ var rejectListeners = chunk.reason;
1391
+ var resolvedChunk = chunk;
1392
+ resolvedChunk.status = RESOLVED_MODEL;
1393
+ resolvedChunk.value = value;
939
1394
 
940
- case 'H':
941
- {
942
- var code = row[colon + 2];
943
- resolveHint(response, code, row.slice(colon + 3));
944
- return;
945
- }
1395
+ if (resolveListeners !== null) {
1396
+ // This is unfortunate that we're reading this eagerly if
1397
+ // we already have listeners attached since they might no
1398
+ // longer be rendered or might not be the highest pri.
1399
+ initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
946
1400
 
947
- case 'E':
948
- {
949
- var errorInfo = JSON.parse(row.slice(colon + 2));
1401
+ wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
1402
+ }
1403
+ }
950
1404
 
951
- {
952
- resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
953
- }
1405
+ function resolveModuleChunk(chunk, value) {
1406
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
1407
+ // We already resolved. We didn't expect to see this.
1408
+ return;
1409
+ }
954
1410
 
955
- return;
956
- }
1411
+ var resolveListeners = chunk.value;
1412
+ var rejectListeners = chunk.reason;
1413
+ var resolvedChunk = chunk;
1414
+ resolvedChunk.status = RESOLVED_MODULE;
1415
+ resolvedChunk.value = value;
957
1416
 
958
- default:
959
- {
960
- // We assume anything else is JSON.
961
- resolveModel(response, id, row.slice(colon + 1));
962
- return;
963
- }
1417
+ if (resolveListeners !== null) {
1418
+ initializeModuleChunk(resolvedChunk);
1419
+ wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
964
1420
  }
965
1421
  }
966
1422
 
967
- function processStringChunk(response, chunk, offset) {
968
- var linebreak = chunk.indexOf('\n', offset);
1423
+ var initializingChunk = null;
1424
+ var initializingChunkBlockedModel = null;
969
1425
 
970
- while (linebreak > -1) {
971
- var fullrow = response._partialRow + chunk.slice(offset, linebreak);
972
- processFullRow(response, fullrow);
973
- response._partialRow = '';
974
- offset = linebreak + 1;
975
- linebreak = chunk.indexOf('\n', offset);
976
- }
1426
+ function initializeModelChunk(chunk) {
1427
+ var prevChunk = initializingChunk;
1428
+ var prevBlocked = initializingChunkBlockedModel;
1429
+ initializingChunk = chunk;
1430
+ initializingChunkBlockedModel = null;
1431
+ var resolvedModel = chunk.value; // We go to the CYCLIC state until we've fully resolved this.
1432
+ // We do this before parsing in case we try to initialize the same chunk
1433
+ // while parsing the model. Such as in a cyclic reference.
977
1434
 
978
- response._partialRow += chunk.slice(offset);
979
- }
980
- function processBinaryChunk(response, chunk) {
1435
+ var cyclicChunk = chunk;
1436
+ cyclicChunk.status = CYCLIC;
1437
+ cyclicChunk.value = null;
1438
+ cyclicChunk.reason = null;
981
1439
 
982
- var stringDecoder = response._stringDecoder;
983
- var linebreak = chunk.indexOf(10); // newline
984
-
985
- while (linebreak > -1) {
986
- var fullrow = response._partialRow + readFinalStringChunk(stringDecoder, chunk.subarray(0, linebreak));
987
- processFullRow(response, fullrow);
988
- response._partialRow = '';
989
- chunk = chunk.subarray(linebreak + 1);
990
- linebreak = chunk.indexOf(10); // newline
991
- }
1440
+ try {
1441
+ var value = parseModel(chunk._response, resolvedModel);
992
1442
 
993
- response._partialRow += readPartialStringChunk(stringDecoder, chunk);
994
- }
1443
+ if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
1444
+ initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
1445
+ // We have to go the BLOCKED state until they're resolved.
995
1446
 
996
- function createFromJSONCallback(response) {
997
- // $FlowFixMe[missing-this-annot]
998
- return function (key, value) {
999
- if (typeof value === 'string') {
1000
- // We can't use .bind here because we need the "this" value.
1001
- return parseModelString(response, this, key, value);
1002
- }
1447
+ var blockedChunk = chunk;
1448
+ blockedChunk.status = BLOCKED;
1449
+ blockedChunk.value = null;
1450
+ blockedChunk.reason = null;
1451
+ } else {
1452
+ var resolveListeners = cyclicChunk.value;
1453
+ var initializedChunk = chunk;
1454
+ initializedChunk.status = INITIALIZED;
1455
+ initializedChunk.value = value;
1003
1456
 
1004
- if (typeof value === 'object' && value !== null) {
1005
- return parseModelTuple(response, value);
1457
+ if (resolveListeners !== null) {
1458
+ wakeChunk(resolveListeners, value);
1459
+ }
1006
1460
  }
1007
-
1008
- return value;
1009
- };
1461
+ } catch (error) {
1462
+ var erroredChunk = chunk;
1463
+ erroredChunk.status = ERRORED;
1464
+ erroredChunk.reason = error;
1465
+ } finally {
1466
+ initializingChunk = prevChunk;
1467
+ initializingChunkBlockedModel = prevBlocked;
1468
+ }
1010
1469
  }
1011
1470
 
1012
- function createResponse(bundlerConfig, callServer) {
1013
- // NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.
1014
- // It should be inlined to one object literal but minor changes can break it.
1015
- var stringDecoder = createStringDecoder() ;
1016
- var response = createResponse$1(bundlerConfig, callServer);
1017
- response._partialRow = '';
1018
-
1019
- {
1020
- response._stringDecoder = stringDecoder;
1021
- } // Don't inline this call because it causes closure to outline the call above.
1471
+ function initializeModuleChunk(chunk) {
1472
+ try {
1473
+ var value = requireModule(chunk.value);
1474
+ var initializedChunk = chunk;
1475
+ initializedChunk.status = INITIALIZED;
1476
+ initializedChunk.value = value;
1477
+ } catch (error) {
1478
+ var erroredChunk = chunk;
1479
+ erroredChunk.status = ERRORED;
1480
+ erroredChunk.reason = error;
1481
+ }
1482
+ } // Report that any missing chunks in the model is now going to throw this
1483
+ // error upon read. Also notify any pending promises.
1022
1484
 
1023
1485
 
1024
- response._fromJSON = createFromJSONCallback(response);
1025
- return response;
1486
+ function reportGlobalError(response, error) {
1487
+ response._chunks.forEach(function (chunk) {
1488
+ // If this chunk was already resolved or errored, it won't
1489
+ // trigger an error but if it wasn't then we need to
1490
+ // because we won't be getting any new data to resolve it.
1491
+ if (chunk.status === PENDING) {
1492
+ triggerErrorOnChunk(chunk, error);
1493
+ }
1494
+ });
1026
1495
  }
1027
1496
 
1028
- function error(format) {
1029
- {
1030
- {
1031
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1032
- args[_key2 - 1] = arguments[_key2];
1033
- }
1497
+ function createElement(type, key, props) {
1498
+ var element;
1034
1499
 
1035
- printWarning('error', format, args);
1036
- }
1500
+ {
1501
+ element = {
1502
+ // This tag allows us to uniquely identify this as a React Element
1503
+ $$typeof: REACT_ELEMENT_TYPE,
1504
+ type: type,
1505
+ key: key,
1506
+ ref: null,
1507
+ props: props,
1508
+ // Record the component responsible for creating this element.
1509
+ _owner: null
1510
+ };
1037
1511
  }
1038
- }
1039
1512
 
1040
- function printWarning(level, format, args) {
1041
- // When changing this logic, you might want to also
1042
- // update consoleWithStackDev.www.js as well.
1043
1513
  {
1044
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1045
- var stack = ReactDebugCurrentFrame.getStackAddendum();
1514
+ // We don't really need to add any of these but keeping them for good measure.
1515
+ // Unfortunately, _store is enumerable in jest matchers so for equality to
1516
+ // work, I need to keep it or make _store non-enumerable in the other file.
1517
+ element._store = {};
1518
+ Object.defineProperty(element._store, 'validated', {
1519
+ configurable: false,
1520
+ enumerable: false,
1521
+ writable: true,
1522
+ value: true // This element has already been validated on the server.
1046
1523
 
1047
- if (stack !== '') {
1048
- format += '%s';
1049
- args = args.concat([stack]);
1050
- } // eslint-disable-next-line react-internal/safe-string-coercion
1524
+ }); // debugInfo contains Server Component debug information.
1051
1525
 
1526
+ Object.defineProperty(element, '_debugInfo', {
1527
+ configurable: false,
1528
+ enumerable: false,
1529
+ writable: true,
1530
+ value: null
1531
+ });
1532
+ }
1052
1533
 
1053
- var argsWithFormat = args.map(function (item) {
1054
- return String(item);
1055
- }); // Careful: RN currently depends on this prefix
1534
+ return element;
1535
+ }
1056
1536
 
1057
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
1058
- // breaks IE9: https://github.com/facebook/react/issues/13610
1059
- // eslint-disable-next-line react-internal/no-production-logging
1537
+ function createLazyChunkWrapper(chunk) {
1538
+ var lazyType = {
1539
+ $$typeof: REACT_LAZY_TYPE,
1540
+ _payload: chunk,
1541
+ _init: readChunk
1542
+ };
1060
1543
 
1061
- Function.prototype.apply.call(console[level], console, argsWithFormat);
1544
+ {
1545
+ // Ensure we have a live array to track future debug info.
1546
+ var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
1547
+ lazyType._debugInfo = chunkDebugInfo;
1062
1548
  }
1063
- }
1064
-
1065
- var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
1066
1549
 
1067
- function isArray(a) {
1068
- return isArrayImpl(a);
1550
+ return lazyType;
1069
1551
  }
1070
1552
 
1071
- // in case they error.
1072
-
1073
- var jsxPropsParents = new WeakMap();
1074
- var jsxChildrenParents = new WeakMap();
1553
+ function getChunk(response, id) {
1554
+ var chunks = response._chunks;
1555
+ var chunk = chunks.get(id);
1075
1556
 
1076
- function isObjectPrototype(object) {
1077
- if (!object) {
1078
- return false;
1557
+ if (!chunk) {
1558
+ chunk = createPendingChunk(response);
1559
+ chunks.set(id, chunk);
1079
1560
  }
1080
1561
 
1081
- var ObjectPrototype = Object.prototype;
1562
+ return chunk;
1563
+ }
1082
1564
 
1083
- if (object === ObjectPrototype) {
1084
- return true;
1085
- } // It might be an object from a different Realm which is
1086
- // still just a plain simple object.
1565
+ function createModelResolver(chunk, parentObject, key, cyclic) {
1566
+ var blocked;
1087
1567
 
1568
+ if (initializingChunkBlockedModel) {
1569
+ blocked = initializingChunkBlockedModel;
1088
1570
 
1089
- if (Object.getPrototypeOf(object)) {
1090
- return false;
1571
+ if (!cyclic) {
1572
+ blocked.deps++;
1573
+ }
1574
+ } else {
1575
+ blocked = initializingChunkBlockedModel = {
1576
+ deps: cyclic ? 0 : 1,
1577
+ value: null
1578
+ };
1091
1579
  }
1092
1580
 
1093
- var names = Object.getOwnPropertyNames(object);
1581
+ return function (value) {
1582
+ parentObject[key] = value;
1583
+ blocked.deps--;
1094
1584
 
1095
- for (var i = 0; i < names.length; i++) {
1096
- if (!(names[i] in ObjectPrototype)) {
1097
- return false;
1098
- }
1099
- }
1585
+ if (blocked.deps === 0) {
1586
+ if (chunk.status !== BLOCKED) {
1587
+ return;
1588
+ }
1100
1589
 
1101
- return true;
1590
+ var resolveListeners = chunk.value;
1591
+ var initializedChunk = chunk;
1592
+ initializedChunk.status = INITIALIZED;
1593
+ initializedChunk.value = blocked.value;
1594
+
1595
+ if (resolveListeners !== null) {
1596
+ wakeChunk(resolveListeners, blocked.value);
1597
+ }
1598
+ }
1599
+ };
1102
1600
  }
1103
1601
 
1104
- function isSimpleObject(object) {
1105
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1106
- return false;
1107
- }
1602
+ function createModelReject(chunk) {
1603
+ return function (error) {
1604
+ return triggerErrorOnChunk(chunk, error);
1605
+ };
1606
+ }
1108
1607
 
1109
- var names = Object.getOwnPropertyNames(object);
1608
+ function createServerReferenceProxy(response, metaData) {
1609
+ var callServer = response._callServer;
1110
1610
 
1111
- for (var i = 0; i < names.length; i++) {
1112
- var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1611
+ var proxy = function () {
1612
+ // $FlowFixMe[method-unbinding]
1613
+ var args = Array.prototype.slice.call(arguments);
1614
+ var p = metaData.bound;
1113
1615
 
1114
- if (!descriptor) {
1115
- return false;
1616
+ if (!p) {
1617
+ return callServer(metaData.id, args);
1116
1618
  }
1117
1619
 
1118
- if (!descriptor.enumerable) {
1119
- if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
1120
- // React adds key and ref getters to props objects to issue warnings.
1121
- // Those getters will not be transferred to the client, but that's ok,
1122
- // so we'll special case them.
1123
- continue;
1124
- }
1620
+ if (p.status === INITIALIZED) {
1621
+ var bound = p.value;
1622
+ return callServer(metaData.id, bound.concat(args));
1623
+ } // Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
1624
+ // TODO: Remove the wrapper once that's fixed.
1125
1625
 
1126
- return false;
1127
- }
1128
- }
1129
1626
 
1130
- return true;
1131
- }
1132
- function objectName(object) {
1133
- // $FlowFixMe[method-unbinding]
1134
- var name = Object.prototype.toString.call(object);
1135
- return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1136
- return p0;
1137
- });
1138
- }
1627
+ return Promise.resolve(p).then(function (bound) {
1628
+ return callServer(metaData.id, bound.concat(args));
1629
+ });
1630
+ };
1139
1631
 
1140
- function describeKeyForErrorMessage(key) {
1141
- var encodedKey = JSON.stringify(key);
1142
- return '"' + key + '"' === encodedKey ? key : encodedKey;
1632
+ registerServerReference(proxy, metaData);
1633
+ return proxy;
1143
1634
  }
1144
1635
 
1145
- function describeValueForErrorMessage(value) {
1146
- switch (typeof value) {
1147
- case 'string':
1148
- {
1149
- return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
1150
- }
1151
-
1152
- case 'object':
1153
- {
1154
- if (isArray(value)) {
1155
- return '[...]';
1156
- }
1636
+ function getOutlinedModel(response, id) {
1637
+ var chunk = getChunk(response, id);
1157
1638
 
1158
- var name = objectName(value);
1639
+ switch (chunk.status) {
1640
+ case RESOLVED_MODEL:
1641
+ initializeModelChunk(chunk);
1642
+ break;
1643
+ } // The status might have changed after initialization.
1159
1644
 
1160
- if (name === 'Object') {
1161
- return '{...}';
1162
- }
1163
1645
 
1164
- return name;
1646
+ switch (chunk.status) {
1647
+ case INITIALIZED:
1648
+ {
1649
+ return chunk.value;
1165
1650
  }
1166
-
1167
- case 'function':
1168
- return 'function';
1651
+ // We always encode it first in the stream so it won't be pending.
1169
1652
 
1170
1653
  default:
1171
- // eslint-disable-next-line react-internal/safe-string-coercion
1172
- return String(value);
1654
+ throw chunk.reason;
1173
1655
  }
1174
1656
  }
1175
1657
 
1176
- function describeElementType(type) {
1177
- if (typeof type === 'string') {
1178
- return type;
1179
- }
1180
-
1181
- switch (type) {
1182
- case REACT_SUSPENSE_TYPE:
1183
- return 'Suspense';
1184
-
1185
- case REACT_SUSPENSE_LIST_TYPE:
1186
- return 'SuspenseList';
1187
- }
1188
-
1189
- if (typeof type === 'object') {
1190
- switch (type.$$typeof) {
1191
- case REACT_FORWARD_REF_TYPE:
1192
- return describeElementType(type.render);
1193
-
1194
- case REACT_MEMO_TYPE:
1195
- return describeElementType(type.type);
1658
+ function parseModelString(response, parentObject, key, value) {
1659
+ if (value[0] === '$') {
1660
+ if (value === '$') {
1661
+ // A very common symbol.
1662
+ return REACT_ELEMENT_TYPE;
1663
+ }
1196
1664
 
1197
- case REACT_LAZY_TYPE:
1665
+ switch (value[1]) {
1666
+ case '$':
1198
1667
  {
1199
- var lazyComponent = type;
1200
- var payload = lazyComponent._payload;
1201
- var init = lazyComponent._init;
1668
+ // This was an escaped string value.
1669
+ return value.slice(1);
1670
+ }
1202
1671
 
1203
- try {
1204
- // Lazy may contain any component type so we recursively resolve it.
1205
- return describeElementType(init(payload));
1206
- } catch (x) {}
1672
+ case 'L':
1673
+ {
1674
+ // Lazy node
1675
+ var id = parseInt(value.slice(2), 16);
1676
+ var chunk = getChunk(response, id); // We create a React.lazy wrapper around any lazy values.
1677
+ // When passed into React, we'll know how to suspend on this.
1678
+
1679
+ return createLazyChunkWrapper(chunk);
1207
1680
  }
1208
- }
1209
- }
1210
1681
 
1211
- return '';
1212
- }
1682
+ case '@':
1683
+ {
1684
+ // Promise
1685
+ if (value.length === 2) {
1686
+ // Infinite promise that never resolves.
1687
+ return new Promise(function () {});
1688
+ }
1213
1689
 
1214
- function describeObjectForErrorMessage(objectOrArray, expandedName) {
1215
- var objKind = objectName(objectOrArray);
1690
+ var _id = parseInt(value.slice(2), 16);
1216
1691
 
1217
- if (objKind !== 'Object' && objKind !== 'Array') {
1218
- return objKind;
1219
- }
1692
+ var _chunk = getChunk(response, _id);
1220
1693
 
1221
- var str = '';
1222
- var start = -1;
1223
- var length = 0;
1694
+ return _chunk;
1695
+ }
1224
1696
 
1225
- if (isArray(objectOrArray)) {
1226
- if (jsxChildrenParents.has(objectOrArray)) {
1227
- // Print JSX Children
1228
- var type = jsxChildrenParents.get(objectOrArray);
1229
- str = '<' + describeElementType(type) + '>';
1230
- var array = objectOrArray;
1697
+ case 'S':
1698
+ {
1699
+ // Symbol
1700
+ return Symbol.for(value.slice(2));
1701
+ }
1231
1702
 
1232
- for (var i = 0; i < array.length; i++) {
1233
- var value = array[i];
1234
- var substr = void 0;
1703
+ case 'F':
1704
+ {
1705
+ // Server Reference
1706
+ var _id2 = parseInt(value.slice(2), 16);
1235
1707
 
1236
- if (typeof value === 'string') {
1237
- substr = value;
1238
- } else if (typeof value === 'object' && value !== null) {
1239
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1240
- substr = '{' + describeObjectForErrorMessage(value) + '}';
1241
- } else {
1242
- substr = '{' + describeValueForErrorMessage(value) + '}';
1708
+ var metadata = getOutlinedModel(response, _id2);
1709
+ return createServerReferenceProxy(response, metadata);
1243
1710
  }
1244
1711
 
1245
- if ('' + i === expandedName) {
1246
- start = str.length;
1247
- length = substr.length;
1248
- str += substr;
1249
- } else if (substr.length < 15 && str.length + substr.length < 40) {
1250
- str += substr;
1251
- } else {
1252
- str += '{...}';
1712
+ case 'T':
1713
+ {
1714
+ // Temporary Reference
1715
+ var _id3 = parseInt(value.slice(2), 16);
1716
+
1717
+ var temporaryReferences = response._tempRefs;
1718
+
1719
+ if (temporaryReferences == null) {
1720
+ 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.');
1721
+ }
1722
+
1723
+ return readTemporaryReference(temporaryReferences, _id3);
1253
1724
  }
1254
- }
1255
1725
 
1256
- str += '</' + describeElementType(type) + '>';
1257
- } else {
1258
- // Print Array
1259
- str = '[';
1260
- var _array = objectOrArray;
1726
+ case 'Q':
1727
+ {
1728
+ // Map
1729
+ var _id4 = parseInt(value.slice(2), 16);
1261
1730
 
1262
- for (var _i = 0; _i < _array.length; _i++) {
1263
- if (_i > 0) {
1264
- str += ', ';
1731
+ var data = getOutlinedModel(response, _id4);
1732
+ return new Map(data);
1265
1733
  }
1266
1734
 
1267
- var _value = _array[_i];
1735
+ case 'W':
1736
+ {
1737
+ // Set
1738
+ var _id5 = parseInt(value.slice(2), 16);
1268
1739
 
1269
- var _substr = void 0;
1740
+ var _data = getOutlinedModel(response, _id5);
1270
1741
 
1271
- if (typeof _value === 'object' && _value !== null) {
1272
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1273
- _substr = describeObjectForErrorMessage(_value);
1274
- } else {
1275
- _substr = describeValueForErrorMessage(_value);
1742
+ return new Set(_data);
1276
1743
  }
1277
1744
 
1278
- if ('' + _i === expandedName) {
1279
- start = str.length;
1280
- length = _substr.length;
1281
- str += _substr;
1282
- } else if (_substr.length < 10 && str.length + _substr.length < 40) {
1283
- str += _substr;
1284
- } else {
1285
- str += '...';
1745
+ case 'I':
1746
+ {
1747
+ // $Infinity
1748
+ return Infinity;
1286
1749
  }
1287
- }
1288
-
1289
- str += ']';
1290
- }
1291
- } else {
1292
- if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1293
- str = '<' + describeElementType(objectOrArray.type) + '/>';
1294
- } else if (jsxPropsParents.has(objectOrArray)) {
1295
- // Print JSX
1296
- var _type = jsxPropsParents.get(objectOrArray);
1297
1750
 
1298
- str = '<' + (describeElementType(_type) || '...');
1299
- var object = objectOrArray;
1300
- var names = Object.keys(object);
1751
+ case '-':
1752
+ {
1753
+ // $-0 or $-Infinity
1754
+ if (value === '$-0') {
1755
+ return -0;
1756
+ } else {
1757
+ return -Infinity;
1758
+ }
1759
+ }
1301
1760
 
1302
- for (var _i2 = 0; _i2 < names.length; _i2++) {
1303
- str += ' ';
1304
- var name = names[_i2];
1305
- str += describeKeyForErrorMessage(name) + '=';
1306
- var _value2 = object[name];
1761
+ case 'N':
1762
+ {
1763
+ // $NaN
1764
+ return NaN;
1765
+ }
1307
1766
 
1308
- var _substr2 = void 0;
1767
+ case 'u':
1768
+ {
1769
+ // matches "$undefined"
1770
+ // Special encoding for `undefined` which can't be serialized as JSON otherwise.
1771
+ return undefined;
1772
+ }
1309
1773
 
1310
- if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1311
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1312
- _substr2 = describeObjectForErrorMessage(_value2);
1313
- } else {
1314
- _substr2 = describeValueForErrorMessage(_value2);
1774
+ case 'D':
1775
+ {
1776
+ // Date
1777
+ return new Date(Date.parse(value.slice(2)));
1315
1778
  }
1316
1779
 
1317
- if (typeof _value2 !== 'string') {
1318
- _substr2 = '{' + _substr2 + '}';
1780
+ case 'n':
1781
+ {
1782
+ // BigInt
1783
+ return BigInt(value.slice(2));
1319
1784
  }
1320
1785
 
1321
- if (name === expandedName) {
1322
- start = str.length;
1323
- length = _substr2.length;
1324
- str += _substr2;
1325
- } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
1326
- str += _substr2;
1327
- } else {
1328
- str += '...';
1786
+ case 'E':
1787
+ {
1788
+ {
1789
+ // In DEV mode we allow indirect eval to produce functions for logging.
1790
+ // This should not compile to eval() because then it has local scope access.
1791
+ try {
1792
+ // eslint-disable-next-line no-eval
1793
+ return (0, eval)(value.slice(2));
1794
+ } catch (x) {
1795
+ // We currently use this to express functions so we fail parsing it,
1796
+ // let's just return a blank function as a place holder.
1797
+ return function () {};
1798
+ }
1799
+ } // Fallthrough
1800
+
1329
1801
  }
1330
- }
1331
1802
 
1332
- str += '>';
1333
- } else {
1334
- // Print Object
1335
- str = '{';
1336
- var _object = objectOrArray;
1803
+ default:
1804
+ {
1805
+ // We assume that anything else is a reference ID.
1806
+ var _id6 = parseInt(value.slice(1), 16);
1337
1807
 
1338
- var _names = Object.keys(_object);
1808
+ var _chunk2 = getChunk(response, _id6);
1339
1809
 
1340
- for (var _i3 = 0; _i3 < _names.length; _i3++) {
1341
- if (_i3 > 0) {
1342
- str += ', ';
1343
- }
1810
+ switch (_chunk2.status) {
1811
+ case RESOLVED_MODEL:
1812
+ initializeModelChunk(_chunk2);
1813
+ break;
1344
1814
 
1345
- var _name = _names[_i3];
1346
- str += describeKeyForErrorMessage(_name) + ': ';
1347
- var _value3 = _object[_name];
1815
+ case RESOLVED_MODULE:
1816
+ initializeModuleChunk(_chunk2);
1817
+ break;
1818
+ } // The status might have changed after initialization.
1348
1819
 
1349
- var _substr3 = void 0;
1350
1820
 
1351
- if (typeof _value3 === 'object' && _value3 !== null) {
1352
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1353
- _substr3 = describeObjectForErrorMessage(_value3);
1354
- } else {
1355
- _substr3 = describeValueForErrorMessage(_value3);
1356
- }
1821
+ switch (_chunk2.status) {
1822
+ case INITIALIZED:
1823
+ var chunkValue = _chunk2.value;
1824
+
1825
+ if (_chunk2._debugInfo) {
1826
+ // If we have a direct reference to an object that was rendered by a synchronous
1827
+ // server component, it might have some debug info about how it was rendered.
1828
+ // We forward this to the underlying object. This might be a React Element or
1829
+ // an Array fragment.
1830
+ // If this was a string / number return value we lose the debug info. We choose
1831
+ // that tradeoff to allow sync server components to return plain values and not
1832
+ // use them as React Nodes necessarily. We could otherwise wrap them in a Lazy.
1833
+ if (typeof chunkValue === 'object' && chunkValue !== null && (Array.isArray(chunkValue) || chunkValue.$$typeof === REACT_ELEMENT_TYPE) && !chunkValue._debugInfo) {
1834
+ // We should maybe use a unique symbol for arrays but this is a React owned array.
1835
+ // $FlowFixMe[prop-missing]: This should be added to elements.
1836
+ Object.defineProperty(chunkValue, '_debugInfo', {
1837
+ configurable: false,
1838
+ enumerable: false,
1839
+ writable: true,
1840
+ value: _chunk2._debugInfo
1841
+ });
1842
+ }
1843
+ }
1357
1844
 
1358
- if (_name === expandedName) {
1359
- start = str.length;
1360
- length = _substr3.length;
1361
- str += _substr3;
1362
- } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
1363
- str += _substr3;
1364
- } else {
1365
- str += '...';
1366
- }
1367
- }
1845
+ return chunkValue;
1368
1846
 
1369
- str += '}';
1847
+ case PENDING:
1848
+ case BLOCKED:
1849
+ case CYCLIC:
1850
+ var parentChunk = initializingChunk;
1851
+
1852
+ _chunk2.then(createModelResolver(parentChunk, parentObject, key, _chunk2.status === CYCLIC), createModelReject(parentChunk));
1853
+
1854
+ return null;
1855
+
1856
+ default:
1857
+ throw _chunk2.reason;
1858
+ }
1859
+ }
1370
1860
  }
1371
1861
  }
1372
1862
 
1373
- if (expandedName === undefined) {
1374
- return str;
1375
- }
1863
+ return value;
1864
+ }
1376
1865
 
1377
- if (start > -1 && length > 0) {
1378
- var highlight = ' '.repeat(start) + '^'.repeat(length);
1379
- return '\n ' + str + '\n ' + highlight;
1866
+ function parseModelTuple(response, value) {
1867
+ var tuple = value;
1868
+
1869
+ if (tuple[0] === REACT_ELEMENT_TYPE) {
1870
+ // TODO: Consider having React just directly accept these arrays as elements.
1871
+ // Or even change the ReactElement type to be an array.
1872
+ return createElement(tuple[1], tuple[2], tuple[3]);
1380
1873
  }
1381
1874
 
1382
- return '\n ' + str;
1875
+ return value;
1383
1876
  }
1384
1877
 
1385
- // Thenable<ReactServerValue>
1386
- // function serializeByValueID(id: number): string {
1387
- // return '$' + id.toString(16);
1388
- // }
1389
-
1390
- function serializePromiseID(id) {
1391
- return '$@' + id.toString(16);
1878
+ function missingCall() {
1879
+ throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
1392
1880
  }
1393
1881
 
1394
- function serializeServerReferenceID(id) {
1395
- return '$F' + id.toString(16);
1882
+ function createResponse(bundlerConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences) {
1883
+ var chunks = new Map();
1884
+ var response = {
1885
+ _bundlerConfig: bundlerConfig,
1886
+ _moduleLoading: moduleLoading,
1887
+ _callServer: callServer !== undefined ? callServer : missingCall,
1888
+ _encodeFormAction: encodeFormAction,
1889
+ _nonce: nonce,
1890
+ _chunks: chunks,
1891
+ _stringDecoder: createStringDecoder(),
1892
+ _fromJSON: null,
1893
+ _rowState: 0,
1894
+ _rowID: 0,
1895
+ _rowTag: 0,
1896
+ _rowLength: 0,
1897
+ _buffer: [],
1898
+ _tempRefs: temporaryReferences
1899
+ }; // Don't inline this call because it causes closure to outline the call above.
1900
+
1901
+ response._fromJSON = createFromJSONCallback(response);
1902
+ return response;
1396
1903
  }
1397
1904
 
1398
- function serializeSymbolReference(name) {
1399
- return '$S' + name;
1905
+ function resolveModel(response, id, model) {
1906
+ var chunks = response._chunks;
1907
+ var chunk = chunks.get(id);
1908
+
1909
+ if (!chunk) {
1910
+ chunks.set(id, createResolvedModelChunk(response, model));
1911
+ } else {
1912
+ resolveModelChunk(chunk, model);
1913
+ }
1400
1914
  }
1401
1915
 
1402
- function serializeFormDataReference(id) {
1403
- // Why K? F is "Function". D is "Date". What else?
1404
- return '$K' + id.toString(16);
1916
+ function resolveText(response, id, text) {
1917
+ var chunks = response._chunks; // We assume that we always reference large strings after they've been
1918
+ // emitted.
1919
+
1920
+ chunks.set(id, createInitializedTextChunk(response, text));
1405
1921
  }
1406
1922
 
1407
- function serializeNumber(number) {
1408
- if (Number.isFinite(number)) {
1409
- if (number === 0 && 1 / number === -Infinity) {
1410
- return '$-0';
1923
+ function resolveModule(response, id, model) {
1924
+ var chunks = response._chunks;
1925
+ var chunk = chunks.get(id);
1926
+ var clientReferenceMetadata = parseModel(response, model);
1927
+ var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
1928
+ // For now we preload all modules as early as possible since it's likely
1929
+ // that we'll need them.
1930
+
1931
+ var promise = preloadModule(clientReference);
1932
+
1933
+ if (promise) {
1934
+ var blockedChunk;
1935
+
1936
+ if (!chunk) {
1937
+ // Technically, we should just treat promise as the chunk in this
1938
+ // case. Because it'll just behave as any other promise.
1939
+ blockedChunk = createBlockedChunk(response);
1940
+ chunks.set(id, blockedChunk);
1411
1941
  } else {
1412
- return number;
1942
+ // This can't actually happen because we don't have any forward
1943
+ // references to modules.
1944
+ blockedChunk = chunk;
1945
+ blockedChunk.status = BLOCKED;
1413
1946
  }
1947
+
1948
+ promise.then(function () {
1949
+ return resolveModuleChunk(blockedChunk, clientReference);
1950
+ }, function (error) {
1951
+ return triggerErrorOnChunk(blockedChunk, error);
1952
+ });
1414
1953
  } else {
1415
- if (number === Infinity) {
1416
- return '$Infinity';
1417
- } else if (number === -Infinity) {
1418
- return '$-Infinity';
1954
+ if (!chunk) {
1955
+ chunks.set(id, createResolvedModuleChunk(response, clientReference));
1419
1956
  } else {
1420
- return '$NaN';
1957
+ // This can't actually happen because we don't have any forward
1958
+ // references to modules.
1959
+ resolveModuleChunk(chunk, clientReference);
1421
1960
  }
1422
1961
  }
1423
1962
  }
1424
1963
 
1425
- function serializeUndefined() {
1426
- return '$undefined';
1427
- }
1964
+ function resolveErrorDev(response, id, digest, message, stack) {
1428
1965
 
1429
- function serializeDateFromDateJSON(dateJSON) {
1430
- // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
1431
- // We need only tack on a $D prefix.
1432
- return '$D' + dateJSON;
1433
- }
1434
1966
 
1435
- function serializeBigInt(n) {
1436
- return '$n' + n.toString(10);
1437
- }
1967
+ var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
1968
+ error.stack = stack;
1969
+ error.digest = digest;
1970
+ var errorWithDigest = error;
1971
+ var chunks = response._chunks;
1972
+ var chunk = chunks.get(id);
1438
1973
 
1439
- function escapeStringValue(value) {
1440
- if (value[0] === '$') {
1441
- // We need to escape $ prefixed strings since we use those to encode
1442
- // references to IDs and as special symbol values.
1443
- return '$' + value;
1974
+ if (!chunk) {
1975
+ chunks.set(id, createErrorChunk(response, errorWithDigest));
1444
1976
  } else {
1445
- return value;
1977
+ triggerErrorOnChunk(chunk, errorWithDigest);
1446
1978
  }
1447
1979
  }
1448
1980
 
1449
- function processReply(root, formFieldPrefix, resolve, reject) {
1450
- var nextPartId = 1;
1451
- var pendingParts = 0;
1452
- var formData = null;
1981
+ function resolveHint(response, code, model) {
1982
+ var hintModel = parseModel(response, model);
1983
+ dispatchHint(code, hintModel);
1984
+ }
1453
1985
 
1454
- function resolveToJSON(key, value) {
1455
- var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
1986
+ function resolveDebugInfo(response, id, debugInfo) {
1456
1987
 
1457
- {
1458
- // $FlowFixMe[incompatible-use]
1459
- var originalValue = parent[key];
1988
+ var chunk = getChunk(response, id);
1989
+ var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
1990
+ chunkDebugInfo.push(debugInfo);
1991
+ }
1460
1992
 
1461
- if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1462
- if (objectName(originalValue) !== 'Object') {
1463
- error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
1464
- } else {
1465
- 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));
1466
- }
1467
- }
1468
- }
1993
+ function resolveConsoleEntry(response, value) {
1469
1994
 
1470
- if (value === null) {
1471
- return null;
1472
- }
1995
+ var payload = parseModel(response, value);
1996
+ var methodName = payload[0]; // TODO: Restore the fake stack before logging.
1997
+ // const stackTrace = payload[1];
1473
1998
 
1474
- if (typeof value === 'object') {
1475
- // $FlowFixMe[method-unbinding]
1476
- if (typeof value.then === 'function') {
1477
- // We assume that any object with a .then property is a "Thenable" type,
1478
- // or a Promise type. Either of which can be represented by a Promise.
1479
- if (formData === null) {
1480
- // Upgrade to use FormData to allow us to stream this value.
1481
- formData = new FormData();
1482
- }
1999
+ var env = payload[2];
2000
+ var args = payload.slice(3);
2001
+ printToConsole(methodName, args, env);
2002
+ }
1483
2003
 
1484
- pendingParts++;
1485
- var promiseId = nextPartId++;
1486
- var thenable = value;
1487
- thenable.then(function (partValue) {
1488
- var partJSON = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
2004
+ function processFullRow(response, id, tag, buffer, chunk) {
1489
2005
 
1490
- var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
2006
+ var stringDecoder = response._stringDecoder;
2007
+ var row = '';
1491
2008
 
1492
- data.append(formFieldPrefix + promiseId, partJSON);
1493
- pendingParts--;
2009
+ for (var i = 0; i < buffer.length; i++) {
2010
+ row += readPartialStringChunk(stringDecoder, buffer[i]);
2011
+ }
1494
2012
 
1495
- if (pendingParts === 0) {
1496
- resolve(data);
1497
- }
1498
- }, function (reason) {
1499
- // In the future we could consider serializing this as an error
1500
- // that throws on the server instead.
1501
- reject(reason);
1502
- });
1503
- return serializePromiseID(promiseId);
1504
- } // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
2013
+ row += readFinalStringChunk(stringDecoder, chunk);
1505
2014
 
2015
+ switch (tag) {
2016
+ case 73
2017
+ /* "I" */
2018
+ :
2019
+ {
2020
+ resolveModule(response, id, row);
2021
+ return;
2022
+ }
1506
2023
 
1507
- if (value instanceof FormData) {
1508
- if (formData === null) {
1509
- // Upgrade to use FormData to allow us to use rich objects as its values.
1510
- formData = new FormData();
1511
- }
2024
+ case 72
2025
+ /* "H" */
2026
+ :
2027
+ {
2028
+ var code = row[0];
2029
+ resolveHint(response, code, row.slice(1));
2030
+ return;
2031
+ }
1512
2032
 
1513
- var data = formData;
1514
- var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
1515
- // These must come first in the form order because we assume that all the
1516
- // fields are available before this is referenced.
2033
+ case 69
2034
+ /* "E" */
2035
+ :
2036
+ {
2037
+ var errorInfo = JSON.parse(row);
1517
2038
 
1518
- var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
2039
+ {
2040
+ resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
2041
+ }
1519
2042
 
1520
- value.forEach(function (originalValue, originalKey) {
1521
- data.append(prefix + originalKey, originalValue);
1522
- });
1523
- return serializeFormDataReference(refId);
2043
+ return;
2044
+ }
2045
+
2046
+ case 84
2047
+ /* "T" */
2048
+ :
2049
+ {
2050
+ resolveText(response, id, row);
2051
+ return;
1524
2052
  }
1525
2053
 
1526
- if (!isArray(value)) {
1527
- var iteratorFn = getIteratorFn(value);
2054
+ case 68
2055
+ /* "D" */
2056
+ :
2057
+ {
2058
+ {
2059
+ var debugInfo = JSON.parse(row);
2060
+ resolveDebugInfo(response, id, debugInfo);
2061
+ return;
2062
+ } // Fallthrough to share the error with Console entries.
2063
+
2064
+ }
1528
2065
 
1529
- if (iteratorFn) {
1530
- return Array.from(value);
2066
+ case 87
2067
+ /* "W" */
2068
+ :
2069
+ {
2070
+ {
2071
+ resolveConsoleEntry(response, row);
2072
+ return;
1531
2073
  }
1532
2074
  }
1533
2075
 
2076
+ case 80
2077
+ /* "P" */
2078
+ :
2079
+ // Fallthrough
2080
+
2081
+ default:
2082
+ /* """ "{" "[" "t" "f" "n" "0" - "9" */
1534
2083
  {
1535
- if (value !== null && !isArray(value)) {
1536
- // Verify that this is a simple plain object.
1537
- if (value.$$typeof === REACT_ELEMENT_TYPE) {
1538
- error('React Element cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
1539
- } else if (value.$$typeof === REACT_LAZY_TYPE) {
1540
- error('React Lazy cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
1541
- } else if (value.$$typeof === REACT_PROVIDER_TYPE) {
1542
- error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
1543
- } else if (objectName(value) !== 'Object') {
1544
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
1545
- } else if (!isSimpleObject(value)) {
1546
- error('Only plain objects can be passed to Client Components from Server Components. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
1547
- } else if (Object.getOwnPropertySymbols) {
1548
- var symbols = Object.getOwnPropertySymbols(value);
1549
-
1550
- if (symbols.length > 0) {
1551
- error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
1552
- }
2084
+ // We assume anything else is JSON.
2085
+ resolveModel(response, id, row);
2086
+ return;
2087
+ }
2088
+ }
2089
+ }
2090
+
2091
+ function processBinaryChunk(response, chunk) {
2092
+ var i = 0;
2093
+ var rowState = response._rowState;
2094
+ var rowID = response._rowID;
2095
+ var rowTag = response._rowTag;
2096
+ var rowLength = response._rowLength;
2097
+ var buffer = response._buffer;
2098
+ var chunkLength = chunk.length;
2099
+
2100
+ while (i < chunkLength) {
2101
+ var lastIdx = -1;
2102
+
2103
+ switch (rowState) {
2104
+ case ROW_ID:
2105
+ {
2106
+ var byte = chunk[i++];
2107
+
2108
+ if (byte === 58
2109
+ /* ":" */
2110
+ ) {
2111
+ // Finished the rowID, next we'll parse the tag.
2112
+ rowState = ROW_TAG;
2113
+ } else {
2114
+ rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
1553
2115
  }
2116
+
2117
+ continue;
1554
2118
  }
1555
- } // $FlowFixMe[incompatible-return]
1556
2119
 
2120
+ case ROW_TAG:
2121
+ {
2122
+ var resolvedRowTag = chunk[i];
2123
+
2124
+ if (resolvedRowTag === 84
2125
+ /* "T" */
2126
+ || enableBinaryFlight
2127
+ /* "V" */
2128
+ ) {
2129
+ rowTag = resolvedRowTag;
2130
+ rowState = ROW_LENGTH;
2131
+ i++;
2132
+ } else if (resolvedRowTag > 64 && resolvedRowTag < 91
2133
+ /* "A"-"Z" */
2134
+ ) {
2135
+ rowTag = resolvedRowTag;
2136
+ rowState = ROW_CHUNK_BY_NEWLINE;
2137
+ i++;
2138
+ } else {
2139
+ rowTag = 0;
2140
+ rowState = ROW_CHUNK_BY_NEWLINE; // This was an unknown tag so it was probably part of the data.
2141
+ }
1557
2142
 
1558
- return value;
1559
- }
2143
+ continue;
2144
+ }
1560
2145
 
1561
- if (typeof value === 'string') {
1562
- // TODO: Maybe too clever. If we support URL there's no similar trick.
1563
- if (value[value.length - 1] === 'Z') {
1564
- // Possibly a Date, whose toJSON automatically calls toISOString
1565
- // $FlowFixMe[incompatible-use]
1566
- var _originalValue = parent[key]; // $FlowFixMe[method-unbinding]
2146
+ case ROW_LENGTH:
2147
+ {
2148
+ var _byte = chunk[i++];
2149
+
2150
+ if (_byte === 44
2151
+ /* "," */
2152
+ ) {
2153
+ // Finished the rowLength, next we'll buffer up to that length.
2154
+ rowState = ROW_CHUNK_BY_LENGTH;
2155
+ } else {
2156
+ rowLength = rowLength << 4 | (_byte > 96 ? _byte - 87 : _byte - 48);
2157
+ }
1567
2158
 
1568
- if (_originalValue instanceof Date) {
1569
- return serializeDateFromDateJSON(value);
2159
+ continue;
1570
2160
  }
1571
- }
1572
2161
 
1573
- return escapeStringValue(value);
1574
- }
2162
+ case ROW_CHUNK_BY_NEWLINE:
2163
+ {
2164
+ // We're looking for a newline
2165
+ lastIdx = chunk.indexOf(10
2166
+ /* "\n" */
2167
+ , i);
2168
+ break;
2169
+ }
1575
2170
 
1576
- if (typeof value === 'boolean') {
1577
- return value;
1578
- }
2171
+ case ROW_CHUNK_BY_LENGTH:
2172
+ {
2173
+ // We're looking for the remaining byte length
2174
+ lastIdx = i + rowLength;
1579
2175
 
1580
- if (typeof value === 'number') {
1581
- return serializeNumber(value);
1582
- }
2176
+ if (lastIdx > chunk.length) {
2177
+ lastIdx = -1;
2178
+ }
1583
2179
 
1584
- if (typeof value === 'undefined') {
1585
- return serializeUndefined();
2180
+ break;
2181
+ }
1586
2182
  }
1587
2183
 
1588
- if (typeof value === 'function') {
1589
- var metaData = knownServerReferences.get(value);
1590
-
1591
- if (metaData !== undefined) {
1592
- var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
2184
+ var offset = chunk.byteOffset + i;
1593
2185
 
1594
- if (formData === null) {
1595
- // Upgrade to use FormData to allow us to stream this value.
1596
- formData = new FormData();
1597
- } // The reference to this function came from the same client so we can pass it back.
2186
+ if (lastIdx > -1) {
2187
+ // We found the last chunk of the row
2188
+ var length = lastIdx - i;
2189
+ var lastChunk = new Uint8Array(chunk.buffer, offset, length);
2190
+ processFullRow(response, rowID, rowTag, buffer, lastChunk); // Reset state machine for a new row
1598
2191
 
2192
+ i = lastIdx;
1599
2193
 
1600
- var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
2194
+ if (rowState === ROW_CHUNK_BY_NEWLINE) {
2195
+ // If we're trailing by a newline we need to skip it.
2196
+ i++;
2197
+ }
1601
2198
 
2199
+ rowState = ROW_ID;
2200
+ rowTag = 0;
2201
+ rowID = 0;
2202
+ rowLength = 0;
2203
+ buffer.length = 0;
2204
+ } else {
2205
+ // The rest of this row is in a future chunk. We stash the rest of the
2206
+ // current chunk until we can process the full row.
2207
+ var _length = chunk.byteLength - i;
1602
2208
 
1603
- formData.set(formFieldPrefix + _refId, metaDataJSON);
1604
- return serializeServerReferenceID(_refId);
1605
- }
2209
+ var remainingSlice = new Uint8Array(chunk.buffer, offset, _length);
2210
+ buffer.push(remainingSlice); // Update how many bytes we're still waiting for. If we're looking for
2211
+ // a newline, this doesn't hurt since we'll just ignore it.
1606
2212
 
1607
- throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
2213
+ rowLength -= remainingSlice.byteLength;
2214
+ break;
1608
2215
  }
2216
+ }
1609
2217
 
1610
- if (typeof value === 'symbol') {
1611
- // $FlowFixMe[incompatible-type] `description` might be undefined
1612
- var name = value.description;
2218
+ response._rowState = rowState;
2219
+ response._rowID = rowID;
2220
+ response._rowTag = rowTag;
2221
+ response._rowLength = rowLength;
2222
+ }
1613
2223
 
1614
- if (Symbol.for(name) !== value) {
1615
- throw new Error('Only global symbols received from Symbol.for(...) can be passed to Server Functions. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
1616
- value.description + ") cannot be found among global symbols."));
1617
- }
2224
+ function parseModel(response, json) {
2225
+ return JSON.parse(json, response._fromJSON);
2226
+ }
1618
2227
 
1619
- return serializeSymbolReference(name);
2228
+ function createFromJSONCallback(response) {
2229
+ // $FlowFixMe[missing-this-annot]
2230
+ return function (key, value) {
2231
+ if (typeof value === 'string') {
2232
+ // We can't use .bind here because we need the "this" value.
2233
+ return parseModelString(response, this, key, value);
1620
2234
  }
1621
2235
 
1622
- if (typeof value === 'bigint') {
1623
- return serializeBigInt(value);
2236
+ if (typeof value === 'object' && value !== null) {
2237
+ return parseModelTuple(response, value);
1624
2238
  }
1625
2239
 
1626
- throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
1627
- } // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
1628
-
1629
-
1630
- var json = JSON.stringify(root, resolveToJSON);
1631
-
1632
- if (formData === null) {
1633
- // If it's a simple data structure, we just use plain JSON.
1634
- resolve(json);
1635
- } else {
1636
- // Otherwise, we use FormData to let us stream in the result.
1637
- formData.set(formFieldPrefix + '0', json);
2240
+ return value;
2241
+ };
2242
+ }
1638
2243
 
1639
- if (pendingParts === 0) {
1640
- // $FlowFixMe[incompatible-call] this has already been refined.
1641
- resolve(formData);
1642
- }
1643
- }
2244
+ function close(response) {
2245
+ // In case there are any remaining unresolved chunks, they won't
2246
+ // be resolved now. So we need to issue an error to those.
2247
+ // Ideally we should be able to early bail out if we kept a
2248
+ // ref count of pending chunks.
2249
+ reportGlobalError(response, new Error('Connection closed.'));
1644
2250
  }
1645
2251
 
1646
2252
  function createResponseFromOptions(options) {
1647
- return createResponse(null, options && options.callServer ? options.callServer : undefined);
2253
+ return createResponse(null, null, options && options.callServer ? options.callServer : undefined, undefined, // encodeFormAction
2254
+ undefined, // nonce
2255
+ options && options.temporaryReferences ? options.temporaryReferences : undefined);
1648
2256
  }
1649
2257
 
1650
2258
  function startReadingFromStream(response, stream) {
@@ -1687,45 +2295,18 @@
1687
2295
  return getRoot(response);
1688
2296
  }
1689
2297
 
1690
- function createFromXHR(request, options) {
1691
- var response = createResponseFromOptions(options);
1692
- var processedLength = 0;
1693
-
1694
- function progress(e) {
1695
- var chunk = request.responseText;
1696
- processStringChunk(response, chunk, processedLength);
1697
- processedLength = chunk.length;
1698
- }
1699
-
1700
- function load(e) {
1701
- progress();
1702
- close(response);
1703
- }
1704
-
1705
- function error(e) {
1706
- reportGlobalError(response, new TypeError('Network error'));
1707
- }
1708
-
1709
- request.addEventListener('progress', progress);
1710
- request.addEventListener('load', load);
1711
- request.addEventListener('error', error);
1712
- request.addEventListener('abort', error);
1713
- request.addEventListener('timeout', error);
1714
- return getRoot(response);
1715
- }
1716
-
1717
- function encodeReply(value)
2298
+ function encodeReply(value, options)
1718
2299
  /* We don't use URLSearchParams yet but maybe */
1719
2300
  {
1720
2301
  return new Promise(function (resolve, reject) {
1721
- processReply(value, '', resolve, reject);
2302
+ processReply(value, '', options && options.temporaryReferences ? options.temporaryReferences : undefined, resolve, reject);
1722
2303
  });
1723
2304
  }
1724
2305
 
1725
2306
  exports.createFromFetch = createFromFetch;
1726
2307
  exports.createFromReadableStream = createFromReadableStream;
1727
- exports.createFromXHR = createFromXHR;
1728
2308
  exports.createServerReference = createServerReference;
2309
+ exports.createTemporaryReferenceSet = createTemporaryReferenceSet;
1729
2310
  exports.encodeReply = encodeReply;
1730
2311
 
1731
2312
  }));