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

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