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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +1768 -1188
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +1739 -0
  3. package/cjs/react-server-dom-webpack-client.browser.production.min.js +40 -34
  4. package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -0
  5. package/cjs/react-server-dom-webpack-client.edge.development.js +1755 -221
  6. package/cjs/react-server-dom-webpack-client.edge.production.js +1986 -0
  7. package/cjs/react-server-dom-webpack-client.edge.production.min.js +45 -28
  8. package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -0
  9. package/cjs/react-server-dom-webpack-client.node.development.js +1743 -239
  10. package/cjs/react-server-dom-webpack-client.node.production.js +1942 -0
  11. package/cjs/react-server-dom-webpack-client.node.production.min.js +44 -28
  12. package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -0
  13. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1702 -194
  14. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1895 -0
  15. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +43 -26
  16. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -0
  17. package/cjs/react-server-dom-webpack-node-register.js +12 -18
  18. package/cjs/react-server-dom-webpack-node-register.js.map +1 -0
  19. package/cjs/react-server-dom-webpack-plugin.js +22 -19
  20. package/cjs/react-server-dom-webpack-plugin.js.map +1 -0
  21. package/cjs/react-server-dom-webpack-server.browser.development.js +1588 -808
  22. package/cjs/react-server-dom-webpack-server.browser.production.js +3257 -0
  23. package/cjs/react-server-dom-webpack-server.browser.production.min.js +80 -62
  24. package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -0
  25. package/cjs/react-server-dom-webpack-server.edge.development.js +1583 -811
  26. package/cjs/react-server-dom-webpack-server.edge.production.js +3261 -0
  27. package/cjs/react-server-dom-webpack-server.edge.production.min.js +82 -62
  28. package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -0
  29. package/cjs/react-server-dom-webpack-server.node.development.js +1575 -805
  30. package/cjs/react-server-dom-webpack-server.node.production.js +3464 -0
  31. package/cjs/react-server-dom-webpack-server.node.production.min.js +85 -67
  32. package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -0
  33. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1526 -761
  34. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +3391 -0
  35. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +82 -65
  36. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -0
  37. package/esm/react-server-dom-webpack-node-loader.production.min.js +19 -12
  38. package/package.json +7 -13
  39. package/umd/react-server-dom-webpack-client.browser.development.js +1770 -1189
  40. package/umd/react-server-dom-webpack-client.browser.production.min.js +26 -20
  41. package/umd/react-server-dom-webpack-server.browser.development.js +1589 -808
  42. package/umd/react-server-dom-webpack-server.browser.production.min.js +55 -42
@@ -56,10 +56,13 @@ function printWarning(level, format, args) {
56
56
  }
57
57
  }
58
58
 
59
+ // -----------------------------------------------------------------------------
60
+ var enablePostpone = false;
61
+
59
62
  function scheduleWork(callback) {
60
63
  callback();
61
64
  }
62
- var VIEW_SIZE = 512;
65
+ var VIEW_SIZE = 2048;
63
66
  var currentView = null;
64
67
  var writtenBytes = 0;
65
68
  function beginWriting(destination) {
@@ -67,20 +70,14 @@ function beginWriting(destination) {
67
70
  writtenBytes = 0;
68
71
  }
69
72
  function writeChunk(destination, chunk) {
70
- if (chunk.length === 0) {
73
+ if (chunk.byteLength === 0) {
71
74
  return;
72
75
  }
73
76
 
74
- if (chunk.length > VIEW_SIZE) {
75
- {
76
- if (precomputedChunkSet.has(chunk)) {
77
- error('A large precomputed chunk was passed to writeChunk without being copied.' + ' Large chunks get enqueued directly and are not copied. This is incompatible with precomputed chunks because you cannot enqueue the same precomputed chunk twice.' + ' Use "cloneChunk" to make a copy of this large precomputed chunk before writing it. This is a bug in React.');
78
- }
79
- } // this chunk may overflow a single view which implies it was not
77
+ if (chunk.byteLength > VIEW_SIZE) {
78
+ // this chunk may overflow a single view which implies it was not
80
79
  // one that is cached by the streaming renderer. We will enqueu
81
80
  // it directly and expect it is not re-used
82
-
83
-
84
81
  if (writtenBytes > 0) {
85
82
  destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
86
83
  currentView = new Uint8Array(VIEW_SIZE);
@@ -94,7 +91,7 @@ function writeChunk(destination, chunk) {
94
91
  var bytesToWrite = chunk;
95
92
  var allowableBytes = currentView.length - writtenBytes;
96
93
 
97
- if (allowableBytes < bytesToWrite.length) {
94
+ if (allowableBytes < bytesToWrite.byteLength) {
98
95
  // this chunk would overflow the current view. We enqueue a full view
99
96
  // and start a new view with the remaining chunk
100
97
  if (allowableBytes === 0) {
@@ -114,7 +111,7 @@ function writeChunk(destination, chunk) {
114
111
  }
115
112
 
116
113
  currentView.set(bytesToWrite, writtenBytes);
117
- writtenBytes += bytesToWrite.length;
114
+ writtenBytes += bytesToWrite.byteLength;
118
115
  }
119
116
  function writeChunkAndReturn(destination, chunk) {
120
117
  writeChunk(destination, chunk); // in web streams there is no backpressure so we can alwas write more
@@ -135,7 +132,9 @@ var textEncoder = new TextEncoder();
135
132
  function stringToChunk(content) {
136
133
  return textEncoder.encode(content);
137
134
  }
138
- var precomputedChunkSet = new Set() ;
135
+ function byteLengthOfChunk(chunk) {
136
+ return chunk.byteLength;
137
+ }
139
138
  function closeWithError(destination, error) {
140
139
  // $FlowFixMe[method-unbinding]
141
140
  if (typeof destination.error === 'function') {
@@ -152,65 +151,270 @@ function closeWithError(destination, error) {
152
151
  }
153
152
  }
154
153
 
155
- // This file is an intermediate layer to translate between Flight
156
- var stringify = JSON.stringify;
157
-
158
- function serializeRowHeader(tag, id) {
159
- return id.toString(16) + ':' + tag;
154
+ // eslint-disable-next-line no-unused-vars
155
+ var CLIENT_REFERENCE_TAG$1 = Symbol.for('react.client.reference');
156
+ var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
157
+ function isClientReference(reference) {
158
+ return reference.$$typeof === CLIENT_REFERENCE_TAG$1;
159
+ }
160
+ function isServerReference(reference) {
161
+ return reference.$$typeof === SERVER_REFERENCE_TAG;
162
+ }
163
+ function registerClientReference(proxyImplementation, id, exportName) {
164
+ return registerClientReferenceImpl(proxyImplementation, id + '#' + exportName, false);
160
165
  }
161
166
 
162
- function processErrorChunkProd(request, id, digest) {
163
- {
164
- // These errors should never make it into a build so we don't need to encode them in codes.json
165
- // eslint-disable-next-line react-internal/prod-error-codes
166
- throw new Error('processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.');
167
+ function registerClientReferenceImpl(proxyImplementation, id, async) {
168
+ return Object.defineProperties(proxyImplementation, {
169
+ $$typeof: {
170
+ value: CLIENT_REFERENCE_TAG$1
171
+ },
172
+ $$id: {
173
+ value: id
174
+ },
175
+ $$async: {
176
+ value: async
177
+ }
178
+ });
179
+ } // $FlowFixMe[method-unbinding]
180
+
181
+
182
+ var FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
183
+
184
+ var ArraySlice = Array.prototype.slice;
185
+
186
+ function bind() {
187
+ // $FlowFixMe[unsupported-syntax]
188
+ var newFn = FunctionBind.apply(this, arguments);
189
+
190
+ if (this.$$typeof === SERVER_REFERENCE_TAG) {
191
+ {
192
+ var thisBind = arguments[0];
193
+
194
+ if (thisBind != null) {
195
+ error('Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().');
196
+ }
197
+ }
198
+
199
+ var args = ArraySlice.call(arguments, 1);
200
+ return Object.defineProperties(newFn, {
201
+ $$typeof: {
202
+ value: SERVER_REFERENCE_TAG
203
+ },
204
+ $$id: {
205
+ value: this.$$id
206
+ },
207
+ $$bound: {
208
+ value: this.$$bound ? this.$$bound.concat(args) : args
209
+ },
210
+ bind: {
211
+ value: bind
212
+ }
213
+ });
167
214
  }
168
- }
169
- function processErrorChunkDev(request, id, digest, message, stack) {
170
215
 
171
- var errorInfo = {
172
- digest: digest,
173
- message: message,
174
- stack: stack
175
- };
176
- var row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
177
- return stringToChunk(row);
178
- }
179
- function processModelChunk(request, id, model) {
180
- // $FlowFixMe[incompatible-type] stringify can return null
181
- var json = stringify(model, request.toJSON);
182
- var row = id.toString(16) + ':' + json + '\n';
183
- return stringToChunk(row);
216
+ return newFn;
184
217
  }
185
- function processReferenceChunk(request, id, reference) {
186
- var json = stringify(reference);
187
- var row = id.toString(16) + ':' + json + '\n';
188
- return stringToChunk(row);
218
+
219
+ function registerServerReference(reference, id, exportName) {
220
+ return Object.defineProperties(reference, {
221
+ $$typeof: {
222
+ value: SERVER_REFERENCE_TAG
223
+ },
224
+ $$id: {
225
+ value: exportName === null ? id : id + '#' + exportName,
226
+ configurable: true
227
+ },
228
+ $$bound: {
229
+ value: null,
230
+ configurable: true
231
+ },
232
+ bind: {
233
+ value: bind,
234
+ configurable: true
235
+ }
236
+ });
189
237
  }
190
- function processImportChunk(request, id, clientReferenceMetadata) {
191
- // $FlowFixMe[incompatible-type] stringify can return null
192
- var json = stringify(clientReferenceMetadata);
193
- var row = serializeRowHeader('I', id) + json + '\n';
194
- return stringToChunk(row);
238
+ var PROMISE_PROTOTYPE = Promise.prototype;
239
+ var deepProxyHandlers = {
240
+ get: function (target, name, receiver) {
241
+ switch (name) {
242
+ // These names are read by the Flight runtime if you end up using the exports object.
243
+ case '$$typeof':
244
+ // These names are a little too common. We should probably have a way to
245
+ // have the Flight runtime extract the inner target instead.
246
+ return target.$$typeof;
247
+
248
+ case '$$id':
249
+ return target.$$id;
250
+
251
+ case '$$async':
252
+ return target.$$async;
253
+
254
+ case 'name':
255
+ return target.name;
256
+
257
+ case 'displayName':
258
+ return undefined;
259
+ // We need to special case this because createElement reads it if we pass this
260
+ // reference.
261
+
262
+ case 'defaultProps':
263
+ return undefined;
264
+ // Avoid this attempting to be serialized.
265
+
266
+ case 'toJSON':
267
+ return undefined;
268
+
269
+ case Symbol.toPrimitive:
270
+ // $FlowFixMe[prop-missing]
271
+ return Object.prototype[Symbol.toPrimitive];
272
+
273
+ case Symbol.toStringTag:
274
+ // $FlowFixMe[prop-missing]
275
+ return Object.prototype[Symbol.toStringTag];
276
+
277
+ case 'Provider':
278
+ throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
279
+ } // eslint-disable-next-line react-internal/safe-string-coercion
280
+
281
+
282
+ var expression = String(target.name) + '.' + String(name);
283
+ throw new Error("Cannot access " + expression + " on the server. " + 'You cannot dot into a client module from a server component. ' + 'You can only pass the imported name through.');
284
+ },
285
+ set: function () {
286
+ throw new Error('Cannot assign to a client module from a server module.');
287
+ }
288
+ };
289
+
290
+ function getReference(target, name) {
291
+ switch (name) {
292
+ // These names are read by the Flight runtime if you end up using the exports object.
293
+ case '$$typeof':
294
+ return target.$$typeof;
295
+
296
+ case '$$id':
297
+ return target.$$id;
298
+
299
+ case '$$async':
300
+ return target.$$async;
301
+
302
+ case 'name':
303
+ return target.name;
304
+ // We need to special case this because createElement reads it if we pass this
305
+ // reference.
306
+
307
+ case 'defaultProps':
308
+ return undefined;
309
+ // Avoid this attempting to be serialized.
310
+
311
+ case 'toJSON':
312
+ return undefined;
313
+
314
+ case Symbol.toPrimitive:
315
+ // $FlowFixMe[prop-missing]
316
+ return Object.prototype[Symbol.toPrimitive];
317
+
318
+ case Symbol.toStringTag:
319
+ // $FlowFixMe[prop-missing]
320
+ return Object.prototype[Symbol.toStringTag];
321
+
322
+ case '__esModule':
323
+ // Something is conditionally checking which export to use. We'll pretend to be
324
+ // an ESM compat module but then we'll check again on the client.
325
+ var moduleId = target.$$id;
326
+ target.default = registerClientReferenceImpl(function () {
327
+ throw new Error("Attempted to call the default export of " + moduleId + " from the server " + "but it's on the client. It's not possible to invoke a client function from " + "the server, it can only be rendered as a Component or passed to props of a " + "Client Component.");
328
+ }, target.$$id + '#', target.$$async);
329
+ return true;
330
+
331
+ case 'then':
332
+ if (target.then) {
333
+ // Use a cached value
334
+ return target.then;
335
+ }
336
+
337
+ if (!target.$$async) {
338
+ // If this module is expected to return a Promise (such as an AsyncModule) then
339
+ // we should resolve that with a client reference that unwraps the Promise on
340
+ // the client.
341
+ var clientReference = registerClientReferenceImpl({}, target.$$id, true);
342
+ var proxy = new Proxy(clientReference, proxyHandlers$1); // Treat this as a resolved Promise for React's use()
343
+
344
+ target.status = 'fulfilled';
345
+ target.value = proxy;
346
+ var then = target.then = registerClientReferenceImpl(function then(resolve, reject) {
347
+ // Expose to React.
348
+ return Promise.resolve(resolve(proxy));
349
+ }, // If this is not used as a Promise but is treated as a reference to a `.then`
350
+ // export then we should treat it as a reference to that name.
351
+ target.$$id + '#then', false);
352
+ return then;
353
+ } else {
354
+ // Since typeof .then === 'function' is a feature test we'd continue recursing
355
+ // indefinitely if we return a function. Instead, we return an object reference
356
+ // if we check further.
357
+ return undefined;
358
+ }
359
+
360
+ }
361
+
362
+ if (typeof name === 'symbol') {
363
+ throw new Error('Cannot read Symbol exports. Only named exports are supported on a client module ' + 'imported on the server.');
364
+ }
365
+
366
+ var cachedReference = target[name];
367
+
368
+ if (!cachedReference) {
369
+ var reference = registerClientReferenceImpl(function () {
370
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
371
+ "Attempted to call " + String(name) + "() from the server but " + String(name) + " is on the client. " + "It's not possible to invoke a client function from the server, it can " + "only be rendered as a Component or passed to props of a Client Component.");
372
+ }, target.$$id + '#' + name, target.$$async);
373
+ Object.defineProperty(reference, 'name', {
374
+ value: name
375
+ });
376
+ cachedReference = target[name] = new Proxy(reference, deepProxyHandlers);
377
+ }
378
+
379
+ return cachedReference;
195
380
  }
196
- function processHintChunk(request, id, code, model) {
197
- var json = stringify(model);
198
- var row = serializeRowHeader('H' + code, id) + json + '\n';
199
- return stringToChunk(row);
381
+
382
+ var proxyHandlers$1 = {
383
+ get: function (target, name, receiver) {
384
+ return getReference(target, name);
385
+ },
386
+ getOwnPropertyDescriptor: function (target, name) {
387
+ var descriptor = Object.getOwnPropertyDescriptor(target, name);
388
+
389
+ if (!descriptor) {
390
+ descriptor = {
391
+ value: getReference(target, name),
392
+ writable: false,
393
+ configurable: false,
394
+ enumerable: false
395
+ };
396
+ Object.defineProperty(target, name, descriptor);
397
+ }
398
+
399
+ return descriptor;
400
+ },
401
+ getPrototypeOf: function (target) {
402
+ // Pretend to be a Promise in case anyone asks.
403
+ return PROMISE_PROTOTYPE;
404
+ },
405
+ set: function () {
406
+ throw new Error('Cannot assign to a client module from a server module.');
407
+ }
408
+ };
409
+ function createClientModuleProxy(moduleId) {
410
+ var clientReference = registerClientReferenceImpl({}, // Represents the whole Module object instead of a particular import.
411
+ moduleId, false);
412
+ return new Proxy(clientReference, proxyHandlers$1);
200
413
  }
201
414
 
202
- // eslint-disable-next-line no-unused-vars
203
- var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
204
- var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
205
415
  function getClientReferenceKey(reference) {
206
416
  return reference.$$async ? reference.$$id + '#async' : reference.$$id;
207
417
  }
208
- function isClientReference(reference) {
209
- return reference.$$typeof === CLIENT_REFERENCE_TAG;
210
- }
211
- function isServerReference(reference) {
212
- return reference.$$typeof === SERVER_REFERENCE_TAG;
213
- }
214
418
  function resolveClientReferenceMetadata(config, clientReference) {
215
419
  var modulePath = clientReference.$$id;
216
420
  var name = '';
@@ -236,12 +440,11 @@ function resolveClientReferenceMetadata(config, clientReference) {
236
440
  }
237
441
  }
238
442
 
239
- return {
240
- id: resolvedModuleData.id,
241
- chunks: resolvedModuleData.chunks,
242
- name: name,
243
- async: !!clientReference.$$async
244
- };
443
+ if (clientReference.$$async === true) {
444
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1];
445
+ } else {
446
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
447
+ }
245
448
  }
246
449
  function getServerReferenceId(config, serverReference) {
247
450
  return serverReference.$$id;
@@ -252,337 +455,357 @@ function getServerReferenceBoundArguments(config, serverReference) {
252
455
 
253
456
  var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
254
457
 
255
- var ReactDOMFlightServerDispatcher = {
458
+ var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
459
+ var previousDispatcher = ReactDOMCurrentDispatcher.current;
460
+ ReactDOMCurrentDispatcher.current = {
256
461
  prefetchDNS: prefetchDNS,
257
462
  preconnect: preconnect,
258
463
  preload: preload,
259
- preinit: preinit
464
+ preloadModule: preloadModule$1,
465
+ preinitStyle: preinitStyle,
466
+ preinitScript: preinitScript,
467
+ preinitModuleScript: preinitModuleScript
260
468
  };
261
469
 
262
- function prefetchDNS(href, options) {
263
- {
264
- if (typeof href === 'string') {
265
- var request = resolveRequest();
470
+ function prefetchDNS(href) {
471
+ if (typeof href === 'string' && href) {
472
+ var request = resolveRequest();
266
473
 
267
- if (request) {
268
- var hints = getHints(request);
269
- var key = 'D' + href;
474
+ if (request) {
475
+ var hints = getHints(request);
476
+ var key = 'D|' + href;
270
477
 
271
- if (hints.has(key)) {
272
- // duplicate hint
273
- return;
274
- }
275
-
276
- hints.add(key);
277
-
278
- if (options) {
279
- emitHint(request, 'D', [href, options]);
280
- } else {
281
- emitHint(request, 'D', href);
282
- }
478
+ if (hints.has(key)) {
479
+ // duplicate hint
480
+ return;
283
481
  }
482
+
483
+ hints.add(key);
484
+ emitHint(request, 'D', href);
485
+ } else {
486
+ previousDispatcher.prefetchDNS(href);
284
487
  }
285
488
  }
286
489
  }
287
490
 
288
- function preconnect(href, options) {
289
- {
290
- if (typeof href === 'string') {
291
- var request = resolveRequest();
491
+ function preconnect(href, crossOrigin) {
492
+ if (typeof href === 'string') {
493
+ var request = resolveRequest();
292
494
 
293
- if (request) {
294
- var hints = getHints(request);
295
- var crossOrigin = options == null || typeof options.crossOrigin !== 'string' ? null : options.crossOrigin === 'use-credentials' ? 'use-credentials' : '';
296
- var key = "C" + (crossOrigin === null ? 'null' : crossOrigin) + "|" + href;
495
+ if (request) {
496
+ var hints = getHints(request);
497
+ var key = "C|" + (crossOrigin == null ? 'null' : crossOrigin) + "|" + href;
297
498
 
298
- if (hints.has(key)) {
299
- // duplicate hint
300
- return;
301
- }
499
+ if (hints.has(key)) {
500
+ // duplicate hint
501
+ return;
502
+ }
302
503
 
303
- hints.add(key);
504
+ hints.add(key);
304
505
 
305
- if (options) {
306
- emitHint(request, 'C', [href, options]);
307
- } else {
308
- emitHint(request, 'C', href);
309
- }
506
+ if (typeof crossOrigin === 'string') {
507
+ emitHint(request, 'C', [href, crossOrigin]);
508
+ } else {
509
+ emitHint(request, 'C', href);
310
510
  }
511
+ } else {
512
+ previousDispatcher.preconnect(href, crossOrigin);
311
513
  }
312
514
  }
313
515
  }
314
516
 
315
- function preload(href, options) {
316
- {
317
- if (typeof href === 'string') {
318
- var request = resolveRequest();
517
+ function preload(href, as, options) {
518
+ if (typeof href === 'string') {
519
+ var request = resolveRequest();
319
520
 
320
- if (request) {
321
- var hints = getHints(request);
322
- var key = 'L' + href;
521
+ if (request) {
522
+ var hints = getHints(request);
523
+ var key = 'L';
323
524
 
324
- if (hints.has(key)) {
325
- // duplicate hint
326
- return;
327
- }
525
+ if (as === 'image' && options) {
526
+ key += getImagePreloadKey(href, options.imageSrcSet, options.imageSizes);
527
+ } else {
528
+ key += "[" + as + "]" + href;
529
+ }
530
+
531
+ if (hints.has(key)) {
532
+ // duplicate hint
533
+ return;
534
+ }
535
+
536
+ hints.add(key);
537
+ var trimmed = trimOptions(options);
328
538
 
329
- hints.add(key);
330
- emitHint(request, 'L', [href, options]);
539
+ if (trimmed) {
540
+ emitHint(request, 'L', [href, as, trimmed]);
541
+ } else {
542
+ emitHint(request, 'L', [href, as]);
331
543
  }
544
+ } else {
545
+ previousDispatcher.preload(href, as, options);
332
546
  }
333
547
  }
334
548
  }
335
549
 
336
- function preinit(href, options) {
337
- {
338
- if (typeof href === 'string') {
339
- var request = resolveRequest();
550
+ function preloadModule$1(href, options) {
551
+ if (typeof href === 'string') {
552
+ var request = resolveRequest();
340
553
 
341
- if (request) {
342
- var hints = getHints(request);
343
- var key = 'I' + href;
554
+ if (request) {
555
+ var hints = getHints(request);
556
+ var key = 'm|' + href;
344
557
 
345
- if (hints.has(key)) {
346
- // duplicate hint
347
- return;
348
- }
558
+ if (hints.has(key)) {
559
+ // duplicate hint
560
+ return;
561
+ }
349
562
 
350
- hints.add(key);
351
- emitHint(request, 'I', [href, options]);
563
+ hints.add(key);
564
+ var trimmed = trimOptions(options);
565
+
566
+ if (trimmed) {
567
+ return emitHint(request, 'm', [href, trimmed]);
568
+ } else {
569
+ return emitHint(request, 'm', href);
352
570
  }
571
+ } else {
572
+ previousDispatcher.preloadModule(href, options);
353
573
  }
354
574
  }
355
575
  }
356
576
 
357
- var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
358
- function prepareHostDispatcher() {
359
- ReactDOMCurrentDispatcher.current = ReactDOMFlightServerDispatcher;
360
- } // Used to distinguish these contexts from ones used in other renderers.
361
- function createHints() {
362
- return new Set();
363
- }
577
+ function preinitStyle(href, precedence, options) {
578
+ if (typeof href === 'string') {
579
+ var request = resolveRequest();
364
580
 
365
- // ATTENTION
366
- // When adding new symbols to this file,
367
- // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
368
- // The Symbol used to tag the ReactElement-like types.
369
- var REACT_ELEMENT_TYPE = Symbol.for('react.element');
370
- var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
371
- var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
372
- var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
373
- var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
374
- var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
375
- var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
376
- var REACT_MEMO_TYPE = Symbol.for('react.memo');
377
- var REACT_LAZY_TYPE = Symbol.for('react.lazy');
378
- var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
379
- var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
380
- var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
381
- var FAUX_ITERATOR_SYMBOL = '@@iterator';
382
- function getIteratorFn(maybeIterable) {
383
- if (maybeIterable === null || typeof maybeIterable !== 'object') {
384
- return null;
385
- }
581
+ if (request) {
582
+ var hints = getHints(request);
583
+ var key = 'S|' + href;
386
584
 
387
- var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
585
+ if (hints.has(key)) {
586
+ // duplicate hint
587
+ return;
588
+ }
388
589
 
389
- if (typeof maybeIterator === 'function') {
390
- return maybeIterator;
391
- }
590
+ hints.add(key);
591
+ var trimmed = trimOptions(options);
392
592
 
393
- return null;
593
+ if (trimmed) {
594
+ return emitHint(request, 'S', [href, typeof precedence === 'string' ? precedence : 0, trimmed]);
595
+ } else if (typeof precedence === 'string') {
596
+ return emitHint(request, 'S', [href, precedence]);
597
+ } else {
598
+ return emitHint(request, 'S', href);
599
+ }
600
+ } else {
601
+ previousDispatcher.preinitStyle(href, precedence, options);
602
+ }
603
+ }
394
604
  }
395
605
 
396
- var rendererSigil;
606
+ function preinitScript(src, options) {
607
+ if (typeof src === 'string') {
608
+ var request = resolveRequest();
397
609
 
398
- {
399
- // Use this to detect multiple renderers using the same context
400
- rendererSigil = {};
401
- } // Used to store the parent path of all context overrides in a shared linked list.
402
- // Forming a reverse tree.
403
- // The structure of a context snapshot is an implementation of this file.
404
- // Currently, it's implemented as tracking the current active node.
610
+ if (request) {
611
+ var hints = getHints(request);
612
+ var key = 'X|' + src;
405
613
 
614
+ if (hints.has(key)) {
615
+ // duplicate hint
616
+ return;
617
+ }
406
618
 
407
- var rootContextSnapshot = null; // We assume that this runtime owns the "current" field on all ReactContext instances.
408
- // This global (actually thread local) state represents what state all those "current",
409
- // fields are currently in.
410
-
411
- var currentActiveSnapshot = null;
619
+ hints.add(key);
620
+ var trimmed = trimOptions(options);
412
621
 
413
- function popNode(prev) {
414
- {
415
- prev.context._currentValue = prev.parentValue;
622
+ if (trimmed) {
623
+ return emitHint(request, 'X', [src, trimmed]);
624
+ } else {
625
+ return emitHint(request, 'X', src);
626
+ }
627
+ } else {
628
+ previousDispatcher.preinitScript(src, options);
629
+ }
416
630
  }
417
631
  }
418
632
 
419
- function pushNode(next) {
420
- {
421
- next.context._currentValue = next.value;
422
- }
423
- }
633
+ function preinitModuleScript(src, options) {
634
+ if (typeof src === 'string') {
635
+ var request = resolveRequest();
424
636
 
425
- function popToNearestCommonAncestor(prev, next) {
426
- if (prev === next) ; else {
427
- popNode(prev);
428
- var parentPrev = prev.parent;
429
- var parentNext = next.parent;
637
+ if (request) {
638
+ var hints = getHints(request);
639
+ var key = 'M|' + src;
430
640
 
431
- if (parentPrev === null) {
432
- if (parentNext !== null) {
433
- throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
434
- }
435
- } else {
436
- if (parentNext === null) {
437
- throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
641
+ if (hints.has(key)) {
642
+ // duplicate hint
643
+ return;
438
644
  }
439
645
 
440
- popToNearestCommonAncestor(parentPrev, parentNext); // On the way back, we push the new ones that weren't common.
646
+ hints.add(key);
647
+ var trimmed = trimOptions(options);
441
648
 
442
- pushNode(next);
649
+ if (trimmed) {
650
+ return emitHint(request, 'M', [src, trimmed]);
651
+ } else {
652
+ return emitHint(request, 'M', src);
653
+ }
654
+ } else {
655
+ previousDispatcher.preinitModuleScript(src, options);
443
656
  }
444
657
  }
445
- }
446
-
447
- function popAllPrevious(prev) {
448
- popNode(prev);
449
- var parentPrev = prev.parent;
658
+ } // Flight normally encodes undefined as a special character however for directive option
659
+ // arguments we don't want to send unnecessary keys and bloat the payload so we create a
660
+ // trimmed object which omits any keys with null or undefined values.
661
+ // This is only typesafe because these option objects have entirely optional fields where
662
+ // null and undefined represent the same thing as no property.
450
663
 
451
- if (parentPrev !== null) {
452
- popAllPrevious(parentPrev);
453
- }
454
- }
455
664
 
456
- function pushAllNext(next) {
457
- var parentNext = next.parent;
665
+ function trimOptions(options) {
666
+ if (options == null) return null;
667
+ var hasProperties = false;
668
+ var trimmed = {};
458
669
 
459
- if (parentNext !== null) {
460
- pushAllNext(parentNext);
670
+ for (var key in options) {
671
+ if (options[key] != null) {
672
+ hasProperties = true;
673
+ trimmed[key] = options[key];
674
+ }
461
675
  }
462
676
 
463
- pushNode(next);
677
+ return hasProperties ? trimmed : null;
464
678
  }
465
679
 
466
- function popPreviousToCommonLevel(prev, next) {
467
- popNode(prev);
468
- var parentPrev = prev.parent;
680
+ function getImagePreloadKey(href, imageSrcSet, imageSizes) {
681
+ var uniquePart = '';
469
682
 
470
- if (parentPrev === null) {
471
- throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
472
- }
683
+ if (typeof imageSrcSet === 'string' && imageSrcSet !== '') {
684
+ uniquePart += '[' + imageSrcSet + ']';
473
685
 
474
- if (parentPrev.depth === next.depth) {
475
- // We found the same level. Now we just need to find a shared ancestor.
476
- popToNearestCommonAncestor(parentPrev, next);
686
+ if (typeof imageSizes === 'string') {
687
+ uniquePart += '[' + imageSizes + ']';
688
+ }
477
689
  } else {
478
- // We must still be deeper.
479
- popPreviousToCommonLevel(parentPrev, next);
690
+ uniquePart += '[][]' + href;
480
691
  }
692
+
693
+ return "[image]" + uniquePart;
481
694
  }
482
695
 
483
- function popNextToCommonLevel(prev, next) {
484
- var parentNext = next.parent;
696
+ // This module registers the host dispatcher so it needs to be imported
697
+ // small, smaller than how we encode undefined, and is unambiguous. We could use
698
+ // a different tuple structure to encode this instead but this makes the runtime
699
+ // cost cheaper by eliminating a type checks in more positions.
700
+ // prettier-ignore
485
701
 
486
- if (parentNext === null) {
487
- throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
488
- }
702
+ function createHints() {
703
+ return new Set();
704
+ }
489
705
 
490
- if (prev.depth === parentNext.depth) {
491
- // We found the same level. Now we just need to find a shared ancestor.
492
- popToNearestCommonAncestor(prev, parentNext);
493
- } else {
494
- // We must still be deeper.
495
- popNextToCommonLevel(prev, parentNext);
496
- }
497
-
498
- pushNode(next);
499
- } // Perform context switching to the new snapshot.
500
- // To make it cheap to read many contexts, while not suspending, we make the switch eagerly by
501
- // updating all the context's current values. That way reads, always just read the current value.
502
- // At the cost of updating contexts even if they're never read by this subtree.
503
-
504
-
505
- function switchContext(newSnapshot) {
506
- // The basic algorithm we need to do is to pop back any contexts that are no longer on the stack.
507
- // We also need to update any new contexts that are now on the stack with the deepest value.
508
- // The easiest way to update new contexts is to just reapply them in reverse order from the
509
- // perspective of the backpointers. To avoid allocating a lot when switching, we use the stack
510
- // for that. Therefore this algorithm is recursive.
511
- // 1) First we pop which ever snapshot tree was deepest. Popping old contexts as we go.
512
- // 2) Then we find the nearest common ancestor from there. Popping old contexts as we go.
513
- // 3) Then we reapply new contexts on the way back up the stack.
514
- var prev = currentActiveSnapshot;
515
- var next = newSnapshot;
516
-
517
- if (prev !== next) {
518
- if (prev === null) {
519
- // $FlowFixMe[incompatible-call]: This has to be non-null since it's not equal to prev.
520
- pushAllNext(next);
521
- } else if (next === null) {
522
- popAllPrevious(prev);
523
- } else if (prev.depth === next.depth) {
524
- popToNearestCommonAncestor(prev, next);
525
- } else if (prev.depth > next.depth) {
526
- popPreviousToCommonLevel(prev, next);
527
- } else {
528
- popNextToCommonLevel(prev, next);
529
- }
706
+ var supportsRequestStorage = false;
707
+ var requestStorage = null;
530
708
 
531
- currentActiveSnapshot = next;
532
- }
709
+ var TEMPORARY_REFERENCE_TAG = Symbol.for('react.temporary.reference'); // eslint-disable-next-line no-unused-vars
710
+
711
+ function isTemporaryReference(reference) {
712
+ return reference.$$typeof === TEMPORARY_REFERENCE_TAG;
713
+ }
714
+ function resolveTemporaryReferenceID(temporaryReference) {
715
+ return temporaryReference.$$id;
533
716
  }
534
- function pushProvider(context, nextValue) {
535
- var prevValue;
717
+ var proxyHandlers = {
718
+ get: function (target, name, receiver) {
719
+ switch (name) {
720
+ // These names are read by the Flight runtime if you end up using the exports object.
721
+ case '$$typeof':
722
+ // These names are a little too common. We should probably have a way to
723
+ // have the Flight runtime extract the inner target instead.
724
+ return target.$$typeof;
536
725
 
537
- {
538
- prevValue = context._currentValue;
539
- context._currentValue = nextValue;
726
+ case '$$id':
727
+ return target.$$id;
540
728
 
541
- {
542
- if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
543
- error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
544
- }
729
+ case '$$async':
730
+ return target.$$async;
731
+
732
+ case 'name':
733
+ return undefined;
734
+
735
+ case 'displayName':
736
+ return undefined;
737
+ // We need to special case this because createElement reads it if we pass this
738
+ // reference.
739
+
740
+ case 'defaultProps':
741
+ return undefined;
742
+ // Avoid this attempting to be serialized.
743
+
744
+ case 'toJSON':
745
+ return undefined;
746
+
747
+ case Symbol.toPrimitive:
748
+ // $FlowFixMe[prop-missing]
749
+ return Object.prototype[Symbol.toPrimitive];
750
+
751
+ case Symbol.toStringTag:
752
+ // $FlowFixMe[prop-missing]
753
+ return Object.prototype[Symbol.toStringTag];
545
754
 
546
- context._currentRenderer = rendererSigil;
755
+ case 'Provider':
756
+ throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
547
757
  }
548
- }
549
758
 
550
- var prevNode = currentActiveSnapshot;
551
- var newNode = {
552
- parent: prevNode,
553
- depth: prevNode === null ? 0 : prevNode.depth + 1,
554
- context: context,
555
- parentValue: prevValue,
556
- value: nextValue
557
- };
558
- currentActiveSnapshot = newNode;
559
- return newNode;
759
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
760
+ "Cannot access " + String(name) + " on the server. " + 'You cannot dot into a temporary client reference from a server component. ' + 'You can only pass the value through to the client.');
761
+ },
762
+ set: function () {
763
+ throw new Error('Cannot assign to a temporary client reference from a server module.');
764
+ }
765
+ };
766
+ function createTemporaryReference(id) {
767
+ var reference = Object.defineProperties(function () {
768
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
769
+ "Attempted to call a temporary Client Reference from the server but it is on the client. " + "It's not possible to invoke a client function from the server, it can " + "only be rendered as a Component or passed to props of a Client Component.");
770
+ }, {
771
+ $$typeof: {
772
+ value: TEMPORARY_REFERENCE_TAG
773
+ },
774
+ $$id: {
775
+ value: id
776
+ }
777
+ });
778
+ return new Proxy(reference, proxyHandlers);
560
779
  }
561
- function popProvider() {
562
- var prevSnapshot = currentActiveSnapshot;
563
780
 
564
- if (prevSnapshot === null) {
565
- throw new Error('Tried to pop a Context at the root of the app. This is a bug in React.');
781
+ // ATTENTION
782
+ // When adding new symbols to this file,
783
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
784
+ // The Symbol used to tag the ReactElement-like types.
785
+ var REACT_ELEMENT_TYPE = Symbol.for('react.element');
786
+ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
787
+ var REACT_CONTEXT_TYPE = Symbol.for('react.context');
788
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
789
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
790
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
791
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
792
+ var REACT_LAZY_TYPE = Symbol.for('react.lazy');
793
+ var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
794
+ var REACT_POSTPONE_TYPE = Symbol.for('react.postpone');
795
+ var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
796
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
797
+ function getIteratorFn(maybeIterable) {
798
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
799
+ return null;
566
800
  }
567
801
 
568
- {
569
- var value = prevSnapshot.parentValue;
802
+ var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
570
803
 
571
- if (value === REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED) {
572
- prevSnapshot.context._currentValue = prevSnapshot.context._defaultValue;
573
- } else {
574
- prevSnapshot.context._currentValue = value;
575
- }
804
+ if (typeof maybeIterator === 'function') {
805
+ return maybeIterator;
576
806
  }
577
807
 
578
- return currentActiveSnapshot = prevSnapshot.parent;
579
- }
580
- function getActiveContext() {
581
- return currentActiveSnapshot;
582
- }
583
- function readContext$1(context) {
584
- var value = context._currentValue ;
585
- return value;
808
+ return null;
586
809
  }
587
810
 
588
811
  // Corresponds to ReactFiberWakeable and ReactFizzWakeable modules. Generally,
@@ -713,29 +936,13 @@ function prepareToUseHooksForComponent(prevThenableState) {
713
936
  thenableState = prevThenableState;
714
937
  }
715
938
  function getThenableStateAfterSuspending() {
716
- var state = thenableState;
939
+ // If you use() to Suspend this should always exist but if you throw a Promise instead,
940
+ // which is not really supported anymore, it will be empty. We use the empty set as a
941
+ // marker to know if this was a replay of the same component or first attempt.
942
+ var state = thenableState || createThenableState();
717
943
  thenableState = null;
718
944
  return state;
719
945
  }
720
-
721
- function readContext(context) {
722
- {
723
- if (context.$$typeof !== REACT_SERVER_CONTEXT_TYPE) {
724
- if (isClientReference(context)) {
725
- error('Cannot read a Client Context from a Server Component.');
726
- } else {
727
- error('Only createServerContext is supported in Server Components.');
728
- }
729
- }
730
-
731
- if (currentRequest$1 === null) {
732
- error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
733
- }
734
- }
735
-
736
- return readContext$1(context);
737
- }
738
-
739
946
  var HooksDispatcher = {
740
947
  useMemo: function (nextCreate) {
741
948
  return nextCreate();
@@ -746,8 +953,8 @@ var HooksDispatcher = {
746
953
  useDebugValue: function () {},
747
954
  useDeferredValue: unsupportedHook,
748
955
  useTransition: unsupportedHook,
749
- readContext: readContext,
750
- useContext: readContext,
956
+ readContext: unsupportedContext,
957
+ useContext: unsupportedContext,
751
958
  useReducer: unsupportedHook,
752
959
  useRef: unsupportedHook,
753
960
  useState: unsupportedHook,
@@ -756,7 +963,6 @@ var HooksDispatcher = {
756
963
  useImperativeHandle: unsupportedHook,
757
964
  useEffect: unsupportedHook,
758
965
  useId: useId,
759
- useMutableSource: unsupportedHook,
760
966
  useSyncExternalStore: unsupportedHook,
761
967
  useCacheRefresh: function () {
762
968
  return unsupportedRefresh;
@@ -781,6 +987,10 @@ function unsupportedRefresh() {
781
987
  throw new Error('Refreshing the cache is not supported in Server Components.');
782
988
  }
783
989
 
990
+ function unsupportedContext() {
991
+ throw new Error('Cannot read a Client Context from a Server Component.');
992
+ }
993
+
784
994
  function useId() {
785
995
  if (currentRequest$1 === null) {
786
996
  throw new Error('useId can only be used while React is rendering');
@@ -806,20 +1016,22 @@ function use(usable) {
806
1016
  }
807
1017
 
808
1018
  return trackUsedThenable(thenableState, thenable, index);
809
- } else if (usable.$$typeof === REACT_SERVER_CONTEXT_TYPE) {
810
- var context = usable;
811
- return readContext(context);
1019
+ } else if (usable.$$typeof === REACT_CONTEXT_TYPE) {
1020
+ unsupportedContext();
812
1021
  }
813
1022
  }
814
1023
 
815
- {
816
- if (isClientReference(usable)) {
817
- error('Cannot use() an already resolved Client Reference.');
1024
+ if (isClientReference(usable)) {
1025
+ if (usable.value != null && usable.value.$$typeof === REACT_CONTEXT_TYPE) {
1026
+ // Show a more specific message since it's a common mistake.
1027
+ throw new Error('Cannot read a Client Context from a Server Component.');
1028
+ } else {
1029
+ throw new Error('Cannot use() an already resolved Client Reference.');
818
1030
  }
819
- } // eslint-disable-next-line react-internal/safe-string-coercion
820
-
821
-
822
- throw new Error('An unsupported type was passed to use(): ' + String(usable));
1031
+ } else {
1032
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
1033
+ 'An unsupported type was passed to use(): ' + String(usable));
1034
+ }
823
1035
  }
824
1036
 
825
1037
  function createSignal() {
@@ -868,6 +1080,8 @@ function isArray(a) {
868
1080
  return isArrayImpl(a);
869
1081
  }
870
1082
 
1083
+ var getPrototypeOf = Object.getPrototypeOf;
1084
+
871
1085
  // in case they error.
872
1086
 
873
1087
  var jsxPropsParents = new WeakMap();
@@ -886,7 +1100,7 @@ function isObjectPrototype(object) {
886
1100
  // still just a plain simple object.
887
1101
 
888
1102
 
889
- if (Object.getPrototypeOf(object)) {
1103
+ if (getPrototypeOf(object)) {
890
1104
  return false;
891
1105
  }
892
1106
 
@@ -902,7 +1116,7 @@ function isObjectPrototype(object) {
902
1116
  }
903
1117
 
904
1118
  function isSimpleObject(object) {
905
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1119
+ if (!isObjectPrototype(getPrototypeOf(object))) {
906
1120
  return false;
907
1121
  }
908
1122
 
@@ -955,6 +1169,10 @@ function describeValueForErrorMessage(value) {
955
1169
  return '[...]';
956
1170
  }
957
1171
 
1172
+ if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
1173
+ return describeClientReference();
1174
+ }
1175
+
958
1176
  var name = objectName(value);
959
1177
 
960
1178
  if (name === 'Object') {
@@ -965,7 +1183,15 @@ function describeValueForErrorMessage(value) {
965
1183
  }
966
1184
 
967
1185
  case 'function':
968
- return 'function';
1186
+ {
1187
+ if (value.$$typeof === CLIENT_REFERENCE_TAG) {
1188
+ return describeClientReference();
1189
+ }
1190
+
1191
+ var _name = value.displayName || value.name;
1192
+
1193
+ return _name ? 'function ' + _name : 'function';
1194
+ }
969
1195
 
970
1196
  default:
971
1197
  // eslint-disable-next-line react-internal/safe-string-coercion
@@ -1011,6 +1237,12 @@ function describeElementType(type) {
1011
1237
  return '';
1012
1238
  }
1013
1239
 
1240
+ var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
1241
+
1242
+ function describeClientReference(ref) {
1243
+ return 'client';
1244
+ }
1245
+
1014
1246
  function describeObjectForErrorMessage(objectOrArray, expandedName) {
1015
1247
  var objKind = objectName(objectOrArray);
1016
1248
 
@@ -1036,7 +1268,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1036
1268
  if (typeof value === 'string') {
1037
1269
  substr = value;
1038
1270
  } else if (typeof value === 'object' && value !== null) {
1039
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1040
1271
  substr = '{' + describeObjectForErrorMessage(value) + '}';
1041
1272
  } else {
1042
1273
  substr = '{' + describeValueForErrorMessage(value) + '}';
@@ -1069,7 +1300,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1069
1300
  var _substr = void 0;
1070
1301
 
1071
1302
  if (typeof _value === 'object' && _value !== null) {
1072
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1073
1303
  _substr = describeObjectForErrorMessage(_value);
1074
1304
  } else {
1075
1305
  _substr = describeValueForErrorMessage(_value);
@@ -1091,6 +1321,8 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1091
1321
  } else {
1092
1322
  if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1093
1323
  str = '<' + describeElementType(objectOrArray.type) + '/>';
1324
+ } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
1325
+ return describeClientReference();
1094
1326
  } else if (jsxPropsParents.has(objectOrArray)) {
1095
1327
  // Print JSX
1096
1328
  var _type = jsxPropsParents.get(objectOrArray);
@@ -1108,7 +1340,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1108
1340
  var _substr2 = void 0;
1109
1341
 
1110
1342
  if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1111
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1112
1343
  _substr2 = describeObjectForErrorMessage(_value2);
1113
1344
  } else {
1114
1345
  _substr2 = describeValueForErrorMessage(_value2);
@@ -1142,20 +1373,19 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1142
1373
  str += ', ';
1143
1374
  }
1144
1375
 
1145
- var _name = _names[_i3];
1146
- str += describeKeyForErrorMessage(_name) + ': ';
1147
- var _value3 = _object[_name];
1376
+ var _name2 = _names[_i3];
1377
+ str += describeKeyForErrorMessage(_name2) + ': ';
1378
+ var _value3 = _object[_name2];
1148
1379
 
1149
1380
  var _substr3 = void 0;
1150
1381
 
1151
1382
  if (typeof _value3 === 'object' && _value3 !== null) {
1152
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1153
1383
  _substr3 = describeObjectForErrorMessage(_value3);
1154
1384
  } else {
1155
1385
  _substr3 = describeValueForErrorMessage(_value3);
1156
1386
  }
1157
1387
 
1158
- if (_name === expandedName) {
1388
+ if (_name2 === expandedName) {
1159
1389
  start = str.length;
1160
1390
  length = _substr3.length;
1161
1391
  str += _substr3;
@@ -1182,41 +1412,44 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1182
1412
  return '\n ' + str;
1183
1413
  }
1184
1414
 
1185
- var ContextRegistry = ReactSharedInternals.ContextRegistry;
1186
- function getOrCreateServerContext(globalName) {
1187
- if (!ContextRegistry[globalName]) {
1188
- ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
1189
- REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
1190
- }
1415
+ var ReactSharedServerInternals = // $FlowFixMe: It's defined in the one we resolve to.
1416
+ React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1191
1417
 
1192
- return ContextRegistry[globalName];
1418
+ if (!ReactSharedServerInternals) {
1419
+ throw new Error('The "react" package in this environment is not configured correctly. ' + 'The "react-server" condition must be enabled in any environment that ' + 'runs React Server Components.');
1193
1420
  }
1194
1421
 
1422
+ var ObjectPrototype = Object.prototype;
1423
+ var stringify = JSON.stringify; // Serializable values
1195
1424
  // Thenable<ReactClientValue>
1196
1425
 
1197
1426
  var PENDING$1 = 0;
1198
1427
  var COMPLETED = 1;
1199
1428
  var ABORTED = 3;
1200
1429
  var ERRORED$1 = 4;
1430
+ var ReactCurrentCache = ReactSharedServerInternals.ReactCurrentCache;
1201
1431
  var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1202
- var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1203
1432
 
1204
1433
  function defaultErrorHandler(error) {
1205
1434
  console['error'](error); // Don't transform to our wrapper
1206
1435
  }
1207
1436
 
1437
+ function defaultPostponeHandler(reason) {// Noop
1438
+ }
1439
+
1208
1440
  var OPEN = 0;
1209
1441
  var CLOSING = 1;
1210
1442
  var CLOSED = 2;
1211
- function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
1443
+ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName) {
1212
1444
  if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1213
1445
  throw new Error('Currently React only supports one RSC renderer at a time.');
1214
1446
  }
1215
1447
 
1216
- prepareHostDispatcher();
1217
1448
  ReactCurrentCache.current = DefaultCacheDispatcher;
1218
1449
  var abortSet = new Set();
1219
1450
  var pingedTasks = [];
1451
+ var cleanupQueue = [];
1452
+
1220
1453
  var hints = createHints();
1221
1454
  var request = {
1222
1455
  status: OPEN,
@@ -1232,23 +1465,24 @@ function createRequest(model, bundlerConfig, onError, context, identifierPrefix)
1232
1465
  pingedTasks: pingedTasks,
1233
1466
  completedImportChunks: [],
1234
1467
  completedHintChunks: [],
1235
- completedJSONChunks: [],
1468
+ completedRegularChunks: [],
1236
1469
  completedErrorChunks: [],
1237
1470
  writtenSymbols: new Map(),
1238
1471
  writtenClientReferences: new Map(),
1239
1472
  writtenServerReferences: new Map(),
1240
- writtenProviders: new Map(),
1473
+ writtenObjects: new WeakMap(),
1241
1474
  identifierPrefix: identifierPrefix || '',
1242
1475
  identifierCount: 1,
1476
+ taintCleanupQueue: cleanupQueue,
1243
1477
  onError: onError === undefined ? defaultErrorHandler : onError,
1244
- // $FlowFixMe[missing-this-annot]
1245
- toJSON: function (key, value) {
1246
- return resolveModelToJSON(request, this, key, value);
1247
- }
1478
+ onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone
1248
1479
  };
1249
- request.pendingChunks++;
1250
- var rootContext = createRootContext(context);
1251
- var rootTask = createTask(request, model, rootContext, abortSet);
1480
+
1481
+ {
1482
+ request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1483
+ }
1484
+
1485
+ var rootTask = createTask(request, model, null, false, abortSet);
1252
1486
  pingedTasks.push(rootTask);
1253
1487
  return request;
1254
1488
  }
@@ -1259,15 +1493,18 @@ function resolveRequest() {
1259
1493
  return null;
1260
1494
  }
1261
1495
 
1262
- function createRootContext(reqContext) {
1263
- return importServerContexts(reqContext);
1264
- }
1496
+ function serializeThenable(request, task, thenable) {
1497
+ var newTask = createTask(request, null, task.keyPath, // the server component sequence continues through Promise-as-a-child.
1498
+ task.implicitSlot, request.abortableTasks);
1265
1499
 
1266
- var POP = {};
1500
+ {
1501
+ // If this came from Flight, forward any debug info into this new row.
1502
+ var debugInfo = thenable._debugInfo;
1267
1503
 
1268
- function serializeThenable(request, thenable) {
1269
- request.pendingChunks++;
1270
- var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1504
+ if (debugInfo) {
1505
+ forwardDebugInfo(request, newTask.id, debugInfo);
1506
+ }
1507
+ }
1271
1508
 
1272
1509
  switch (thenable.status) {
1273
1510
  case 'fulfilled':
@@ -1281,14 +1518,10 @@ function serializeThenable(request, thenable) {
1281
1518
  case 'rejected':
1282
1519
  {
1283
1520
  var x = thenable.reason;
1284
- var digest = logRecoverableError(request, x);
1285
1521
 
1286
1522
  {
1287
- var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1288
- message = _getErrorMessageAndSt.message,
1289
- stack = _getErrorMessageAndSt.stack;
1290
-
1291
- emitErrorChunkDev(request, newTask.id, digest, message, stack);
1523
+ var digest = logRecoverableError(request, x);
1524
+ emitErrorChunk(request, newTask.id, digest, x);
1292
1525
  }
1293
1526
 
1294
1527
  return newTask.id;
@@ -1326,18 +1559,16 @@ function serializeThenable(request, thenable) {
1326
1559
  newTask.model = value;
1327
1560
  pingTask(request, newTask);
1328
1561
  }, function (reason) {
1329
- newTask.status = ERRORED$1; // TODO: We should ideally do this inside performWork so it's scheduled
1330
-
1331
- var digest = logRecoverableError(request, reason);
1332
-
1333
1562
  {
1334
- var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1335
- _message = _getErrorMessageAndSt2.message,
1336
- _stack = _getErrorMessageAndSt2.stack;
1563
+ newTask.status = ERRORED$1;
1564
+
1565
+ var _digest = logRecoverableError(request, reason);
1337
1566
 
1338
- emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1567
+ emitErrorChunk(request, newTask.id, _digest, reason);
1339
1568
  }
1340
1569
 
1570
+ request.abortableTasks.delete(newTask);
1571
+
1341
1572
  if (request.destination !== null) {
1342
1573
  flushCompletedChunks(request, request.destination);
1343
1574
  }
@@ -1409,14 +1640,136 @@ function createLazyWrapperAroundWakeable(wakeable) {
1409
1640
  _payload: thenable,
1410
1641
  _init: readThenable
1411
1642
  };
1643
+
1644
+ {
1645
+ // If this came from React, transfer the debug info.
1646
+ lazyType._debugInfo = thenable._debugInfo || [];
1647
+ }
1648
+
1412
1649
  return lazyType;
1413
1650
  }
1414
1651
 
1415
- function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1652
+ function renderFunctionComponent(request, task, key, Component, props) {
1653
+ // Reset the task's thenable state before continuing, so that if a later
1654
+ // component suspends we can reuse the same task object. If the same
1655
+ // component suspends again, the thenable state will be restored.
1656
+ var prevThenableState = task.thenableState;
1657
+ task.thenableState = null;
1658
+
1659
+ {
1660
+ if (debugID === null) {
1661
+ // We don't have a chunk to assign debug info. We need to outline this
1662
+ // component to assign it an ID.
1663
+ return outlineTask(request, task);
1664
+ } else if (prevThenableState !== null) ; else {
1665
+ // This is a new component in the same task so we can emit more debug info.
1666
+ var componentName = Component.displayName || Component.name || '';
1667
+ request.pendingChunks++;
1668
+ emitDebugChunk(request, debugID, {
1669
+ name: componentName,
1670
+ env: request.environmentName
1671
+ });
1672
+ }
1673
+ }
1674
+
1675
+ prepareToUseHooksForComponent(prevThenableState); // The secondArg is always undefined in Server Components since refs error early.
1676
+
1677
+ var secondArg = undefined;
1678
+ var result = Component(props, secondArg);
1679
+
1680
+ if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1681
+ // When the return value is in children position we can resolve it immediately,
1682
+ // to its value without a wrapper if it's synchronously available.
1683
+ var thenable = result;
1684
+
1685
+ if (thenable.status === 'fulfilled') {
1686
+ return thenable.value;
1687
+ } // TODO: Once we accept Promises as children on the client, we can just return
1688
+ // the thenable here.
1689
+
1690
+
1691
+ result = createLazyWrapperAroundWakeable(result);
1692
+ } // Track this element's key on the Server Component on the keyPath context..
1693
+
1694
+
1695
+ var prevKeyPath = task.keyPath;
1696
+ var prevImplicitSlot = task.implicitSlot;
1697
+
1698
+ if (key !== null) {
1699
+ // Append the key to the path. Technically a null key should really add the child
1700
+ // index. We don't do that to hold the payload small and implementation simple.
1701
+ task.keyPath = prevKeyPath === null ? key : prevKeyPath + ',' + key;
1702
+ } else if (prevKeyPath === null) {
1703
+ // This sequence of Server Components has no keys. This means that it was rendered
1704
+ // in a slot that needs to assign an implicit key. Even if children below have
1705
+ // explicit keys, they should not be used for the outer most key since it might
1706
+ // collide with other slots in that set.
1707
+ task.implicitSlot = true;
1708
+ }
1709
+
1710
+ var json = renderModelDestructive(request, task, emptyRoot, '', result);
1711
+ task.keyPath = prevKeyPath;
1712
+ task.implicitSlot = prevImplicitSlot;
1713
+ return json;
1714
+ }
1715
+
1716
+ function renderFragment(request, task, children) {
1717
+ {
1718
+ var debugInfo = children._debugInfo;
1719
+
1720
+ if (debugInfo) {
1721
+ // If this came from Flight, forward any debug info into this new row.
1722
+ if (debugID === null) {
1723
+ // We don't have a chunk to assign debug info. We need to outline this
1724
+ // component to assign it an ID.
1725
+ return outlineTask(request, task);
1726
+ } else {
1727
+ // Forward any debug info we have the first time we see it.
1728
+ // We do this after init so that we have received all the debug info
1729
+ // from the server by the time we emit it.
1730
+ forwardDebugInfo(request, debugID, debugInfo);
1731
+ }
1732
+ }
1733
+ }
1734
+
1735
+ {
1736
+ return children;
1737
+ }
1738
+ }
1739
+
1740
+ function renderClientElement(task, type, key, props) {
1741
+ {
1742
+ return [REACT_ELEMENT_TYPE, type, key, props];
1743
+ } // We prepend the terminal client element that actually gets serialized with
1744
+ } // The chunk ID we're currently rendering that we can assign debug data to.
1745
+
1746
+
1747
+ var debugID = null;
1748
+
1749
+ function outlineTask(request, task) {
1750
+ var newTask = createTask(request, task.model, // the currently rendering element
1751
+ task.keyPath, // unlike outlineModel this one carries along context
1752
+ task.implicitSlot, request.abortableTasks);
1753
+ retryTask(request, newTask);
1754
+
1755
+ if (newTask.status === COMPLETED) {
1756
+ // We completed synchronously so we can refer to this by reference. This
1757
+ // makes it behaves the same as prod during deserialization.
1758
+ return serializeByValueID(newTask.id);
1759
+ } // This didn't complete synchronously so it wouldn't have even if we didn't
1760
+ // outline it, so this would reduce to a lazy reference even in prod.
1761
+
1762
+
1763
+ return serializeLazyID(newTask.id);
1764
+ }
1765
+
1766
+ function renderElement(request, task, type, key, ref, props) {
1416
1767
  if (ref !== null && ref !== undefined) {
1417
1768
  // When the ref moves to the regular props object this will implicitly
1418
1769
  // throw for functions. We could probably relax it to a DEV warning for other
1419
1770
  // cases.
1771
+ // TODO: `ref` is now just a prop when `enableRefAsProp` is on. Should we
1772
+ // do what the above comment says?
1420
1773
  throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1421
1774
  }
1422
1775
 
@@ -1429,49 +1782,38 @@ function attemptResolveElement(request, type, key, ref, props, prevThenableState
1429
1782
  }
1430
1783
 
1431
1784
  if (typeof type === 'function') {
1432
- if (isClientReference(type)) {
1785
+ if (isClientReference(type) || isTemporaryReference(type)) {
1433
1786
  // This is a reference to a Client Component.
1434
- return [REACT_ELEMENT_TYPE, type, key, props];
1435
- } // This is a server-side component.
1436
-
1437
-
1438
- prepareToUseHooksForComponent(prevThenableState);
1439
- var result = type(props);
1440
-
1441
- if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1442
- // When the return value is in children position we can resolve it immediately,
1443
- // to its value without a wrapper if it's synchronously available.
1444
- var thenable = result;
1787
+ return renderClientElement(task, type, key, props);
1788
+ } // This is a Server Component.
1445
1789
 
1446
- if (thenable.status === 'fulfilled') {
1447
- return thenable.value;
1448
- } // TODO: Once we accept Promises as children on the client, we can just return
1449
- // the thenable here.
1450
1790
 
1451
-
1452
- return createLazyWrapperAroundWakeable(result);
1453
- }
1454
-
1455
- return result;
1791
+ return renderFunctionComponent(request, task, key, type, props);
1456
1792
  } else if (typeof type === 'string') {
1457
1793
  // This is a host element. E.g. HTML.
1458
- return [REACT_ELEMENT_TYPE, type, key, props];
1794
+ return renderClientElement(task, type, key, props);
1459
1795
  } else if (typeof type === 'symbol') {
1460
- if (type === REACT_FRAGMENT_TYPE) {
1796
+ if (type === REACT_FRAGMENT_TYPE && key === null) {
1461
1797
  // For key-less fragments, we add a small optimization to avoid serializing
1462
1798
  // it as a wrapper.
1463
- // TODO: If a key is specified, we should propagate its key to any children.
1464
- // Same as if a Server Component has a key.
1465
- return props.children;
1799
+ var prevImplicitSlot = task.implicitSlot;
1800
+
1801
+ if (task.keyPath === null) {
1802
+ task.implicitSlot = true;
1803
+ }
1804
+
1805
+ var json = renderModelDestructive(request, task, emptyRoot, '', props.children);
1806
+ task.implicitSlot = prevImplicitSlot;
1807
+ return json;
1466
1808
  } // This might be a built-in React component. We'll let the client decide.
1467
1809
  // Any built-in works as long as its props are serializable.
1468
1810
 
1469
1811
 
1470
- return [REACT_ELEMENT_TYPE, type, key, props];
1812
+ return renderClientElement(task, type, key, props);
1471
1813
  } else if (type != null && typeof type === 'object') {
1472
1814
  if (isClientReference(type)) {
1473
1815
  // This is a reference to a Client Component.
1474
- return [REACT_ELEMENT_TYPE, type, key, props];
1816
+ return renderClientElement(task, type, key, props);
1475
1817
  }
1476
1818
 
1477
1819
  switch (type.$$typeof) {
@@ -1480,45 +1822,17 @@ function attemptResolveElement(request, type, key, ref, props, prevThenableState
1480
1822
  var payload = type._payload;
1481
1823
  var init = type._init;
1482
1824
  var wrappedType = init(payload);
1483
- return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1825
+ return renderElement(request, task, wrappedType, key, ref, props);
1484
1826
  }
1485
1827
 
1486
1828
  case REACT_FORWARD_REF_TYPE:
1487
1829
  {
1488
- var render = type.render;
1489
- prepareToUseHooksForComponent(prevThenableState);
1490
- return render(props, undefined);
1830
+ return renderFunctionComponent(request, task, key, type.render, props);
1491
1831
  }
1492
1832
 
1493
1833
  case REACT_MEMO_TYPE:
1494
1834
  {
1495
- return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1496
- }
1497
-
1498
- case REACT_PROVIDER_TYPE:
1499
- {
1500
- pushProvider(type._context, props.value);
1501
-
1502
- {
1503
- var extraKeys = Object.keys(props).filter(function (value) {
1504
- if (value === 'children' || value === 'value') {
1505
- return false;
1506
- }
1507
-
1508
- return true;
1509
- });
1510
-
1511
- if (extraKeys.length !== 0) {
1512
- error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1513
- }
1514
- }
1515
-
1516
- return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
1517
- {
1518
- value: props.value,
1519
- children: props.children,
1520
- __pop: POP
1521
- }];
1835
+ return renderElement(request, task, type.type, key, ref, props);
1522
1836
  }
1523
1837
  }
1524
1838
  }
@@ -1538,16 +1852,51 @@ function pingTask(request, task) {
1538
1852
  }
1539
1853
  }
1540
1854
 
1541
- function createTask(request, model, context, abortSet) {
1855
+ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1856
+ request.pendingChunks++;
1542
1857
  var id = request.nextChunkId++;
1858
+
1859
+ if (typeof model === 'object' && model !== null) {
1860
+ // If we're about to write this into a new task we can assign it an ID early so that
1861
+ // any other references can refer to the value we're about to write.
1862
+ {
1863
+ request.writtenObjects.set(model, id);
1864
+ }
1865
+ }
1866
+
1543
1867
  var task = {
1544
1868
  id: id,
1545
1869
  status: PENDING$1,
1546
1870
  model: model,
1547
- context: context,
1871
+ keyPath: keyPath,
1872
+ implicitSlot: implicitSlot,
1548
1873
  ping: function () {
1549
1874
  return pingTask(request, task);
1550
1875
  },
1876
+ toJSON: function (parentPropertyName, value) {
1877
+ var parent = this; // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
1878
+
1879
+ {
1880
+ // $FlowFixMe[incompatible-use]
1881
+ var originalValue = parent[parentPropertyName];
1882
+
1883
+ if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1884
+ if (objectName(originalValue) !== 'Object') {
1885
+ var jsxParentType = jsxChildrenParents.get(parent);
1886
+
1887
+ if (typeof jsxParentType === 'string') {
1888
+ error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, parentPropertyName));
1889
+ } else {
1890
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, parentPropertyName));
1891
+ }
1892
+ } else {
1893
+ error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, parentPropertyName));
1894
+ }
1895
+ }
1896
+ }
1897
+
1898
+ return renderModel(request, task, parent, parentPropertyName, value);
1899
+ },
1551
1900
  thenableState: null
1552
1901
  };
1553
1902
  abortSet.add(task);
@@ -1570,12 +1919,12 @@ function serializeServerReferenceID(id) {
1570
1919
  return '$F' + id.toString(16);
1571
1920
  }
1572
1921
 
1573
- function serializeSymbolReference(name) {
1574
- return '$S' + name;
1922
+ function serializeTemporaryReferenceID(id) {
1923
+ return '$T' + id;
1575
1924
  }
1576
1925
 
1577
- function serializeProviderReference(name) {
1578
- return '$P' + name;
1926
+ function serializeSymbolReference(name) {
1927
+ return '$S' + name;
1579
1928
  }
1580
1929
 
1581
1930
  function serializeNumber(number) {
@@ -1610,13 +1959,23 @@ function serializeBigInt(n) {
1610
1959
  return '$n' + n.toString(10);
1611
1960
  }
1612
1961
 
1613
- function serializeClientReference(request, parent, key, clientReference) {
1962
+ function serializeRowHeader(tag, id) {
1963
+ return id.toString(16) + ':' + tag;
1964
+ }
1965
+
1966
+ function encodeReferenceChunk(request, id, reference) {
1967
+ var json = stringify(reference);
1968
+ var row = id.toString(16) + ':' + json + '\n';
1969
+ return stringToChunk(row);
1970
+ }
1971
+
1972
+ function serializeClientReference(request, parent, parentPropertyName, clientReference) {
1614
1973
  var clientReferenceKey = getClientReferenceKey(clientReference);
1615
1974
  var writtenClientReferences = request.writtenClientReferences;
1616
1975
  var existingId = writtenClientReferences.get(clientReferenceKey);
1617
1976
 
1618
1977
  if (existingId !== undefined) {
1619
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1978
+ if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1620
1979
  // If we're encoding the "type" of an element, we can refer
1621
1980
  // to that by a lazy reference instead of directly since React
1622
1981
  // knows how to deal with lazy values. This lets us suspend
@@ -1635,7 +1994,7 @@ function serializeClientReference(request, parent, key, clientReference) {
1635
1994
  emitImportChunk(request, importId, clientReferenceMetadata);
1636
1995
  writtenClientReferences.set(clientReferenceKey, importId);
1637
1996
 
1638
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1997
+ if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1639
1998
  // If we're encoding the "type" of an element, we can refer
1640
1999
  // to that by a lazy reference instead of directly since React
1641
2000
  // knows how to deal with lazy values. This lets us suspend
@@ -1649,20 +2008,20 @@ function serializeClientReference(request, parent, key, clientReference) {
1649
2008
  request.pendingChunks++;
1650
2009
  var errorId = request.nextChunkId++;
1651
2010
  var digest = logRecoverableError(request, x);
1652
-
1653
- {
1654
- var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1655
- message = _getErrorMessageAndSt3.message,
1656
- stack = _getErrorMessageAndSt3.stack;
1657
-
1658
- emitErrorChunkDev(request, errorId, digest, message, stack);
1659
- }
1660
-
2011
+ emitErrorChunk(request, errorId, digest, x);
1661
2012
  return serializeByValueID(errorId);
1662
2013
  }
1663
2014
  }
1664
2015
 
1665
- function serializeServerReference(request, parent, key, serverReference) {
2016
+ function outlineModel(request, value) {
2017
+ var newTask = createTask(request, value, null, // The way we use outlining is for reusing an object.
2018
+ false, // It makes no sense for that use case to be contextual.
2019
+ request.abortableTasks);
2020
+ retryTask(request, newTask);
2021
+ return newTask.id;
2022
+ }
2023
+
2024
+ function serializeServerReference(request, serverReference) {
1666
2025
  var writtenServerReferences = request.writtenServerReferences;
1667
2026
  var existingId = writtenServerReferences.get(serverReference);
1668
2027
 
@@ -1675,15 +2034,69 @@ function serializeServerReference(request, parent, key, serverReference) {
1675
2034
  id: getServerReferenceId(request.bundlerConfig, serverReference),
1676
2035
  bound: bound ? Promise.resolve(bound) : null
1677
2036
  };
1678
- request.pendingChunks++;
1679
- var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1680
-
1681
- var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1682
- request.completedJSONChunks.push(processedChunk);
2037
+ var metadataId = outlineModel(request, serverReferenceMetadata);
1683
2038
  writtenServerReferences.set(serverReference, metadataId);
1684
2039
  return serializeServerReferenceID(metadataId);
1685
2040
  }
1686
2041
 
2042
+ function serializeTemporaryReference(request, temporaryReference) {
2043
+ var id = resolveTemporaryReferenceID(temporaryReference);
2044
+ return serializeTemporaryReferenceID(id);
2045
+ }
2046
+
2047
+ function serializeLargeTextString(request, text) {
2048
+ request.pendingChunks += 2;
2049
+ var textId = request.nextChunkId++;
2050
+ var textChunk = stringToChunk(text);
2051
+ var binaryLength = byteLengthOfChunk(textChunk);
2052
+ var row = textId.toString(16) + ':T' + binaryLength.toString(16) + ',';
2053
+ var headerChunk = stringToChunk(row);
2054
+ request.completedRegularChunks.push(headerChunk, textChunk);
2055
+ return serializeByValueID(textId);
2056
+ }
2057
+
2058
+ function serializeMap(request, map) {
2059
+ var entries = Array.from(map);
2060
+
2061
+ for (var i = 0; i < entries.length; i++) {
2062
+ var key = entries[i][0];
2063
+
2064
+ if (typeof key === 'object' && key !== null) {
2065
+ var writtenObjects = request.writtenObjects;
2066
+ var existingId = writtenObjects.get(key);
2067
+
2068
+ if (existingId === undefined) {
2069
+ // Mark all object keys as seen so that they're always outlined.
2070
+ writtenObjects.set(key, -1);
2071
+ }
2072
+ }
2073
+ }
2074
+
2075
+ var id = outlineModel(request, entries);
2076
+ return '$Q' + id.toString(16);
2077
+ }
2078
+
2079
+ function serializeSet(request, set) {
2080
+ var entries = Array.from(set);
2081
+
2082
+ for (var i = 0; i < entries.length; i++) {
2083
+ var key = entries[i];
2084
+
2085
+ if (typeof key === 'object' && key !== null) {
2086
+ var writtenObjects = request.writtenObjects;
2087
+ var existingId = writtenObjects.get(key);
2088
+
2089
+ if (existingId === undefined) {
2090
+ // Mark all object keys as seen so that they're always outlined.
2091
+ writtenObjects.set(key, -1);
2092
+ }
2093
+ }
2094
+ }
2095
+
2096
+ var id = outlineModel(request, entries);
2097
+ return '$W' + id.toString(16);
2098
+ }
2099
+
1687
2100
  function escapeStringValue(value) {
1688
2101
  if (value[0] === '$') {
1689
2102
  // We need to escape $ prefixed strings since we use those to encode
@@ -1694,166 +2107,262 @@ function escapeStringValue(value) {
1694
2107
  }
1695
2108
  }
1696
2109
 
1697
- var insideContextProps = null;
1698
- var isInsideContextValue = false;
1699
- function resolveModelToJSON(request, parent, key, value) {
1700
- // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
1701
- {
1702
- // $FlowFixMe[incompatible-use]
1703
- var originalValue = parent[key];
2110
+ var modelRoot = false;
1704
2111
 
1705
- if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1706
- if (objectName(originalValue) !== 'Object') {
1707
- var jsxParentType = jsxChildrenParents.get(parent);
2112
+ function renderModel(request, task, parent, key, value) {
2113
+ var prevKeyPath = task.keyPath;
2114
+ var prevImplicitSlot = task.implicitSlot;
1708
2115
 
1709
- if (typeof jsxParentType === 'string') {
1710
- error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
1711
- } else {
1712
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
2116
+ try {
2117
+ return renderModelDestructive(request, task, parent, key, value);
2118
+ } catch (thrownValue) {
2119
+ var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2120
+ // reasons, the rest of the Suspense implementation expects the thrown
2121
+ // value to be a thenable, because before `use` existed that was the
2122
+ // (unstable) API for suspending. This implementation detail can change
2123
+ // later, once we deprecate the old API in favor of `use`.
2124
+ getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
2125
+ // to a lazy reference, so that it doesn't error the parent.
2126
+
2127
+ var model = task.model;
2128
+ var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2129
+
2130
+ if (typeof x === 'object' && x !== null) {
2131
+ // $FlowFixMe[method-unbinding]
2132
+ if (typeof x.then === 'function') {
2133
+ // Something suspended, we'll need to create a new task and resolve it later.
2134
+ var newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
2135
+ var ping = newTask.ping;
2136
+ x.then(ping, ping);
2137
+ newTask.thenableState = getThenableStateAfterSuspending(); // Restore the context. We assume that this will be restored by the inner
2138
+ // functions in case nothing throws so we don't use "finally" here.
2139
+
2140
+ task.keyPath = prevKeyPath;
2141
+ task.implicitSlot = prevImplicitSlot;
2142
+
2143
+ if (wasReactNode) {
2144
+ return serializeLazyID(newTask.id);
1713
2145
  }
1714
- } else {
1715
- error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
2146
+
2147
+ return serializeByValueID(newTask.id);
1716
2148
  }
1717
- }
1718
- } // Special Symbols
2149
+ } // Restore the context. We assume that this will be restored by the inner
2150
+ // functions in case nothing throws so we don't use "finally" here.
1719
2151
 
1720
2152
 
1721
- switch (value) {
1722
- case REACT_ELEMENT_TYPE:
1723
- return '$';
1724
- }
2153
+ task.keyPath = prevKeyPath;
2154
+ task.implicitSlot = prevImplicitSlot;
1725
2155
 
1726
- {
1727
- if (parent[0] === REACT_ELEMENT_TYPE && parent[1] && parent[1].$$typeof === REACT_PROVIDER_TYPE && key === '3') {
1728
- insideContextProps = value;
1729
- } else if (insideContextProps === parent && key === 'value') {
1730
- isInsideContextValue = true;
1731
- } else if (insideContextProps === parent && key === 'children') {
1732
- isInsideContextValue = false;
1733
- }
1734
- } // Resolve Server Components.
2156
+ if (wasReactNode) {
2157
+ // Something errored. We'll still send everything we have up until this point.
2158
+ // We'll replace this element with a lazy reference that throws on the client
2159
+ // once it gets rendered.
2160
+ request.pendingChunks++;
2161
+ var errorId = request.nextChunkId++;
2162
+ var digest = logRecoverableError(request, x);
2163
+ emitErrorChunk(request, errorId, digest, x);
2164
+ return serializeLazyID(errorId);
2165
+ } // Something errored but it was not in a React Node. There's no need to serialize
2166
+ // it by value because it'll just error the whole parent row anyway so we can
2167
+ // just stop any siblings and error the whole parent row.
1735
2168
 
1736
2169
 
1737
- while (typeof value === 'object' && value !== null && (value.$$typeof === REACT_ELEMENT_TYPE || value.$$typeof === REACT_LAZY_TYPE)) {
1738
- {
1739
- if (isInsideContextValue) {
1740
- error('React elements are not allowed in ServerContext');
1741
- }
1742
- }
2170
+ throw x;
2171
+ }
2172
+ }
1743
2173
 
1744
- try {
1745
- switch (value.$$typeof) {
1746
- case REACT_ELEMENT_TYPE:
1747
- {
1748
- // TODO: Concatenate keys of parents onto children.
1749
- var element = value; // Attempt to render the Server Component.
2174
+ function renderModelDestructive(request, task, parent, parentPropertyName, value) {
2175
+ // Set the currently rendering model
2176
+ task.model = value; // Special Symbol, that's very common.
2177
+
2178
+ if (value === REACT_ELEMENT_TYPE) {
2179
+ return '$';
2180
+ }
2181
+
2182
+ if (value === null) {
2183
+ return null;
2184
+ }
1750
2185
 
1751
- value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, null);
1752
- break;
2186
+ if (typeof value === 'object') {
2187
+ switch (value.$$typeof) {
2188
+ case REACT_ELEMENT_TYPE:
2189
+ {
2190
+ var _writtenObjects = request.writtenObjects;
2191
+
2192
+ var _existingId = _writtenObjects.get(value);
2193
+
2194
+ if (_existingId !== undefined) {
2195
+ if (modelRoot === value) {
2196
+ // This is the ID we're currently emitting so we need to write it
2197
+ // once but if we discover it again, we refer to it by id.
2198
+ modelRoot = null;
2199
+ } else if (_existingId === -1) {
2200
+ // Seen but not yet outlined.
2201
+ // TODO: If we throw here we can treat this as suspending which causes an outline
2202
+ // but that is able to reuse the same task if we're already in one but then that
2203
+ // will be a lazy future value rather than guaranteed to exist but maybe that's good.
2204
+ var newId = outlineModel(request, value);
2205
+ return serializeByValueID(newId);
2206
+ } else {
2207
+ // We've already emitted this as an outlined object, so we can refer to that by its
2208
+ // existing ID. TODO: We should use a lazy reference since, unlike plain objects,
2209
+ // elements might suspend so it might not have emitted yet even if we have the ID for
2210
+ // it. However, this creates an extra wrapper when it's not needed. We should really
2211
+ // detect whether this already was emitted and synchronously available. In that
2212
+ // case we can refer to it synchronously and only make it lazy otherwise.
2213
+ // We currently don't have a data structure that lets us see that though.
2214
+ return serializeByValueID(_existingId);
2215
+ }
2216
+ } else {
2217
+ // This is the first time we've seen this object. We may never see it again
2218
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2219
+ _writtenObjects.set(value, -1);
1753
2220
  }
1754
2221
 
1755
- case REACT_LAZY_TYPE:
2222
+ var element = value;
2223
+
1756
2224
  {
1757
- var payload = value._payload;
1758
- var init = value._init;
1759
- value = init(payload);
1760
- break;
2225
+ var debugInfo = value._debugInfo;
2226
+
2227
+ if (debugInfo) {
2228
+ // If this came from Flight, forward any debug info into this new row.
2229
+ if (debugID === null) {
2230
+ // We don't have a chunk to assign debug info. We need to outline this
2231
+ // component to assign it an ID.
2232
+ return outlineTask(request, task);
2233
+ } else {
2234
+ // Forward any debug info we have the first time we see it.
2235
+ forwardDebugInfo(request, debugID, debugInfo);
2236
+ }
2237
+ }
1761
2238
  }
1762
- }
1763
- } catch (thrownValue) {
1764
- var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
1765
- // reasons, the rest of the Suspense implementation expects the thrown
1766
- // value to be a thenable, because before `use` existed that was the
1767
- // (unstable) API for suspending. This implementation detail can change
1768
- // later, once we deprecate the old API in favor of `use`.
1769
- getSuspendedThenable() : thrownValue; // $FlowFixMe[method-unbinding]
1770
-
1771
- if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
1772
- // Something suspended, we'll need to create a new task and resolve it later.
1773
- request.pendingChunks++;
1774
- var newTask = createTask(request, value, getActiveContext(), request.abortableTasks);
1775
- var ping = newTask.ping;
1776
- x.then(ping, ping);
1777
- newTask.thenableState = getThenableStateAfterSuspending();
1778
- return serializeLazyID(newTask.id);
1779
- } else {
1780
- // Something errored. We'll still send everything we have up until this point.
1781
- // We'll replace this element with a lazy reference that throws on the client
1782
- // once it gets rendered.
1783
- request.pendingChunks++;
1784
- var errorId = request.nextChunkId++;
1785
- var digest = logRecoverableError(request, x);
1786
2239
 
2240
+ var props = element.props;
2241
+ var ref;
2242
+
2243
+ {
2244
+ ref = element.ref;
2245
+ } // Attempt to render the Server Component.
2246
+
2247
+
2248
+ return renderElement(request, task, element.type, // $FlowFixMe[incompatible-call] the key of an element is null | string
2249
+ element.key, ref, props);
2250
+ }
2251
+
2252
+ case REACT_LAZY_TYPE:
1787
2253
  {
1788
- var _getErrorMessageAndSt4 = getErrorMessageAndStackDev(x),
1789
- message = _getErrorMessageAndSt4.message,
1790
- stack = _getErrorMessageAndSt4.stack;
2254
+ // Reset the task's thenable state before continuing. If there was one, it was
2255
+ // from suspending the lazy before.
2256
+ task.thenableState = null;
2257
+ var lazy = value;
2258
+ var payload = lazy._payload;
2259
+ var init = lazy._init;
2260
+ var resolvedModel = init(payload);
2261
+
2262
+ {
2263
+ var _debugInfo = lazy._debugInfo;
2264
+
2265
+ if (_debugInfo) {
2266
+ // If this came from Flight, forward any debug info into this new row.
2267
+ if (debugID === null) {
2268
+ // We don't have a chunk to assign debug info. We need to outline this
2269
+ // component to assign it an ID.
2270
+ return outlineTask(request, task);
2271
+ } else {
2272
+ // Forward any debug info we have the first time we see it.
2273
+ // We do this after init so that we have received all the debug info
2274
+ // from the server by the time we emit it.
2275
+ forwardDebugInfo(request, debugID, _debugInfo);
2276
+ }
2277
+ }
2278
+ }
1791
2279
 
1792
- emitErrorChunkDev(request, errorId, digest, message, stack);
2280
+ return renderModelDestructive(request, task, emptyRoot, '', resolvedModel);
1793
2281
  }
2282
+ }
1794
2283
 
1795
- return serializeLazyID(errorId);
1796
- }
2284
+ if (isClientReference(value)) {
2285
+ return serializeClientReference(request, parent, parentPropertyName, value);
1797
2286
  }
1798
- }
1799
2287
 
1800
- if (value === null) {
1801
- return null;
1802
- }
2288
+ var writtenObjects = request.writtenObjects;
2289
+ var existingId = writtenObjects.get(value); // $FlowFixMe[method-unbinding]
1803
2290
 
1804
- if (typeof value === 'object') {
1805
- if (isClientReference(value)) {
1806
- return serializeClientReference(request, parent, key, value); // $FlowFixMe[method-unbinding]
1807
- } else if (typeof value.then === 'function') {
1808
- // We assume that any object with a .then property is a "Thenable" type,
2291
+ if (typeof value.then === 'function') {
2292
+ if (existingId !== undefined) {
2293
+ if (modelRoot === value) {
2294
+ // This is the ID we're currently emitting so we need to write it
2295
+ // once but if we discover it again, we refer to it by id.
2296
+ modelRoot = null;
2297
+ } else {
2298
+ // We've seen this promise before, so we can just refer to the same result.
2299
+ return serializePromiseID(existingId);
2300
+ }
2301
+ } // We assume that any object with a .then property is a "Thenable" type,
1809
2302
  // or a Promise type. Either of which can be represented by a Promise.
1810
- var promiseId = serializeThenable(request, value);
2303
+
2304
+
2305
+ var promiseId = serializeThenable(request, task, value);
2306
+ writtenObjects.set(value, promiseId);
1811
2307
  return serializePromiseID(promiseId);
1812
- } else if (value.$$typeof === REACT_PROVIDER_TYPE) {
1813
- var providerKey = value._context._globalName;
1814
- var writtenProviders = request.writtenProviders;
1815
- var providerId = writtenProviders.get(key);
1816
-
1817
- if (providerId === undefined) {
1818
- request.pendingChunks++;
1819
- providerId = request.nextChunkId++;
1820
- writtenProviders.set(providerKey, providerId);
1821
- emitProviderChunk(request, providerId, providerKey);
2308
+ }
2309
+
2310
+ if (existingId !== undefined) {
2311
+ if (modelRoot === value) {
2312
+ // This is the ID we're currently emitting so we need to write it
2313
+ // once but if we discover it again, we refer to it by id.
2314
+ modelRoot = null;
2315
+ } else if (existingId === -1) {
2316
+ // Seen but not yet outlined.
2317
+ var _newId = outlineModel(request, value);
2318
+
2319
+ return serializeByValueID(_newId);
2320
+ } else {
2321
+ // We've already emitted this as an outlined object, so we can
2322
+ // just refer to that by its existing ID.
2323
+ return serializeByValueID(existingId);
1822
2324
  }
2325
+ } else {
2326
+ // This is the first time we've seen this object. We may never see it again
2327
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2328
+ writtenObjects.set(value, -1);
2329
+ }
1823
2330
 
1824
- return serializeByValueID(providerId);
1825
- } else if (value === POP) {
1826
- popProvider();
2331
+ if (isArray(value)) {
2332
+ return renderFragment(request, task, value);
2333
+ }
1827
2334
 
1828
- {
1829
- insideContextProps = null;
1830
- isInsideContextValue = false;
1831
- }
2335
+ if (value instanceof Map) {
2336
+ return serializeMap(request, value);
2337
+ }
1832
2338
 
1833
- return undefined;
2339
+ if (value instanceof Set) {
2340
+ return serializeSet(request, value);
1834
2341
  }
1835
2342
 
1836
- if (!isArray(value)) {
1837
- var iteratorFn = getIteratorFn(value);
2343
+ var iteratorFn = getIteratorFn(value);
1838
2344
 
1839
- if (iteratorFn) {
1840
- return Array.from(value);
1841
- }
2345
+ if (iteratorFn) {
2346
+ return renderFragment(request, task, Array.from(value));
2347
+ } // Verify that this is a simple plain object.
2348
+
2349
+
2350
+ var proto = getPrototypeOf(value);
2351
+
2352
+ if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
2353
+ throw new Error('Only plain objects, and a few built-ins, can be passed to Client Components ' + 'from Server Components. Classes or null prototypes are not supported.');
1842
2354
  }
1843
2355
 
1844
2356
  {
1845
- if (value !== null && !isArray(value)) {
1846
- // Verify that this is a simple plain object.
1847
- if (objectName(value) !== 'Object') {
1848
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
1849
- } else if (!isSimpleObject(value)) {
1850
- 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));
1851
- } else if (Object.getOwnPropertySymbols) {
1852
- var symbols = Object.getOwnPropertySymbols(value);
1853
-
1854
- if (symbols.length > 0) {
1855
- 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));
1856
- }
2357
+ if (objectName(value) !== 'Object') {
2358
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, parentPropertyName));
2359
+ } else if (!isSimpleObject(value)) {
2360
+ 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, parentPropertyName));
2361
+ } else if (Object.getOwnPropertySymbols) {
2362
+ var symbols = Object.getOwnPropertySymbols(value);
2363
+
2364
+ if (symbols.length > 0) {
2365
+ 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, parentPropertyName));
1857
2366
  }
1858
2367
  }
1859
2368
  } // $FlowFixMe[incompatible-return]
@@ -1863,17 +2372,25 @@ function resolveModelToJSON(request, parent, key, value) {
1863
2372
  }
1864
2373
 
1865
2374
  if (typeof value === 'string') {
1866
- // TODO: Maybe too clever. If we support URL there's no similar trick.
2375
+
2376
+
1867
2377
  if (value[value.length - 1] === 'Z') {
1868
2378
  // Possibly a Date, whose toJSON automatically calls toISOString
1869
2379
  // $FlowFixMe[incompatible-use]
1870
- var _originalValue = parent[key]; // $FlowFixMe[method-unbinding]
2380
+ var originalValue = parent[parentPropertyName];
1871
2381
 
1872
- if (_originalValue instanceof Date) {
2382
+ if (originalValue instanceof Date) {
1873
2383
  return serializeDateFromDateJSON(value);
1874
2384
  }
1875
2385
  }
1876
2386
 
2387
+ if (value.length >= 1024) {
2388
+ // For large strings, we encode them outside the JSON payload so that we
2389
+ // don't have to double encode and double parse the strings. This can also
2390
+ // be more compact in case the string has a lot of escaped characters.
2391
+ return serializeLargeTextString(request, value);
2392
+ }
2393
+
1877
2394
  return escapeStringValue(value);
1878
2395
  }
1879
2396
 
@@ -1891,26 +2408,34 @@ function resolveModelToJSON(request, parent, key, value) {
1891
2408
 
1892
2409
  if (typeof value === 'function') {
1893
2410
  if (isClientReference(value)) {
1894
- return serializeClientReference(request, parent, key, value);
2411
+ return serializeClientReference(request, parent, parentPropertyName, value);
1895
2412
  }
1896
2413
 
1897
2414
  if (isServerReference(value)) {
1898
- return serializeServerReference(request, parent, key, value);
2415
+ return serializeServerReference(request, value);
2416
+ }
2417
+
2418
+ if (isTemporaryReference(value)) {
2419
+ return serializeTemporaryReference(request, value);
1899
2420
  }
1900
2421
 
1901
- if (/^on[A-Z]/.test(key)) {
1902
- throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, key) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
2422
+ if (/^on[A-Z]/.test(parentPropertyName)) {
2423
+ throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, parentPropertyName) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
2424
+ } else if ((jsxChildrenParents.has(parent) || jsxPropsParents.has(parent) && parentPropertyName === 'children')) {
2425
+ var componentName = value.displayName || value.name || 'Component';
2426
+ throw new Error('Functions are not valid as a child of Client Components. This may happen if ' + 'you return ' + componentName + ' instead of <' + componentName + ' /> from render. ' + 'Or maybe you meant to call this function rather than return it.' + describeObjectForErrorMessage(parent, parentPropertyName));
1903
2427
  } else {
1904
- throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server".' + describeObjectForErrorMessage(parent, key));
2428
+ throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server". ' + 'Or maybe you meant to call this function rather than return it.' + describeObjectForErrorMessage(parent, parentPropertyName));
1905
2429
  }
1906
2430
  }
1907
2431
 
1908
2432
  if (typeof value === 'symbol') {
1909
2433
  var writtenSymbols = request.writtenSymbols;
1910
- var existingId = writtenSymbols.get(value);
1911
2434
 
1912
- if (existingId !== undefined) {
1913
- return serializeByValueID(existingId);
2435
+ var _existingId2 = writtenSymbols.get(value);
2436
+
2437
+ if (_existingId2 !== undefined) {
2438
+ return serializeByValueID(_existingId2);
1914
2439
  } // $FlowFixMe[incompatible-type] `description` might be undefined
1915
2440
 
1916
2441
 
@@ -1918,7 +2443,7 @@ function resolveModelToJSON(request, parent, key, value) {
1918
2443
 
1919
2444
  if (Symbol.for(name) !== value) {
1920
2445
  throw new Error('Only global symbols received from Symbol.for(...) can be passed to Client Components. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
1921
- value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, key));
2446
+ value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, parentPropertyName));
1922
2447
  }
1923
2448
 
1924
2449
  request.pendingChunks++;
@@ -1929,15 +2454,42 @@ function resolveModelToJSON(request, parent, key, value) {
1929
2454
  }
1930
2455
 
1931
2456
  if (typeof value === 'bigint') {
2457
+
1932
2458
  return serializeBigInt(value);
1933
2459
  }
1934
2460
 
1935
- throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, key));
2461
+ throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, parentPropertyName));
2462
+ }
2463
+
2464
+ function logPostpone(request, reason) {
2465
+ var prevRequest = currentRequest;
2466
+ currentRequest = null;
2467
+
2468
+ try {
2469
+ var onPostpone = request.onPostpone;
2470
+
2471
+ if (supportsRequestStorage) ; else {
2472
+ onPostpone(reason);
2473
+ }
2474
+ } finally {
2475
+ currentRequest = prevRequest;
2476
+ }
1936
2477
  }
1937
2478
 
1938
2479
  function logRecoverableError(request, error) {
1939
- var onError = request.onError;
1940
- var errorDigest = onError(error);
2480
+ var prevRequest = currentRequest;
2481
+ currentRequest = null;
2482
+ var errorDigest;
2483
+
2484
+ try {
2485
+ var onError = request.onError;
2486
+
2487
+ if (supportsRequestStorage) ; else {
2488
+ errorDigest = onError(error);
2489
+ }
2490
+ } finally {
2491
+ currentRequest = prevRequest;
2492
+ }
1941
2493
 
1942
2494
  if (errorDigest != null && typeof errorDigest !== 'string') {
1943
2495
  // eslint-disable-next-line react-internal/prod-error-codes
@@ -1947,7 +2499,45 @@ function logRecoverableError(request, error) {
1947
2499
  return errorDigest || '';
1948
2500
  }
1949
2501
 
1950
- function getErrorMessageAndStackDev(error) {
2502
+ function fatalError(request, error) {
2503
+
2504
+
2505
+ if (request.destination !== null) {
2506
+ request.status = CLOSED;
2507
+ closeWithError(request.destination, error);
2508
+ } else {
2509
+ request.status = CLOSING;
2510
+ request.fatalError = error;
2511
+ }
2512
+ }
2513
+
2514
+ function emitPostponeChunk(request, id, postponeInstance) {
2515
+ var row;
2516
+
2517
+ {
2518
+ var reason = '';
2519
+ var stack = '';
2520
+
2521
+ try {
2522
+ // eslint-disable-next-line react-internal/safe-string-coercion
2523
+ reason = String(postponeInstance.message); // eslint-disable-next-line react-internal/safe-string-coercion
2524
+
2525
+ stack = String(postponeInstance.stack);
2526
+ } catch (x) {}
2527
+
2528
+ row = serializeRowHeader('P', id) + stringify({
2529
+ reason: reason,
2530
+ stack: stack
2531
+ }) + '\n';
2532
+ }
2533
+
2534
+ var processedChunk = stringToChunk(row);
2535
+ request.completedErrorChunks.push(processedChunk);
2536
+ }
2537
+
2538
+ function emitErrorChunk(request, id, digest, error) {
2539
+ var errorInfo;
2540
+
1951
2541
  {
1952
2542
  var message;
1953
2543
  var stack = '';
@@ -1958,101 +2548,123 @@ function getErrorMessageAndStackDev(error) {
1958
2548
  message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
1959
2549
 
1960
2550
  stack = String(error.stack);
2551
+ } else if (typeof error === 'object' && error !== null) {
2552
+ message = describeObjectForErrorMessage(error);
1961
2553
  } else {
1962
- message = 'Error: ' + error;
2554
+ // eslint-disable-next-line react-internal/safe-string-coercion
2555
+ message = String(error);
1963
2556
  }
1964
2557
  } catch (x) {
1965
2558
  message = 'An error occurred but serializing the error message failed.';
1966
2559
  }
1967
2560
 
1968
- return {
2561
+ errorInfo = {
2562
+ digest: digest,
1969
2563
  message: message,
1970
2564
  stack: stack
1971
2565
  };
1972
2566
  }
1973
- }
1974
-
1975
- function fatalError(request, error) {
1976
- // This is called outside error handling code such as if an error happens in React internals.
1977
- if (request.destination !== null) {
1978
- request.status = CLOSED;
1979
- closeWithError(request.destination, error);
1980
- } else {
1981
- request.status = CLOSING;
1982
- request.fatalError = error;
1983
- }
1984
- }
1985
-
1986
- function emitErrorChunkProd(request, id, digest) {
1987
- var processedChunk = processErrorChunkProd();
1988
- request.completedErrorChunks.push(processedChunk);
1989
- }
1990
2567
 
1991
- function emitErrorChunkDev(request, id, digest, message, stack) {
1992
- var processedChunk = processErrorChunkDev(request, id, digest, message, stack);
2568
+ var row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
2569
+ var processedChunk = stringToChunk(row);
1993
2570
  request.completedErrorChunks.push(processedChunk);
1994
2571
  }
1995
2572
 
1996
2573
  function emitImportChunk(request, id, clientReferenceMetadata) {
1997
- var processedChunk = processImportChunk(request, id, clientReferenceMetadata);
2574
+ // $FlowFixMe[incompatible-type] stringify can return null
2575
+ var json = stringify(clientReferenceMetadata);
2576
+ var row = serializeRowHeader('I', id) + json + '\n';
2577
+ var processedChunk = stringToChunk(row);
1998
2578
  request.completedImportChunks.push(processedChunk);
1999
2579
  }
2000
2580
 
2001
2581
  function emitHintChunk(request, code, model) {
2002
- var processedChunk = processHintChunk(request, request.nextChunkId++, code, model);
2582
+ var json = stringify(model);
2583
+ var id = request.nextChunkId++;
2584
+ var row = serializeRowHeader('H' + code, id) + json + '\n';
2585
+ var processedChunk = stringToChunk(row);
2003
2586
  request.completedHintChunks.push(processedChunk);
2004
2587
  }
2005
2588
 
2006
2589
  function emitSymbolChunk(request, id, name) {
2007
2590
  var symbolReference = serializeSymbolReference(name);
2008
- var processedChunk = processReferenceChunk(request, id, symbolReference);
2591
+ var processedChunk = encodeReferenceChunk(request, id, symbolReference);
2009
2592
  request.completedImportChunks.push(processedChunk);
2010
2593
  }
2011
2594
 
2012
- function emitProviderChunk(request, id, contextName) {
2013
- var contextReference = serializeProviderReference(contextName);
2014
- var processedChunk = processReferenceChunk(request, id, contextReference);
2015
- request.completedJSONChunks.push(processedChunk);
2595
+ function emitModelChunk(request, id, json) {
2596
+ var row = id.toString(16) + ':' + json + '\n';
2597
+ var processedChunk = stringToChunk(row);
2598
+ request.completedRegularChunks.push(processedChunk);
2599
+ }
2600
+
2601
+ function emitDebugChunk(request, id, debugInfo) {
2602
+
2603
+
2604
+ var json = stringify(debugInfo);
2605
+ var row = serializeRowHeader('D', id) + json + '\n';
2606
+ var processedChunk = stringToChunk(row);
2607
+ request.completedRegularChunks.push(processedChunk);
2608
+ }
2609
+
2610
+ function forwardDebugInfo(request, id, debugInfo) {
2611
+ for (var i = 0; i < debugInfo.length; i++) {
2612
+ request.pendingChunks++;
2613
+ emitDebugChunk(request, id, debugInfo[i]);
2614
+ }
2016
2615
  }
2017
2616
 
2617
+ var emptyRoot = {};
2618
+
2018
2619
  function retryTask(request, task) {
2019
2620
  if (task.status !== PENDING$1) {
2020
2621
  // We completed this by other means before we had a chance to retry it.
2021
2622
  return;
2022
2623
  }
2023
2624
 
2024
- switchContext(task.context);
2625
+ var prevDebugID = debugID;
2025
2626
 
2026
2627
  try {
2027
- var value = task.model;
2028
-
2029
- if (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
2030
- // TODO: Concatenate keys of parents onto children.
2031
- var element = value; // When retrying a component, reuse the thenableState from the
2032
- // previous attempt.
2033
-
2034
- var prevThenableState = task.thenableState; // Attempt to render the Server Component.
2035
- // Doing this here lets us reuse this same task if the next component
2036
- // also suspends.
2037
-
2038
- task.model = value;
2039
- value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, prevThenableState); // Successfully finished this component. We're going to keep rendering
2040
- // using the same task, but we reset its thenable state before continuing.
2041
-
2042
- task.thenableState = null; // Keep rendering and reuse the same task. This inner loop is separate
2043
- // from the render above because we don't need to reset the thenable state
2044
- // until the next time something suspends and retries.
2045
-
2046
- while (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
2047
- // TODO: Concatenate keys of parents onto children.
2048
- var nextElement = value;
2049
- task.model = value;
2050
- value = attemptResolveElement(request, nextElement.type, nextElement.key, nextElement.ref, nextElement.props, null);
2051
- }
2628
+ // Track the root so we know that we have to emit this object even though it
2629
+ // already has an ID. This is needed because we might see this object twice
2630
+ // in the same toJSON if it is cyclic.
2631
+ modelRoot = task.model;
2632
+
2633
+ if (true) {
2634
+ // Track the ID of the current task so we can assign debug info to this id.
2635
+ debugID = task.id;
2636
+ } // We call the destructive form that mutates this task. That way if something
2637
+ // suspends again, we can reuse the same task instead of spawning a new one.
2638
+
2639
+
2640
+ var resolvedModel = renderModelDestructive(request, task, emptyRoot, '', task.model);
2641
+
2642
+ if (true) {
2643
+ // We're now past rendering this task and future renders will spawn new tasks for their
2644
+ // debug info.
2645
+ debugID = null;
2646
+ } // Track the root again for the resolved object.
2647
+
2648
+
2649
+ modelRoot = resolvedModel; // The keyPath resets at any terminal child node.
2650
+
2651
+ task.keyPath = null;
2652
+ task.implicitSlot = false;
2653
+ var json;
2654
+
2655
+ if (typeof resolvedModel === 'object' && resolvedModel !== null) {
2656
+ // Object might contain unresolved values like additional elements.
2657
+ // This is simulating what the JSON loop would do if this was part of it.
2658
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2659
+ json = stringify(resolvedModel, task.toJSON);
2660
+ } else {
2661
+ // If the value is a string, it means it's a terminal value and we already escaped it
2662
+ // We don't need to escape it again so it's not passed the toJSON replacer.
2663
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2664
+ json = stringify(resolvedModel);
2052
2665
  }
2053
2666
 
2054
- var processedChunk = processModelChunk(request, task.id, value);
2055
- request.completedJSONChunks.push(processedChunk);
2667
+ emitModelChunk(request, task.id, json);
2056
2668
  request.abortableTasks.delete(task);
2057
2669
  task.status = COMPLETED;
2058
2670
  } catch (thrownValue) {
@@ -2061,27 +2673,27 @@ function retryTask(request, task) {
2061
2673
  // value to be a thenable, because before `use` existed that was the
2062
2674
  // (unstable) API for suspending. This implementation detail can change
2063
2675
  // later, once we deprecate the old API in favor of `use`.
2064
- getSuspendedThenable() : thrownValue; // $FlowFixMe[method-unbinding]
2065
-
2066
- if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
2067
- // Something suspended again, let's pick it back up later.
2068
- var ping = task.ping;
2069
- x.then(ping, ping);
2070
- task.thenableState = getThenableStateAfterSuspending();
2071
- return;
2072
- } else {
2073
- request.abortableTasks.delete(task);
2074
- task.status = ERRORED$1;
2075
- var digest = logRecoverableError(request, x);
2076
-
2077
- {
2078
- var _getErrorMessageAndSt5 = getErrorMessageAndStackDev(x),
2079
- message = _getErrorMessageAndSt5.message,
2080
- stack = _getErrorMessageAndSt5.stack;
2676
+ getSuspendedThenable() : thrownValue;
2081
2677
 
2082
- emitErrorChunkDev(request, task.id, digest, message, stack);
2678
+ if (typeof x === 'object' && x !== null) {
2679
+ // $FlowFixMe[method-unbinding]
2680
+ if (typeof x.then === 'function') {
2681
+ // Something suspended again, let's pick it back up later.
2682
+ var ping = task.ping;
2683
+ x.then(ping, ping);
2684
+ task.thenableState = getThenableStateAfterSuspending();
2685
+ return;
2083
2686
  }
2084
2687
  }
2688
+
2689
+ request.abortableTasks.delete(task);
2690
+ task.status = ERRORED$1;
2691
+ var digest = logRecoverableError(request, x);
2692
+ emitErrorChunk(request, task.id, digest, x);
2693
+ } finally {
2694
+ {
2695
+ debugID = prevDebugID;
2696
+ }
2085
2697
  }
2086
2698
  }
2087
2699
 
@@ -2119,7 +2731,7 @@ function abortTask(task, request, errorId) {
2119
2731
  // has a single value referencing the error.
2120
2732
 
2121
2733
  var ref = serializeByValueID(errorId);
2122
- var processedChunk = processReferenceChunk(request, task.id, ref);
2734
+ var processedChunk = encodeReferenceChunk(request, task.id, ref);
2123
2735
  request.completedErrorChunks.push(processedChunk);
2124
2736
  }
2125
2737
 
@@ -2163,12 +2775,12 @@ function flushCompletedChunks(request, destination) {
2163
2775
 
2164
2776
  hintChunks.splice(0, i); // Next comes model data.
2165
2777
 
2166
- var jsonChunks = request.completedJSONChunks;
2778
+ var regularChunks = request.completedRegularChunks;
2167
2779
  i = 0;
2168
2780
 
2169
- for (; i < jsonChunks.length; i++) {
2781
+ for (; i < regularChunks.length; i++) {
2170
2782
  request.pendingChunks--;
2171
- var _chunk2 = jsonChunks[i];
2783
+ var _chunk2 = regularChunks[i];
2172
2784
 
2173
2785
  var _keepWriting2 = writeChunkAndReturn(destination, _chunk2);
2174
2786
 
@@ -2179,7 +2791,7 @@ function flushCompletedChunks(request, destination) {
2179
2791
  }
2180
2792
  }
2181
2793
 
2182
- jsonChunks.splice(0, i); // Finally, errors are sent. The idea is that it's ok to delay
2794
+ regularChunks.splice(0, i); // Finally, errors are sent. The idea is that it's ok to delay
2183
2795
  // any error messages and prioritize display of other parts of
2184
2796
  // the page.
2185
2797
 
@@ -2206,7 +2818,7 @@ function flushCompletedChunks(request, destination) {
2206
2818
  }
2207
2819
 
2208
2820
  if (request.pendingChunks === 0) {
2209
- // We're done.
2821
+
2210
2822
  close$1(destination);
2211
2823
  }
2212
2824
  }
@@ -2258,6 +2870,9 @@ function startFlowing(request, destination) {
2258
2870
  logRecoverableError(request, error);
2259
2871
  fatalError(request, error);
2260
2872
  }
2873
+ }
2874
+ function stopFlowing(request) {
2875
+ request.destination = null;
2261
2876
  } // This is called to early terminate a request. It creates an error at all pending tasks.
2262
2877
 
2263
2878
  function abort(request, reason) {
@@ -2267,17 +2882,13 @@ function abort(request, reason) {
2267
2882
  if (abortableTasks.size > 0) {
2268
2883
  // We have tasks to abort. We'll emit one error row and then emit a reference
2269
2884
  // to that row from every row that's still remaining.
2270
- var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
2271
- var digest = logRecoverableError(request, error);
2272
2885
  request.pendingChunks++;
2273
2886
  var errorId = request.nextChunkId++;
2274
2887
 
2275
- if (true) {
2276
- var _getErrorMessageAndSt6 = getErrorMessageAndStackDev(error),
2277
- message = _getErrorMessageAndSt6.message,
2278
- stack = _getErrorMessageAndSt6.stack;
2279
-
2280
- emitErrorChunkDev(request, errorId, digest, message, stack);
2888
+ var postponeInstance; if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
2889
+ var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
2890
+ var digest = logRecoverableError(request, error);
2891
+ emitErrorChunk(request, errorId, digest, error);
2281
2892
  }
2282
2893
 
2283
2894
  abortableTasks.forEach(function (task) {
@@ -2295,28 +2906,20 @@ function abort(request, reason) {
2295
2906
  }
2296
2907
  }
2297
2908
 
2298
- function importServerContexts(contexts) {
2299
- if (contexts) {
2300
- var prevContext = getActiveContext();
2301
- switchContext(rootContextSnapshot);
2302
-
2303
- for (var i = 0; i < contexts.length; i++) {
2304
- var _contexts$i = contexts[i],
2305
- name = _contexts$i[0],
2306
- value = _contexts$i[1];
2307
- var context = getOrCreateServerContext(name);
2308
- pushProvider(context, value);
2309
- }
2310
-
2311
- var importedContext = getActiveContext();
2312
- switchContext(prevContext);
2313
- return importedContext;
2314
- }
2909
+ // This is the parsed shape of the wire format which is why it is
2910
+ // condensed to only the essentialy information
2911
+ var ID = 0;
2912
+ var CHUNKS = 1;
2913
+ var NAME = 2; // export const ASYNC = 3;
2914
+ // This logic is correct because currently only include the 4th tuple member
2915
+ // when the module is async. If that changes we will need to actually assert
2916
+ // the value is true. We don't index into the 4th slot because flow does not
2917
+ // like the potential out of bounds access
2315
2918
 
2316
- return rootContextSnapshot;
2919
+ function isAsyncImport(metadata) {
2920
+ return metadata.length === 4;
2317
2921
  }
2318
2922
 
2319
- // eslint-disable-next-line no-unused-vars
2320
2923
  function resolveServerReference(bundlerConfig, id) {
2321
2924
  var name = '';
2322
2925
  var resolvedModuleData = bundlerConfig[id];
@@ -2342,19 +2945,38 @@ function resolveServerReference(bundlerConfig, id) {
2342
2945
  } // TODO: This needs to return async: true if it's an async module.
2343
2946
 
2344
2947
 
2345
- return {
2346
- id: resolvedModuleData.id,
2347
- chunks: resolvedModuleData.chunks,
2348
- name: name,
2349
- async: false
2350
- };
2948
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
2351
2949
  } // The chunk cache contains all the chunks we've preloaded so far.
2352
2950
  // If they're still pending they're a thenable. This map also exists
2353
2951
  // in Webpack but unfortunately it's not exposed so we have to
2354
2952
  // replicate it in user space. null means that it has already loaded.
2355
2953
 
2356
2954
  var chunkCache = new Map();
2357
- var asyncModuleCache = new Map();
2955
+
2956
+ function requireAsyncModule(id) {
2957
+ // We've already loaded all the chunks. We can require the module.
2958
+ var promise = __webpack_require__(id);
2959
+
2960
+ if (typeof promise.then !== 'function') {
2961
+ // This wasn't a promise after all.
2962
+ return null;
2963
+ } else if (promise.status === 'fulfilled') {
2964
+ // This module was already resolved earlier.
2965
+ return null;
2966
+ } else {
2967
+ // Instrument the Promise to stash the result.
2968
+ promise.then(function (value) {
2969
+ var fulfilledThenable = promise;
2970
+ fulfilledThenable.status = 'fulfilled';
2971
+ fulfilledThenable.value = value;
2972
+ }, function (reason) {
2973
+ var rejectedThenable = promise;
2974
+ rejectedThenable.status = 'rejected';
2975
+ rejectedThenable.reason = reason;
2976
+ });
2977
+ return promise;
2978
+ }
2979
+ }
2358
2980
 
2359
2981
  function ignoreReject() {// We rely on rejected promises to be handled by another listener.
2360
2982
  } // Start preloading the modules since we might need them soon.
@@ -2362,16 +2984,17 @@ function ignoreReject() {// We rely on rejected promises to be handled by anothe
2362
2984
 
2363
2985
 
2364
2986
  function preloadModule(metadata) {
2365
- var chunks = metadata.chunks;
2987
+ var chunks = metadata[CHUNKS];
2366
2988
  var promises = [];
2989
+ var i = 0;
2367
2990
 
2368
- for (var i = 0; i < chunks.length; i++) {
2369
- var chunkId = chunks[i];
2991
+ while (i < chunks.length) {
2992
+ var chunkId = chunks[i++];
2993
+ var chunkFilename = chunks[i++];
2370
2994
  var entry = chunkCache.get(chunkId);
2371
2995
 
2372
2996
  if (entry === undefined) {
2373
- var thenable = __webpack_chunk_load__(chunkId);
2374
-
2997
+ var thenable = loadChunk(chunkId, chunkFilename);
2375
2998
  promises.push(thenable); // $FlowFixMe[method-unbinding]
2376
2999
 
2377
3000
  var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
@@ -2382,30 +3005,13 @@ function preloadModule(metadata) {
2382
3005
  }
2383
3006
  }
2384
3007
 
2385
- if (metadata.async) {
2386
- var existingPromise = asyncModuleCache.get(metadata.id);
2387
-
2388
- if (existingPromise) {
2389
- if (existingPromise.status === 'fulfilled') {
2390
- return null;
2391
- }
2392
-
2393
- return existingPromise;
3008
+ if (isAsyncImport(metadata)) {
3009
+ if (promises.length === 0) {
3010
+ return requireAsyncModule(metadata[ID]);
2394
3011
  } else {
2395
- var modulePromise = Promise.all(promises).then(function () {
2396
- return __webpack_require__(metadata.id);
3012
+ return Promise.all(promises).then(function () {
3013
+ return requireAsyncModule(metadata[ID]);
2397
3014
  });
2398
- modulePromise.then(function (value) {
2399
- var fulfilledThenable = modulePromise;
2400
- fulfilledThenable.status = 'fulfilled';
2401
- fulfilledThenable.value = value;
2402
- }, function (reason) {
2403
- var rejectedThenable = modulePromise;
2404
- rejectedThenable.status = 'rejected';
2405
- rejectedThenable.reason = reason;
2406
- });
2407
- asyncModuleCache.set(metadata.id, modulePromise);
2408
- return modulePromise;
2409
3015
  }
2410
3016
  } else if (promises.length > 0) {
2411
3017
  return Promise.all(promises);
@@ -2416,35 +3022,53 @@ function preloadModule(metadata) {
2416
3022
  // Increase priority if necessary.
2417
3023
 
2418
3024
  function requireModule(metadata) {
2419
- var moduleExports;
2420
-
2421
- if (metadata.async) {
2422
- // We assume that preloadModule has been called before, which
2423
- // should have added something to the module cache.
2424
- var promise = asyncModuleCache.get(metadata.id);
3025
+ var moduleExports = __webpack_require__(metadata[ID]);
2425
3026
 
2426
- if (promise.status === 'fulfilled') {
2427
- moduleExports = promise.value;
3027
+ if (isAsyncImport(metadata)) {
3028
+ if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
3029
+ // This Promise should've been instrumented by preloadModule.
3030
+ moduleExports = moduleExports.value;
2428
3031
  } else {
2429
- throw promise.reason;
3032
+ throw moduleExports.reason;
2430
3033
  }
2431
- } else {
2432
- moduleExports = __webpack_require__(metadata.id);
2433
3034
  }
2434
3035
 
2435
- if (metadata.name === '*') {
3036
+ if (metadata[NAME] === '*') {
2436
3037
  // This is a placeholder value that represents that the caller imported this
2437
3038
  // as a CommonJS module as is.
2438
3039
  return moduleExports;
2439
3040
  }
2440
3041
 
2441
- if (metadata.name === '') {
3042
+ if (metadata[NAME] === '') {
2442
3043
  // This is a placeholder value that represents that the caller accessed the
2443
3044
  // default property of this if it was an ESM interop module.
2444
3045
  return moduleExports.__esModule ? moduleExports.default : moduleExports;
2445
3046
  }
2446
3047
 
2447
- return moduleExports[metadata.name];
3048
+ return moduleExports[metadata[NAME]];
3049
+ }
3050
+
3051
+ var chunkMap = new Map();
3052
+ /**
3053
+ * We patch the chunk filename function in webpack to insert our own resolution
3054
+ * of chunks that come from Flight and may not be known to the webpack runtime
3055
+ */
3056
+
3057
+ var webpackGetChunkFilename = __webpack_require__.u;
3058
+
3059
+ __webpack_require__.u = function (chunkId) {
3060
+ var flightChunk = chunkMap.get(chunkId);
3061
+
3062
+ if (flightChunk !== undefined) {
3063
+ return flightChunk;
3064
+ }
3065
+
3066
+ return webpackGetChunkFilename(chunkId);
3067
+ };
3068
+
3069
+ function loadChunk(chunkId, filename) {
3070
+ chunkMap.set(chunkId, filename);
3071
+ return __webpack_chunk_load__(chunkId);
2448
3072
  }
2449
3073
 
2450
3074
  // The server acts as a Client of itself when resolving Server References.
@@ -2544,11 +3168,11 @@ function createResolvedModelChunk(response, value) {
2544
3168
  return new Chunk(RESOLVED_MODEL, value, null, response);
2545
3169
  }
2546
3170
 
2547
- function bindArgs(fn, args) {
3171
+ function bindArgs$1(fn, args) {
2548
3172
  return fn.bind.apply(fn, [null].concat(args));
2549
3173
  }
2550
3174
 
2551
- function loadServerReference(response, id, bound, parentChunk, parentObject, key) {
3175
+ function loadServerReference$1(response, id, bound, parentChunk, parentObject, key) {
2552
3176
  var serverReference = resolveServerReference(response._bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
2553
3177
  // the relevant modules already loaded but it allows for lazy loading of code
2554
3178
  // if needed.
@@ -2559,7 +3183,7 @@ function loadServerReference(response, id, bound, parentChunk, parentObject, key
2559
3183
  if (bound) {
2560
3184
  promise = Promise.all([bound, preloadPromise]).then(function (_ref) {
2561
3185
  var args = _ref[0];
2562
- return bindArgs(requireModule(serverReference), args);
3186
+ return bindArgs$1(requireModule(serverReference), args);
2563
3187
  });
2564
3188
  } else {
2565
3189
  if (preloadPromise) {
@@ -2689,6 +3313,21 @@ function createModelReject(chunk) {
2689
3313
  };
2690
3314
  }
2691
3315
 
3316
+ function getOutlinedModel(response, id) {
3317
+ var chunk = getChunk(response, id);
3318
+
3319
+ if (chunk.status === RESOLVED_MODEL) {
3320
+ initializeModelChunk(chunk);
3321
+ }
3322
+
3323
+ if (chunk.status !== INITIALIZED) {
3324
+ // We know that this is emitted earlier so otherwise it's an error.
3325
+ throw chunk.reason;
3326
+ }
3327
+
3328
+ return chunk.value;
3329
+ }
3330
+
2692
3331
  function parseModelString(response, parentObject, key, value) {
2693
3332
  if (value[0] === '$') {
2694
3333
  switch (value[1]) {
@@ -2706,31 +3345,39 @@ function parseModelString(response, parentObject, key, value) {
2706
3345
  return chunk;
2707
3346
  }
2708
3347
 
2709
- case 'S':
3348
+ case 'F':
2710
3349
  {
2711
- // Symbol
2712
- return Symbol.for(value.slice(2));
3350
+ // Server Reference
3351
+ var _id = parseInt(value.slice(2), 16); // TODO: Just encode this in the reference inline instead of as a model.
3352
+
3353
+
3354
+ var metaData = getOutlinedModel(response, _id);
3355
+ return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
2713
3356
  }
2714
3357
 
2715
- case 'F':
3358
+ case 'T':
2716
3359
  {
2717
- // Server Reference
2718
- var _id = parseInt(value.slice(2), 16);
3360
+ // Temporary Reference
3361
+ return createTemporaryReference(value.slice(2));
3362
+ }
2719
3363
 
2720
- var _chunk = getChunk(response, _id);
3364
+ case 'Q':
3365
+ {
3366
+ // Map
3367
+ var _id2 = parseInt(value.slice(2), 16);
2721
3368
 
2722
- if (_chunk.status === RESOLVED_MODEL) {
2723
- initializeModelChunk(_chunk);
2724
- }
3369
+ var data = getOutlinedModel(response, _id2);
3370
+ return new Map(data);
3371
+ }
2725
3372
 
2726
- if (_chunk.status !== INITIALIZED) {
2727
- // We know that this is emitted earlier so otherwise it's an error.
2728
- throw _chunk.reason;
2729
- } // TODO: Just encode this in the reference inline instead of as a model.
3373
+ case 'W':
3374
+ {
3375
+ // Set
3376
+ var _id3 = parseInt(value.slice(2), 16);
2730
3377
 
3378
+ var _data = getOutlinedModel(response, _id3);
2731
3379
 
2732
- var metaData = _chunk.value;
2733
- return loadServerReference(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
3380
+ return new Set(_data);
2734
3381
  }
2735
3382
 
2736
3383
  case 'K':
@@ -2738,7 +3385,9 @@ function parseModelString(response, parentObject, key, value) {
2738
3385
  // FormData
2739
3386
  var stringId = value.slice(2);
2740
3387
  var formPrefix = response._prefix + stringId + '_';
2741
- var data = new FormData();
3388
+
3389
+ var _data2 = new FormData();
3390
+
2742
3391
  var backingFormData = response._formData; // We assume that the reference to FormData always comes after each
2743
3392
  // entry that it references so we can assume they all exist in the
2744
3393
  // backing store already.
@@ -2746,10 +3395,10 @@ function parseModelString(response, parentObject, key, value) {
2746
3395
 
2747
3396
  backingFormData.forEach(function (entry, entryKey) {
2748
3397
  if (entryKey.startsWith(formPrefix)) {
2749
- data.append(entryKey.slice(formPrefix.length), entry);
3398
+ _data2.append(entryKey.slice(formPrefix.length), entry);
2750
3399
  }
2751
3400
  });
2752
- return data;
3401
+ return _data2;
2753
3402
  }
2754
3403
 
2755
3404
  case 'I':
@@ -2796,31 +3445,31 @@ function parseModelString(response, parentObject, key, value) {
2796
3445
  default:
2797
3446
  {
2798
3447
  // We assume that anything else is a reference ID.
2799
- var _id2 = parseInt(value.slice(1), 16);
3448
+ var _id4 = parseInt(value.slice(1), 16);
2800
3449
 
2801
- var _chunk2 = getChunk(response, _id2);
3450
+ var _chunk = getChunk(response, _id4);
2802
3451
 
2803
- switch (_chunk2.status) {
3452
+ switch (_chunk.status) {
2804
3453
  case RESOLVED_MODEL:
2805
- initializeModelChunk(_chunk2);
3454
+ initializeModelChunk(_chunk);
2806
3455
  break;
2807
3456
  } // The status might have changed after initialization.
2808
3457
 
2809
3458
 
2810
- switch (_chunk2.status) {
3459
+ switch (_chunk.status) {
2811
3460
  case INITIALIZED:
2812
- return _chunk2.value;
3461
+ return _chunk.value;
2813
3462
 
2814
3463
  case PENDING:
2815
3464
  case BLOCKED:
2816
3465
  var parentChunk = initializingChunk;
2817
3466
 
2818
- _chunk2.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
3467
+ _chunk.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
2819
3468
 
2820
3469
  return null;
2821
3470
 
2822
3471
  default:
2823
- throw _chunk2.reason;
3472
+ throw _chunk.reason;
2824
3473
  }
2825
3474
  }
2826
3475
  }
@@ -2856,8 +3505,130 @@ function close(response) {
2856
3505
  reportGlobalError(response, new Error('Connection closed.'));
2857
3506
  }
2858
3507
 
3508
+ function bindArgs(fn, args) {
3509
+ return fn.bind.apply(fn, [null].concat(args));
3510
+ }
3511
+
3512
+ function loadServerReference(bundlerConfig, id, bound) {
3513
+ var serverReference = resolveServerReference(bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
3514
+ // the relevant modules already loaded but it allows for lazy loading of code
3515
+ // if needed.
3516
+
3517
+ var preloadPromise = preloadModule(serverReference);
3518
+
3519
+ if (bound) {
3520
+ return Promise.all([bound, preloadPromise]).then(function (_ref) {
3521
+ var args = _ref[0];
3522
+ return bindArgs(requireModule(serverReference), args);
3523
+ });
3524
+ } else if (preloadPromise) {
3525
+ return Promise.resolve(preloadPromise).then(function () {
3526
+ return requireModule(serverReference);
3527
+ });
3528
+ } else {
3529
+ // Synchronously available
3530
+ return Promise.resolve(requireModule(serverReference));
3531
+ }
3532
+ }
3533
+
3534
+ function decodeBoundActionMetaData(body, serverManifest, formFieldPrefix) {
3535
+ // The data for this reference is encoded in multiple fields under this prefix.
3536
+ var actionResponse = createResponse(serverManifest, formFieldPrefix, body);
3537
+ close(actionResponse);
3538
+ var refPromise = getRoot(actionResponse); // Force it to initialize
3539
+ // $FlowFixMe
3540
+
3541
+ refPromise.then(function () {});
3542
+
3543
+ if (refPromise.status !== 'fulfilled') {
3544
+ // $FlowFixMe
3545
+ throw refPromise.reason;
3546
+ }
3547
+
3548
+ return refPromise.value;
3549
+ }
3550
+
3551
+ function decodeAction(body, serverManifest) {
3552
+ // We're going to create a new formData object that holds all the fields except
3553
+ // the implementation details of the action data.
3554
+ var formData = new FormData();
3555
+ var action = null; // $FlowFixMe[prop-missing]
3556
+
3557
+ body.forEach(function (value, key) {
3558
+ if (!key.startsWith('$ACTION_')) {
3559
+ formData.append(key, value);
3560
+ return;
3561
+ } // Later actions may override earlier actions if a button is used to override the default
3562
+ // form action.
3563
+
3564
+
3565
+ if (key.startsWith('$ACTION_REF_')) {
3566
+ var formFieldPrefix = '$ACTION_' + key.slice(12) + ':';
3567
+ var metaData = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3568
+ action = loadServerReference(serverManifest, metaData.id, metaData.bound);
3569
+ return;
3570
+ }
3571
+
3572
+ if (key.startsWith('$ACTION_ID_')) {
3573
+ var id = key.slice(11);
3574
+ action = loadServerReference(serverManifest, id, null);
3575
+ return;
3576
+ }
3577
+ });
3578
+
3579
+ if (action === null) {
3580
+ return null;
3581
+ } // Return the action with the remaining FormData bound to the first argument.
3582
+
3583
+
3584
+ return action.then(function (fn) {
3585
+ return fn.bind(null, formData);
3586
+ });
3587
+ }
3588
+ function decodeFormState(actionResult, body, serverManifest) {
3589
+ var keyPath = body.get('$ACTION_KEY');
3590
+
3591
+ if (typeof keyPath !== 'string') {
3592
+ // This form submission did not include any form state.
3593
+ return Promise.resolve(null);
3594
+ } // Search through the form data object to get the reference id and the number
3595
+ // of bound arguments. This repeats some of the work done in decodeAction.
3596
+
3597
+
3598
+ var metaData = null; // $FlowFixMe[prop-missing]
3599
+
3600
+ body.forEach(function (value, key) {
3601
+ if (key.startsWith('$ACTION_REF_')) {
3602
+ var formFieldPrefix = '$ACTION_' + key.slice(12) + ':';
3603
+ metaData = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3604
+ } // We don't check for the simple $ACTION_ID_ case because form state actions
3605
+ // are always bound to the state argument.
3606
+
3607
+ });
3608
+
3609
+ if (metaData === null) {
3610
+ // Should be unreachable.
3611
+ return Promise.resolve(null);
3612
+ }
3613
+
3614
+ var referenceId = metaData.id;
3615
+ return Promise.resolve(metaData.bound).then(function (bound) {
3616
+ if (bound === null) {
3617
+ // Should be unreachable because form state actions are always bound to the
3618
+ // state argument.
3619
+ return null;
3620
+ } // The form action dispatch method is always bound to the initial state.
3621
+ // But when comparing signatures, we compare to the original unbound action.
3622
+ // Subtract one from the arity to account for this.
3623
+
3624
+
3625
+ var boundArity = bound.length - 1;
3626
+ return [actionResult, keyPath, referenceId, boundArity];
3627
+ });
3628
+ }
3629
+
2859
3630
  function renderToReadableStream(model, webpackMap, options) {
2860
- var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.context : undefined, options ? options.identifierPrefix : undefined);
3631
+ var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.identifierPrefix : undefined, options ? options.onPostpone : undefined, options ? options.environmentName : undefined);
2861
3632
 
2862
3633
  if (options && options.signal) {
2863
3634
  var signal = options.signal;
@@ -2882,7 +3653,10 @@ function renderToReadableStream(model, webpackMap, options) {
2882
3653
  pull: function (controller) {
2883
3654
  startFlowing(request, controller);
2884
3655
  },
2885
- cancel: function (reason) {}
3656
+ cancel: function (reason) {
3657
+ stopFlowing(request);
3658
+ abort(request, reason);
3659
+ }
2886
3660
  }, // $FlowFixMe[prop-missing] size() methods are not allowed on byte streams.
2887
3661
  {
2888
3662
  highWaterMark: 0
@@ -2898,11 +3672,17 @@ function decodeReply(body, webpackMap) {
2898
3672
  }
2899
3673
 
2900
3674
  var response = createResponse(webpackMap, '', body);
3675
+ var root = getRoot(response);
2901
3676
  close(response);
2902
- return getRoot(response);
3677
+ return root;
2903
3678
  }
2904
3679
 
3680
+ exports.createClientModuleProxy = createClientModuleProxy;
3681
+ exports.decodeAction = decodeAction;
3682
+ exports.decodeFormState = decodeFormState;
2905
3683
  exports.decodeReply = decodeReply;
3684
+ exports.registerClientReference = registerClientReference;
3685
+ exports.registerServerReference = registerServerReference;
2906
3686
  exports.renderToReadableStream = renderToReadableStream;
2907
3687
  })();
2908
3688
  }