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
@@ -15,8 +15,9 @@ if (process.env.NODE_ENV !== "production") {
15
15
  'use strict';
16
16
 
17
17
  var React = require('react');
18
- var async_hooks = require('async_hooks');
19
18
  var util = require('util');
19
+ require('crypto');
20
+ var async_hooks = require('async_hooks');
20
21
  var ReactDOM = require('react-dom');
21
22
 
22
23
  var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
@@ -58,6 +59,9 @@ function printWarning(level, format, args) {
58
59
  }
59
60
  }
60
61
 
62
+ // -----------------------------------------------------------------------------
63
+ var enablePostpone = false;
64
+
61
65
  function scheduleWork(callback) {
62
66
  setImmediate(callback);
63
67
  }
@@ -128,15 +132,9 @@ function writeViewChunk(destination, chunk) {
128
132
  }
129
133
 
130
134
  if (chunk.byteLength > VIEW_SIZE) {
131
- {
132
- if (precomputedChunkSet && precomputedChunkSet.has(chunk)) {
133
- 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.');
134
- }
135
- } // this chunk may overflow a single view which implies it was not
135
+ // this chunk may overflow a single view which implies it was not
136
136
  // one that is cached by the streaming renderer. We will enqueu
137
137
  // it directly and expect it is not re-used
138
-
139
-
140
138
  if (writtenBytes > 0) {
141
139
  writeToDestination(destination, currentView.subarray(0, writtenBytes));
142
140
  currentView = new Uint8Array(VIEW_SIZE);
@@ -212,71 +210,278 @@ var textEncoder = new util.TextEncoder();
212
210
  function stringToChunk(content) {
213
211
  return content;
214
212
  }
215
- var precomputedChunkSet = new Set() ;
213
+ function byteLengthOfChunk(chunk) {
214
+ return typeof chunk === 'string' ? Buffer.byteLength(chunk, 'utf8') : chunk.byteLength;
215
+ }
216
216
  function closeWithError(destination, error) {
217
217
  // $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
218
218
  destination.destroy(error);
219
219
  }
220
220
 
221
- // This file is an intermediate layer to translate between Flight
222
- var stringify = JSON.stringify;
223
-
224
- function serializeRowHeader(tag, id) {
225
- return id.toString(16) + ':' + tag;
221
+ // eslint-disable-next-line no-unused-vars
222
+ var CLIENT_REFERENCE_TAG$1 = Symbol.for('react.client.reference');
223
+ var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
224
+ function isClientReference(reference) {
225
+ return reference.$$typeof === CLIENT_REFERENCE_TAG$1;
226
+ }
227
+ function isServerReference(reference) {
228
+ return reference.$$typeof === SERVER_REFERENCE_TAG;
229
+ }
230
+ function registerClientReference(proxyImplementation, id, exportName) {
231
+ return registerClientReferenceImpl(proxyImplementation, id + '#' + exportName, false);
226
232
  }
227
233
 
228
- function processErrorChunkProd(request, id, digest) {
229
- {
230
- // These errors should never make it into a build so we don't need to encode them in codes.json
231
- // eslint-disable-next-line react-internal/prod-error-codes
232
- throw new Error('processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.');
234
+ function registerClientReferenceImpl(proxyImplementation, id, async) {
235
+ return Object.defineProperties(proxyImplementation, {
236
+ $$typeof: {
237
+ value: CLIENT_REFERENCE_TAG$1
238
+ },
239
+ $$id: {
240
+ value: id
241
+ },
242
+ $$async: {
243
+ value: async
244
+ }
245
+ });
246
+ } // $FlowFixMe[method-unbinding]
247
+
248
+
249
+ var FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
250
+
251
+ var ArraySlice = Array.prototype.slice;
252
+
253
+ function bind() {
254
+ // $FlowFixMe[unsupported-syntax]
255
+ var newFn = FunctionBind.apply(this, arguments);
256
+
257
+ if (this.$$typeof === SERVER_REFERENCE_TAG) {
258
+ {
259
+ var thisBind = arguments[0];
260
+
261
+ if (thisBind != null) {
262
+ error('Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().');
263
+ }
264
+ }
265
+
266
+ var args = ArraySlice.call(arguments, 1);
267
+ return Object.defineProperties(newFn, {
268
+ $$typeof: {
269
+ value: SERVER_REFERENCE_TAG
270
+ },
271
+ $$id: {
272
+ value: this.$$id
273
+ },
274
+ $$bound: {
275
+ value: this.$$bound ? this.$$bound.concat(args) : args
276
+ },
277
+ bind: {
278
+ value: bind
279
+ }
280
+ });
233
281
  }
234
- }
235
- function processErrorChunkDev(request, id, digest, message, stack) {
236
282
 
237
- var errorInfo = {
238
- digest: digest,
239
- message: message,
240
- stack: stack
241
- };
242
- var row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
243
- return stringToChunk(row);
283
+ return newFn;
244
284
  }
245
- function processModelChunk(request, id, model) {
246
- // $FlowFixMe[incompatible-type] stringify can return null
247
- var json = stringify(model, request.toJSON);
248
- var row = id.toString(16) + ':' + json + '\n';
249
- return stringToChunk(row);
250
- }
251
- function processReferenceChunk(request, id, reference) {
252
- var json = stringify(reference);
253
- var row = id.toString(16) + ':' + json + '\n';
254
- return stringToChunk(row);
285
+
286
+ function registerServerReference(reference, id, exportName) {
287
+ return Object.defineProperties(reference, {
288
+ $$typeof: {
289
+ value: SERVER_REFERENCE_TAG
290
+ },
291
+ $$id: {
292
+ value: exportName === null ? id : id + '#' + exportName,
293
+ configurable: true
294
+ },
295
+ $$bound: {
296
+ value: null,
297
+ configurable: true
298
+ },
299
+ bind: {
300
+ value: bind,
301
+ configurable: true
302
+ }
303
+ });
255
304
  }
256
- function processImportChunk(request, id, clientReferenceMetadata) {
257
- // $FlowFixMe[incompatible-type] stringify can return null
258
- var json = stringify(clientReferenceMetadata);
259
- var row = serializeRowHeader('I', id) + json + '\n';
260
- return stringToChunk(row);
305
+ var PROMISE_PROTOTYPE = Promise.prototype;
306
+ var deepProxyHandlers = {
307
+ get: function (target, name, receiver) {
308
+ switch (name) {
309
+ // These names are read by the Flight runtime if you end up using the exports object.
310
+ case '$$typeof':
311
+ // These names are a little too common. We should probably have a way to
312
+ // have the Flight runtime extract the inner target instead.
313
+ return target.$$typeof;
314
+
315
+ case '$$id':
316
+ return target.$$id;
317
+
318
+ case '$$async':
319
+ return target.$$async;
320
+
321
+ case 'name':
322
+ return target.name;
323
+
324
+ case 'displayName':
325
+ return undefined;
326
+ // We need to special case this because createElement reads it if we pass this
327
+ // reference.
328
+
329
+ case 'defaultProps':
330
+ return undefined;
331
+ // Avoid this attempting to be serialized.
332
+
333
+ case 'toJSON':
334
+ return undefined;
335
+
336
+ case Symbol.toPrimitive:
337
+ // $FlowFixMe[prop-missing]
338
+ return Object.prototype[Symbol.toPrimitive];
339
+
340
+ case Symbol.toStringTag:
341
+ // $FlowFixMe[prop-missing]
342
+ return Object.prototype[Symbol.toStringTag];
343
+
344
+ case 'Provider':
345
+ 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.");
346
+ } // eslint-disable-next-line react-internal/safe-string-coercion
347
+
348
+
349
+ var expression = String(target.name) + '.' + String(name);
350
+ 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.');
351
+ },
352
+ set: function () {
353
+ throw new Error('Cannot assign to a client module from a server module.');
354
+ }
355
+ };
356
+
357
+ function getReference(target, name) {
358
+ switch (name) {
359
+ // These names are read by the Flight runtime if you end up using the exports object.
360
+ case '$$typeof':
361
+ return target.$$typeof;
362
+
363
+ case '$$id':
364
+ return target.$$id;
365
+
366
+ case '$$async':
367
+ return target.$$async;
368
+
369
+ case 'name':
370
+ return target.name;
371
+ // We need to special case this because createElement reads it if we pass this
372
+ // reference.
373
+
374
+ case 'defaultProps':
375
+ return undefined;
376
+ // Avoid this attempting to be serialized.
377
+
378
+ case 'toJSON':
379
+ return undefined;
380
+
381
+ case Symbol.toPrimitive:
382
+ // $FlowFixMe[prop-missing]
383
+ return Object.prototype[Symbol.toPrimitive];
384
+
385
+ case Symbol.toStringTag:
386
+ // $FlowFixMe[prop-missing]
387
+ return Object.prototype[Symbol.toStringTag];
388
+
389
+ case '__esModule':
390
+ // Something is conditionally checking which export to use. We'll pretend to be
391
+ // an ESM compat module but then we'll check again on the client.
392
+ var moduleId = target.$$id;
393
+ target.default = registerClientReferenceImpl(function () {
394
+ 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.");
395
+ }, target.$$id + '#', target.$$async);
396
+ return true;
397
+
398
+ case 'then':
399
+ if (target.then) {
400
+ // Use a cached value
401
+ return target.then;
402
+ }
403
+
404
+ if (!target.$$async) {
405
+ // If this module is expected to return a Promise (such as an AsyncModule) then
406
+ // we should resolve that with a client reference that unwraps the Promise on
407
+ // the client.
408
+ var clientReference = registerClientReferenceImpl({}, target.$$id, true);
409
+ var proxy = new Proxy(clientReference, proxyHandlers$1); // Treat this as a resolved Promise for React's use()
410
+
411
+ target.status = 'fulfilled';
412
+ target.value = proxy;
413
+ var then = target.then = registerClientReferenceImpl(function then(resolve, reject) {
414
+ // Expose to React.
415
+ return Promise.resolve(resolve(proxy));
416
+ }, // If this is not used as a Promise but is treated as a reference to a `.then`
417
+ // export then we should treat it as a reference to that name.
418
+ target.$$id + '#then', false);
419
+ return then;
420
+ } else {
421
+ // Since typeof .then === 'function' is a feature test we'd continue recursing
422
+ // indefinitely if we return a function. Instead, we return an object reference
423
+ // if we check further.
424
+ return undefined;
425
+ }
426
+
427
+ }
428
+
429
+ if (typeof name === 'symbol') {
430
+ throw new Error('Cannot read Symbol exports. Only named exports are supported on a client module ' + 'imported on the server.');
431
+ }
432
+
433
+ var cachedReference = target[name];
434
+
435
+ if (!cachedReference) {
436
+ var reference = registerClientReferenceImpl(function () {
437
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
438
+ "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.");
439
+ }, target.$$id + '#' + name, target.$$async);
440
+ Object.defineProperty(reference, 'name', {
441
+ value: name
442
+ });
443
+ cachedReference = target[name] = new Proxy(reference, deepProxyHandlers);
444
+ }
445
+
446
+ return cachedReference;
261
447
  }
262
- function processHintChunk(request, id, code, model) {
263
- var json = stringify(model);
264
- var row = serializeRowHeader('H' + code, id) + json + '\n';
265
- return stringToChunk(row);
448
+
449
+ var proxyHandlers$1 = {
450
+ get: function (target, name, receiver) {
451
+ return getReference(target, name);
452
+ },
453
+ getOwnPropertyDescriptor: function (target, name) {
454
+ var descriptor = Object.getOwnPropertyDescriptor(target, name);
455
+
456
+ if (!descriptor) {
457
+ descriptor = {
458
+ value: getReference(target, name),
459
+ writable: false,
460
+ configurable: false,
461
+ enumerable: false
462
+ };
463
+ Object.defineProperty(target, name, descriptor);
464
+ }
465
+
466
+ return descriptor;
467
+ },
468
+ getPrototypeOf: function (target) {
469
+ // Pretend to be a Promise in case anyone asks.
470
+ return PROMISE_PROTOTYPE;
471
+ },
472
+ set: function () {
473
+ throw new Error('Cannot assign to a client module from a server module.');
474
+ }
475
+ };
476
+ function createClientModuleProxy(moduleId) {
477
+ var clientReference = registerClientReferenceImpl({}, // Represents the whole Module object instead of a particular import.
478
+ moduleId, false);
479
+ return new Proxy(clientReference, proxyHandlers$1);
266
480
  }
267
481
 
268
- // eslint-disable-next-line no-unused-vars
269
- var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
270
- var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
271
482
  function getClientReferenceKey(reference) {
272
483
  return reference.$$async ? reference.$$id + '#async' : reference.$$id;
273
484
  }
274
- function isClientReference(reference) {
275
- return reference.$$typeof === CLIENT_REFERENCE_TAG;
276
- }
277
- function isServerReference(reference) {
278
- return reference.$$typeof === SERVER_REFERENCE_TAG;
279
- }
280
485
  function resolveClientReferenceMetadata(config, clientReference) {
281
486
  var modulePath = clientReference.$$id;
282
487
  var name = '';
@@ -302,12 +507,11 @@ function resolveClientReferenceMetadata(config, clientReference) {
302
507
  }
303
508
  }
304
509
 
305
- return {
306
- id: resolvedModuleData.id,
307
- chunks: resolvedModuleData.chunks,
308
- name: name,
309
- async: !!clientReference.$$async
310
- };
510
+ if (clientReference.$$async === true) {
511
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1];
512
+ } else {
513
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
514
+ }
311
515
  }
312
516
  function getServerReferenceId(config, serverReference) {
313
517
  return serverReference.$$id;
@@ -318,339 +522,357 @@ function getServerReferenceBoundArguments(config, serverReference) {
318
522
 
319
523
  var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
320
524
 
321
- var ReactDOMFlightServerDispatcher = {
525
+ var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
526
+ var previousDispatcher = ReactDOMCurrentDispatcher.current;
527
+ ReactDOMCurrentDispatcher.current = {
322
528
  prefetchDNS: prefetchDNS,
323
529
  preconnect: preconnect,
324
530
  preload: preload,
325
- preinit: preinit
531
+ preloadModule: preloadModule$1,
532
+ preinitStyle: preinitStyle,
533
+ preinitScript: preinitScript,
534
+ preinitModuleScript: preinitModuleScript
326
535
  };
327
536
 
328
- function prefetchDNS(href, options) {
329
- {
330
- if (typeof href === 'string') {
331
- var request = resolveRequest();
332
-
333
- if (request) {
334
- var hints = getHints(request);
335
- var key = 'D' + href;
336
-
337
- if (hints.has(key)) {
338
- // duplicate hint
339
- return;
340
- }
537
+ function prefetchDNS(href) {
538
+ if (typeof href === 'string' && href) {
539
+ var request = resolveRequest();
341
540
 
342
- hints.add(key);
541
+ if (request) {
542
+ var hints = getHints(request);
543
+ var key = 'D|' + href;
343
544
 
344
- if (options) {
345
- emitHint(request, 'D', [href, options]);
346
- } else {
347
- emitHint(request, 'D', href);
348
- }
545
+ if (hints.has(key)) {
546
+ // duplicate hint
547
+ return;
349
548
  }
549
+
550
+ hints.add(key);
551
+ emitHint(request, 'D', href);
552
+ } else {
553
+ previousDispatcher.prefetchDNS(href);
350
554
  }
351
555
  }
352
556
  }
353
557
 
354
- function preconnect(href, options) {
355
- {
356
- if (typeof href === 'string') {
357
- var request = resolveRequest();
558
+ function preconnect(href, crossOrigin) {
559
+ if (typeof href === 'string') {
560
+ var request = resolveRequest();
358
561
 
359
- if (request) {
360
- var hints = getHints(request);
361
- var crossOrigin = options == null || typeof options.crossOrigin !== 'string' ? null : options.crossOrigin === 'use-credentials' ? 'use-credentials' : '';
362
- var key = "C" + (crossOrigin === null ? 'null' : crossOrigin) + "|" + href;
562
+ if (request) {
563
+ var hints = getHints(request);
564
+ var key = "C|" + (crossOrigin == null ? 'null' : crossOrigin) + "|" + href;
363
565
 
364
- if (hints.has(key)) {
365
- // duplicate hint
366
- return;
367
- }
566
+ if (hints.has(key)) {
567
+ // duplicate hint
568
+ return;
569
+ }
368
570
 
369
- hints.add(key);
571
+ hints.add(key);
370
572
 
371
- if (options) {
372
- emitHint(request, 'C', [href, options]);
373
- } else {
374
- emitHint(request, 'C', href);
375
- }
573
+ if (typeof crossOrigin === 'string') {
574
+ emitHint(request, 'C', [href, crossOrigin]);
575
+ } else {
576
+ emitHint(request, 'C', href);
376
577
  }
578
+ } else {
579
+ previousDispatcher.preconnect(href, crossOrigin);
377
580
  }
378
581
  }
379
582
  }
380
583
 
381
- function preload(href, options) {
382
- {
383
- if (typeof href === 'string') {
384
- var request = resolveRequest();
584
+ function preload(href, as, options) {
585
+ if (typeof href === 'string') {
586
+ var request = resolveRequest();
385
587
 
386
- if (request) {
387
- var hints = getHints(request);
388
- var key = 'L' + href;
588
+ if (request) {
589
+ var hints = getHints(request);
590
+ var key = 'L';
389
591
 
390
- if (hints.has(key)) {
391
- // duplicate hint
392
- return;
393
- }
592
+ if (as === 'image' && options) {
593
+ key += getImagePreloadKey(href, options.imageSrcSet, options.imageSizes);
594
+ } else {
595
+ key += "[" + as + "]" + href;
596
+ }
597
+
598
+ if (hints.has(key)) {
599
+ // duplicate hint
600
+ return;
601
+ }
602
+
603
+ hints.add(key);
604
+ var trimmed = trimOptions(options);
394
605
 
395
- hints.add(key);
396
- emitHint(request, 'L', [href, options]);
606
+ if (trimmed) {
607
+ emitHint(request, 'L', [href, as, trimmed]);
608
+ } else {
609
+ emitHint(request, 'L', [href, as]);
397
610
  }
611
+ } else {
612
+ previousDispatcher.preload(href, as, options);
398
613
  }
399
614
  }
400
615
  }
401
616
 
402
- function preinit(href, options) {
403
- {
404
- if (typeof href === 'string') {
405
- var request = resolveRequest();
617
+ function preloadModule$1(href, options) {
618
+ if (typeof href === 'string') {
619
+ var request = resolveRequest();
406
620
 
407
- if (request) {
408
- var hints = getHints(request);
409
- var key = 'I' + href;
621
+ if (request) {
622
+ var hints = getHints(request);
623
+ var key = 'm|' + href;
410
624
 
411
- if (hints.has(key)) {
412
- // duplicate hint
413
- return;
414
- }
625
+ if (hints.has(key)) {
626
+ // duplicate hint
627
+ return;
628
+ }
415
629
 
416
- hints.add(key);
417
- emitHint(request, 'I', [href, options]);
630
+ hints.add(key);
631
+ var trimmed = trimOptions(options);
632
+
633
+ if (trimmed) {
634
+ return emitHint(request, 'm', [href, trimmed]);
635
+ } else {
636
+ return emitHint(request, 'm', href);
418
637
  }
638
+ } else {
639
+ previousDispatcher.preloadModule(href, options);
419
640
  }
420
641
  }
421
642
  }
422
643
 
423
- var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
424
- function prepareHostDispatcher() {
425
- ReactDOMCurrentDispatcher.current = ReactDOMFlightServerDispatcher;
426
- } // Used to distinguish these contexts from ones used in other renderers.
427
- function createHints() {
428
- return new Set();
429
- }
644
+ function preinitStyle(href, precedence, options) {
645
+ if (typeof href === 'string') {
646
+ var request = resolveRequest();
430
647
 
431
- var requestStorage = new async_hooks.AsyncLocalStorage();
648
+ if (request) {
649
+ var hints = getHints(request);
650
+ var key = 'S|' + href;
432
651
 
433
- // ATTENTION
434
- // When adding new symbols to this file,
435
- // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
436
- // The Symbol used to tag the ReactElement-like types.
437
- var REACT_ELEMENT_TYPE = Symbol.for('react.element');
438
- var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
439
- var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
440
- var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
441
- var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
442
- var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
443
- var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
444
- var REACT_MEMO_TYPE = Symbol.for('react.memo');
445
- var REACT_LAZY_TYPE = Symbol.for('react.lazy');
446
- var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
447
- var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
448
- var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
449
- var FAUX_ITERATOR_SYMBOL = '@@iterator';
450
- function getIteratorFn(maybeIterable) {
451
- if (maybeIterable === null || typeof maybeIterable !== 'object') {
452
- return null;
453
- }
652
+ if (hints.has(key)) {
653
+ // duplicate hint
654
+ return;
655
+ }
454
656
 
455
- var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
657
+ hints.add(key);
658
+ var trimmed = trimOptions(options);
456
659
 
457
- if (typeof maybeIterator === 'function') {
458
- return maybeIterator;
660
+ if (trimmed) {
661
+ return emitHint(request, 'S', [href, typeof precedence === 'string' ? precedence : 0, trimmed]);
662
+ } else if (typeof precedence === 'string') {
663
+ return emitHint(request, 'S', [href, precedence]);
664
+ } else {
665
+ return emitHint(request, 'S', href);
666
+ }
667
+ } else {
668
+ previousDispatcher.preinitStyle(href, precedence, options);
669
+ }
459
670
  }
460
-
461
- return null;
462
671
  }
463
672
 
464
- var rendererSigil;
673
+ function preinitScript(src, options) {
674
+ if (typeof src === 'string') {
675
+ var request = resolveRequest();
465
676
 
466
- {
467
- // Use this to detect multiple renderers using the same context
468
- rendererSigil = {};
469
- } // Used to store the parent path of all context overrides in a shared linked list.
470
- // Forming a reverse tree.
471
- // The structure of a context snapshot is an implementation of this file.
472
- // Currently, it's implemented as tracking the current active node.
677
+ if (request) {
678
+ var hints = getHints(request);
679
+ var key = 'X|' + src;
473
680
 
681
+ if (hints.has(key)) {
682
+ // duplicate hint
683
+ return;
684
+ }
474
685
 
475
- var rootContextSnapshot = null; // We assume that this runtime owns the "current" field on all ReactContext instances.
476
- // This global (actually thread local) state represents what state all those "current",
477
- // fields are currently in.
478
-
479
- var currentActiveSnapshot = null;
686
+ hints.add(key);
687
+ var trimmed = trimOptions(options);
480
688
 
481
- function popNode(prev) {
482
- {
483
- prev.context._currentValue = prev.parentValue;
689
+ if (trimmed) {
690
+ return emitHint(request, 'X', [src, trimmed]);
691
+ } else {
692
+ return emitHint(request, 'X', src);
693
+ }
694
+ } else {
695
+ previousDispatcher.preinitScript(src, options);
696
+ }
484
697
  }
485
698
  }
486
699
 
487
- function pushNode(next) {
488
- {
489
- next.context._currentValue = next.value;
490
- }
491
- }
700
+ function preinitModuleScript(src, options) {
701
+ if (typeof src === 'string') {
702
+ var request = resolveRequest();
492
703
 
493
- function popToNearestCommonAncestor(prev, next) {
494
- if (prev === next) ; else {
495
- popNode(prev);
496
- var parentPrev = prev.parent;
497
- var parentNext = next.parent;
704
+ if (request) {
705
+ var hints = getHints(request);
706
+ var key = 'M|' + src;
498
707
 
499
- if (parentPrev === null) {
500
- if (parentNext !== null) {
501
- throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
502
- }
503
- } else {
504
- if (parentNext === null) {
505
- throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
708
+ if (hints.has(key)) {
709
+ // duplicate hint
710
+ return;
506
711
  }
507
712
 
508
- popToNearestCommonAncestor(parentPrev, parentNext); // On the way back, we push the new ones that weren't common.
713
+ hints.add(key);
714
+ var trimmed = trimOptions(options);
509
715
 
510
- pushNode(next);
716
+ if (trimmed) {
717
+ return emitHint(request, 'M', [src, trimmed]);
718
+ } else {
719
+ return emitHint(request, 'M', src);
720
+ }
721
+ } else {
722
+ previousDispatcher.preinitModuleScript(src, options);
511
723
  }
512
724
  }
513
- }
725
+ } // Flight normally encodes undefined as a special character however for directive option
726
+ // arguments we don't want to send unnecessary keys and bloat the payload so we create a
727
+ // trimmed object which omits any keys with null or undefined values.
728
+ // This is only typesafe because these option objects have entirely optional fields where
729
+ // null and undefined represent the same thing as no property.
514
730
 
515
- function popAllPrevious(prev) {
516
- popNode(prev);
517
- var parentPrev = prev.parent;
518
731
 
519
- if (parentPrev !== null) {
520
- popAllPrevious(parentPrev);
521
- }
522
- }
523
-
524
- function pushAllNext(next) {
525
- var parentNext = next.parent;
732
+ function trimOptions(options) {
733
+ if (options == null) return null;
734
+ var hasProperties = false;
735
+ var trimmed = {};
526
736
 
527
- if (parentNext !== null) {
528
- pushAllNext(parentNext);
737
+ for (var key in options) {
738
+ if (options[key] != null) {
739
+ hasProperties = true;
740
+ trimmed[key] = options[key];
741
+ }
529
742
  }
530
743
 
531
- pushNode(next);
744
+ return hasProperties ? trimmed : null;
532
745
  }
533
746
 
534
- function popPreviousToCommonLevel(prev, next) {
535
- popNode(prev);
536
- var parentPrev = prev.parent;
747
+ function getImagePreloadKey(href, imageSrcSet, imageSizes) {
748
+ var uniquePart = '';
537
749
 
538
- if (parentPrev === null) {
539
- throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
540
- }
750
+ if (typeof imageSrcSet === 'string' && imageSrcSet !== '') {
751
+ uniquePart += '[' + imageSrcSet + ']';
541
752
 
542
- if (parentPrev.depth === next.depth) {
543
- // We found the same level. Now we just need to find a shared ancestor.
544
- popToNearestCommonAncestor(parentPrev, next);
753
+ if (typeof imageSizes === 'string') {
754
+ uniquePart += '[' + imageSizes + ']';
755
+ }
545
756
  } else {
546
- // We must still be deeper.
547
- popPreviousToCommonLevel(parentPrev, next);
757
+ uniquePart += '[][]' + href;
548
758
  }
759
+
760
+ return "[image]" + uniquePart;
549
761
  }
550
762
 
551
- function popNextToCommonLevel(prev, next) {
552
- var parentNext = next.parent;
763
+ // This module registers the host dispatcher so it needs to be imported
764
+ // small, smaller than how we encode undefined, and is unambiguous. We could use
765
+ // a different tuple structure to encode this instead but this makes the runtime
766
+ // cost cheaper by eliminating a type checks in more positions.
767
+ // prettier-ignore
553
768
 
554
- if (parentNext === null) {
555
- throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
556
- }
769
+ function createHints() {
770
+ return new Set();
771
+ }
557
772
 
558
- if (prev.depth === parentNext.depth) {
559
- // We found the same level. Now we just need to find a shared ancestor.
560
- popToNearestCommonAncestor(prev, parentNext);
561
- } else {
562
- // We must still be deeper.
563
- popNextToCommonLevel(prev, parentNext);
564
- }
565
-
566
- pushNode(next);
567
- } // Perform context switching to the new snapshot.
568
- // To make it cheap to read many contexts, while not suspending, we make the switch eagerly by
569
- // updating all the context's current values. That way reads, always just read the current value.
570
- // At the cost of updating contexts even if they're never read by this subtree.
571
-
572
-
573
- function switchContext(newSnapshot) {
574
- // The basic algorithm we need to do is to pop back any contexts that are no longer on the stack.
575
- // We also need to update any new contexts that are now on the stack with the deepest value.
576
- // The easiest way to update new contexts is to just reapply them in reverse order from the
577
- // perspective of the backpointers. To avoid allocating a lot when switching, we use the stack
578
- // for that. Therefore this algorithm is recursive.
579
- // 1) First we pop which ever snapshot tree was deepest. Popping old contexts as we go.
580
- // 2) Then we find the nearest common ancestor from there. Popping old contexts as we go.
581
- // 3) Then we reapply new contexts on the way back up the stack.
582
- var prev = currentActiveSnapshot;
583
- var next = newSnapshot;
584
-
585
- if (prev !== next) {
586
- if (prev === null) {
587
- // $FlowFixMe[incompatible-call]: This has to be non-null since it's not equal to prev.
588
- pushAllNext(next);
589
- } else if (next === null) {
590
- popAllPrevious(prev);
591
- } else if (prev.depth === next.depth) {
592
- popToNearestCommonAncestor(prev, next);
593
- } else if (prev.depth > next.depth) {
594
- popPreviousToCommonLevel(prev, next);
595
- } else {
596
- popNextToCommonLevel(prev, next);
597
- }
773
+ var supportsRequestStorage = true;
774
+ var requestStorage = new async_hooks.AsyncLocalStorage();
598
775
 
599
- currentActiveSnapshot = next;
600
- }
776
+ var TEMPORARY_REFERENCE_TAG = Symbol.for('react.temporary.reference'); // eslint-disable-next-line no-unused-vars
777
+
778
+ function isTemporaryReference(reference) {
779
+ return reference.$$typeof === TEMPORARY_REFERENCE_TAG;
780
+ }
781
+ function resolveTemporaryReferenceID(temporaryReference) {
782
+ return temporaryReference.$$id;
601
783
  }
602
- function pushProvider(context, nextValue) {
603
- var prevValue;
784
+ var proxyHandlers = {
785
+ get: function (target, name, receiver) {
786
+ switch (name) {
787
+ // These names are read by the Flight runtime if you end up using the exports object.
788
+ case '$$typeof':
789
+ // These names are a little too common. We should probably have a way to
790
+ // have the Flight runtime extract the inner target instead.
791
+ return target.$$typeof;
604
792
 
605
- {
606
- prevValue = context._currentValue;
607
- context._currentValue = nextValue;
793
+ case '$$id':
794
+ return target.$$id;
608
795
 
609
- {
610
- if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
611
- error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
612
- }
796
+ case '$$async':
797
+ return target.$$async;
798
+
799
+ case 'name':
800
+ return undefined;
801
+
802
+ case 'displayName':
803
+ return undefined;
804
+ // We need to special case this because createElement reads it if we pass this
805
+ // reference.
806
+
807
+ case 'defaultProps':
808
+ return undefined;
809
+ // Avoid this attempting to be serialized.
613
810
 
614
- context._currentRenderer = rendererSigil;
811
+ case 'toJSON':
812
+ return undefined;
813
+
814
+ case Symbol.toPrimitive:
815
+ // $FlowFixMe[prop-missing]
816
+ return Object.prototype[Symbol.toPrimitive];
817
+
818
+ case Symbol.toStringTag:
819
+ // $FlowFixMe[prop-missing]
820
+ return Object.prototype[Symbol.toStringTag];
821
+
822
+ case 'Provider':
823
+ 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.");
615
824
  }
616
- }
617
825
 
618
- var prevNode = currentActiveSnapshot;
619
- var newNode = {
620
- parent: prevNode,
621
- depth: prevNode === null ? 0 : prevNode.depth + 1,
622
- context: context,
623
- parentValue: prevValue,
624
- value: nextValue
625
- };
626
- currentActiveSnapshot = newNode;
627
- return newNode;
826
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
827
+ "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.');
828
+ },
829
+ set: function () {
830
+ throw new Error('Cannot assign to a temporary client reference from a server module.');
831
+ }
832
+ };
833
+ function createTemporaryReference(id) {
834
+ var reference = Object.defineProperties(function () {
835
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
836
+ "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.");
837
+ }, {
838
+ $$typeof: {
839
+ value: TEMPORARY_REFERENCE_TAG
840
+ },
841
+ $$id: {
842
+ value: id
843
+ }
844
+ });
845
+ return new Proxy(reference, proxyHandlers);
628
846
  }
629
- function popProvider() {
630
- var prevSnapshot = currentActiveSnapshot;
631
847
 
632
- if (prevSnapshot === null) {
633
- throw new Error('Tried to pop a Context at the root of the app. This is a bug in React.');
848
+ // ATTENTION
849
+ // When adding new symbols to this file,
850
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
851
+ // The Symbol used to tag the ReactElement-like types.
852
+ var REACT_ELEMENT_TYPE = Symbol.for('react.element');
853
+ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
854
+ var REACT_CONTEXT_TYPE = Symbol.for('react.context');
855
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
856
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
857
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
858
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
859
+ var REACT_LAZY_TYPE = Symbol.for('react.lazy');
860
+ var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
861
+ var REACT_POSTPONE_TYPE = Symbol.for('react.postpone');
862
+ var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
863
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
864
+ function getIteratorFn(maybeIterable) {
865
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
866
+ return null;
634
867
  }
635
868
 
636
- {
637
- var value = prevSnapshot.parentValue;
869
+ var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
638
870
 
639
- if (value === REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED) {
640
- prevSnapshot.context._currentValue = prevSnapshot.context._defaultValue;
641
- } else {
642
- prevSnapshot.context._currentValue = value;
643
- }
871
+ if (typeof maybeIterator === 'function') {
872
+ return maybeIterator;
644
873
  }
645
874
 
646
- return currentActiveSnapshot = prevSnapshot.parent;
647
- }
648
- function getActiveContext() {
649
- return currentActiveSnapshot;
650
- }
651
- function readContext$1(context) {
652
- var value = context._currentValue ;
653
- return value;
875
+ return null;
654
876
  }
655
877
 
656
878
  // Corresponds to ReactFiberWakeable and ReactFizzWakeable modules. Generally,
@@ -781,29 +1003,13 @@ function prepareToUseHooksForComponent(prevThenableState) {
781
1003
  thenableState = prevThenableState;
782
1004
  }
783
1005
  function getThenableStateAfterSuspending() {
784
- var state = thenableState;
1006
+ // If you use() to Suspend this should always exist but if you throw a Promise instead,
1007
+ // which is not really supported anymore, it will be empty. We use the empty set as a
1008
+ // marker to know if this was a replay of the same component or first attempt.
1009
+ var state = thenableState || createThenableState();
785
1010
  thenableState = null;
786
1011
  return state;
787
1012
  }
788
-
789
- function readContext(context) {
790
- {
791
- if (context.$$typeof !== REACT_SERVER_CONTEXT_TYPE) {
792
- if (isClientReference(context)) {
793
- error('Cannot read a Client Context from a Server Component.');
794
- } else {
795
- error('Only createServerContext is supported in Server Components.');
796
- }
797
- }
798
-
799
- if (currentRequest$1 === null) {
800
- 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().');
801
- }
802
- }
803
-
804
- return readContext$1(context);
805
- }
806
-
807
1013
  var HooksDispatcher = {
808
1014
  useMemo: function (nextCreate) {
809
1015
  return nextCreate();
@@ -814,8 +1020,8 @@ var HooksDispatcher = {
814
1020
  useDebugValue: function () {},
815
1021
  useDeferredValue: unsupportedHook,
816
1022
  useTransition: unsupportedHook,
817
- readContext: readContext,
818
- useContext: readContext,
1023
+ readContext: unsupportedContext,
1024
+ useContext: unsupportedContext,
819
1025
  useReducer: unsupportedHook,
820
1026
  useRef: unsupportedHook,
821
1027
  useState: unsupportedHook,
@@ -824,7 +1030,6 @@ var HooksDispatcher = {
824
1030
  useImperativeHandle: unsupportedHook,
825
1031
  useEffect: unsupportedHook,
826
1032
  useId: useId,
827
- useMutableSource: unsupportedHook,
828
1033
  useSyncExternalStore: unsupportedHook,
829
1034
  useCacheRefresh: function () {
830
1035
  return unsupportedRefresh;
@@ -849,6 +1054,10 @@ function unsupportedRefresh() {
849
1054
  throw new Error('Refreshing the cache is not supported in Server Components.');
850
1055
  }
851
1056
 
1057
+ function unsupportedContext() {
1058
+ throw new Error('Cannot read a Client Context from a Server Component.');
1059
+ }
1060
+
852
1061
  function useId() {
853
1062
  if (currentRequest$1 === null) {
854
1063
  throw new Error('useId can only be used while React is rendering');
@@ -874,20 +1083,22 @@ function use(usable) {
874
1083
  }
875
1084
 
876
1085
  return trackUsedThenable(thenableState, thenable, index);
877
- } else if (usable.$$typeof === REACT_SERVER_CONTEXT_TYPE) {
878
- var context = usable;
879
- return readContext(context);
1086
+ } else if (usable.$$typeof === REACT_CONTEXT_TYPE) {
1087
+ unsupportedContext();
880
1088
  }
881
1089
  }
882
1090
 
883
- {
884
- if (isClientReference(usable)) {
885
- error('Cannot use() an already resolved Client Reference.');
1091
+ if (isClientReference(usable)) {
1092
+ if (usable.value != null && usable.value.$$typeof === REACT_CONTEXT_TYPE) {
1093
+ // Show a more specific message since it's a common mistake.
1094
+ throw new Error('Cannot read a Client Context from a Server Component.');
1095
+ } else {
1096
+ throw new Error('Cannot use() an already resolved Client Reference.');
886
1097
  }
887
- } // eslint-disable-next-line react-internal/safe-string-coercion
888
-
889
-
890
- throw new Error('An unsupported type was passed to use(): ' + String(usable));
1098
+ } else {
1099
+ throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
1100
+ 'An unsupported type was passed to use(): ' + String(usable));
1101
+ }
891
1102
  }
892
1103
 
893
1104
  function createSignal() {
@@ -936,6 +1147,8 @@ function isArray(a) {
936
1147
  return isArrayImpl(a);
937
1148
  }
938
1149
 
1150
+ var getPrototypeOf = Object.getPrototypeOf;
1151
+
939
1152
  // in case they error.
940
1153
 
941
1154
  var jsxPropsParents = new WeakMap();
@@ -954,7 +1167,7 @@ function isObjectPrototype(object) {
954
1167
  // still just a plain simple object.
955
1168
 
956
1169
 
957
- if (Object.getPrototypeOf(object)) {
1170
+ if (getPrototypeOf(object)) {
958
1171
  return false;
959
1172
  }
960
1173
 
@@ -970,7 +1183,7 @@ function isObjectPrototype(object) {
970
1183
  }
971
1184
 
972
1185
  function isSimpleObject(object) {
973
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1186
+ if (!isObjectPrototype(getPrototypeOf(object))) {
974
1187
  return false;
975
1188
  }
976
1189
 
@@ -1023,6 +1236,10 @@ function describeValueForErrorMessage(value) {
1023
1236
  return '[...]';
1024
1237
  }
1025
1238
 
1239
+ if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
1240
+ return describeClientReference();
1241
+ }
1242
+
1026
1243
  var name = objectName(value);
1027
1244
 
1028
1245
  if (name === 'Object') {
@@ -1033,7 +1250,15 @@ function describeValueForErrorMessage(value) {
1033
1250
  }
1034
1251
 
1035
1252
  case 'function':
1036
- return 'function';
1253
+ {
1254
+ if (value.$$typeof === CLIENT_REFERENCE_TAG) {
1255
+ return describeClientReference();
1256
+ }
1257
+
1258
+ var _name = value.displayName || value.name;
1259
+
1260
+ return _name ? 'function ' + _name : 'function';
1261
+ }
1037
1262
 
1038
1263
  default:
1039
1264
  // eslint-disable-next-line react-internal/safe-string-coercion
@@ -1079,6 +1304,12 @@ function describeElementType(type) {
1079
1304
  return '';
1080
1305
  }
1081
1306
 
1307
+ var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
1308
+
1309
+ function describeClientReference(ref) {
1310
+ return 'client';
1311
+ }
1312
+
1082
1313
  function describeObjectForErrorMessage(objectOrArray, expandedName) {
1083
1314
  var objKind = objectName(objectOrArray);
1084
1315
 
@@ -1104,7 +1335,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1104
1335
  if (typeof value === 'string') {
1105
1336
  substr = value;
1106
1337
  } else if (typeof value === 'object' && value !== null) {
1107
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1108
1338
  substr = '{' + describeObjectForErrorMessage(value) + '}';
1109
1339
  } else {
1110
1340
  substr = '{' + describeValueForErrorMessage(value) + '}';
@@ -1137,7 +1367,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1137
1367
  var _substr = void 0;
1138
1368
 
1139
1369
  if (typeof _value === 'object' && _value !== null) {
1140
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1141
1370
  _substr = describeObjectForErrorMessage(_value);
1142
1371
  } else {
1143
1372
  _substr = describeValueForErrorMessage(_value);
@@ -1159,6 +1388,8 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1159
1388
  } else {
1160
1389
  if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1161
1390
  str = '<' + describeElementType(objectOrArray.type) + '/>';
1391
+ } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
1392
+ return describeClientReference();
1162
1393
  } else if (jsxPropsParents.has(objectOrArray)) {
1163
1394
  // Print JSX
1164
1395
  var _type = jsxPropsParents.get(objectOrArray);
@@ -1176,7 +1407,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1176
1407
  var _substr2 = void 0;
1177
1408
 
1178
1409
  if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1179
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1180
1410
  _substr2 = describeObjectForErrorMessage(_value2);
1181
1411
  } else {
1182
1412
  _substr2 = describeValueForErrorMessage(_value2);
@@ -1210,20 +1440,19 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1210
1440
  str += ', ';
1211
1441
  }
1212
1442
 
1213
- var _name = _names[_i3];
1214
- str += describeKeyForErrorMessage(_name) + ': ';
1215
- var _value3 = _object[_name];
1443
+ var _name2 = _names[_i3];
1444
+ str += describeKeyForErrorMessage(_name2) + ': ';
1445
+ var _value3 = _object[_name2];
1216
1446
 
1217
1447
  var _substr3 = void 0;
1218
1448
 
1219
1449
  if (typeof _value3 === 'object' && _value3 !== null) {
1220
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1221
1450
  _substr3 = describeObjectForErrorMessage(_value3);
1222
1451
  } else {
1223
1452
  _substr3 = describeValueForErrorMessage(_value3);
1224
1453
  }
1225
1454
 
1226
- if (_name === expandedName) {
1455
+ if (_name2 === expandedName) {
1227
1456
  start = str.length;
1228
1457
  length = _substr3.length;
1229
1458
  str += _substr3;
@@ -1250,41 +1479,44 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1250
1479
  return '\n ' + str;
1251
1480
  }
1252
1481
 
1253
- var ContextRegistry = ReactSharedInternals.ContextRegistry;
1254
- function getOrCreateServerContext(globalName) {
1255
- if (!ContextRegistry[globalName]) {
1256
- ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
1257
- REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
1258
- }
1482
+ var ReactSharedServerInternals = // $FlowFixMe: It's defined in the one we resolve to.
1483
+ React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1259
1484
 
1260
- return ContextRegistry[globalName];
1485
+ if (!ReactSharedServerInternals) {
1486
+ 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.');
1261
1487
  }
1262
1488
 
1489
+ var ObjectPrototype = Object.prototype;
1490
+ var stringify = JSON.stringify; // Serializable values
1263
1491
  // Thenable<ReactClientValue>
1264
1492
 
1265
1493
  var PENDING$1 = 0;
1266
1494
  var COMPLETED = 1;
1267
1495
  var ABORTED = 3;
1268
1496
  var ERRORED$1 = 4;
1497
+ var ReactCurrentCache = ReactSharedServerInternals.ReactCurrentCache;
1269
1498
  var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1270
- var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1271
1499
 
1272
1500
  function defaultErrorHandler(error) {
1273
1501
  console['error'](error); // Don't transform to our wrapper
1274
1502
  }
1275
1503
 
1504
+ function defaultPostponeHandler(reason) {// Noop
1505
+ }
1506
+
1276
1507
  var OPEN = 0;
1277
1508
  var CLOSING = 1;
1278
1509
  var CLOSED = 2;
1279
- function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
1510
+ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName) {
1280
1511
  if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1281
1512
  throw new Error('Currently React only supports one RSC renderer at a time.');
1282
1513
  }
1283
1514
 
1284
- prepareHostDispatcher();
1285
1515
  ReactCurrentCache.current = DefaultCacheDispatcher;
1286
1516
  var abortSet = new Set();
1287
1517
  var pingedTasks = [];
1518
+ var cleanupQueue = [];
1519
+
1288
1520
  var hints = createHints();
1289
1521
  var request = {
1290
1522
  status: OPEN,
@@ -1300,23 +1532,24 @@ function createRequest(model, bundlerConfig, onError, context, identifierPrefix)
1300
1532
  pingedTasks: pingedTasks,
1301
1533
  completedImportChunks: [],
1302
1534
  completedHintChunks: [],
1303
- completedJSONChunks: [],
1535
+ completedRegularChunks: [],
1304
1536
  completedErrorChunks: [],
1305
1537
  writtenSymbols: new Map(),
1306
1538
  writtenClientReferences: new Map(),
1307
1539
  writtenServerReferences: new Map(),
1308
- writtenProviders: new Map(),
1540
+ writtenObjects: new WeakMap(),
1309
1541
  identifierPrefix: identifierPrefix || '',
1310
1542
  identifierCount: 1,
1543
+ taintCleanupQueue: cleanupQueue,
1311
1544
  onError: onError === undefined ? defaultErrorHandler : onError,
1312
- // $FlowFixMe[missing-this-annot]
1313
- toJSON: function (key, value) {
1314
- return resolveModelToJSON(request, this, key, value);
1315
- }
1545
+ onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone
1316
1546
  };
1317
- request.pendingChunks++;
1318
- var rootContext = createRootContext(context);
1319
- var rootTask = createTask(request, model, rootContext, abortSet);
1547
+
1548
+ {
1549
+ request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1550
+ }
1551
+
1552
+ var rootTask = createTask(request, model, null, false, abortSet);
1320
1553
  pingedTasks.push(rootTask);
1321
1554
  return request;
1322
1555
  }
@@ -1332,15 +1565,18 @@ function resolveRequest() {
1332
1565
  return null;
1333
1566
  }
1334
1567
 
1335
- function createRootContext(reqContext) {
1336
- return importServerContexts(reqContext);
1337
- }
1568
+ function serializeThenable(request, task, thenable) {
1569
+ var newTask = createTask(request, null, task.keyPath, // the server component sequence continues through Promise-as-a-child.
1570
+ task.implicitSlot, request.abortableTasks);
1338
1571
 
1339
- var POP = {};
1572
+ {
1573
+ // If this came from Flight, forward any debug info into this new row.
1574
+ var debugInfo = thenable._debugInfo;
1340
1575
 
1341
- function serializeThenable(request, thenable) {
1342
- request.pendingChunks++;
1343
- var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1576
+ if (debugInfo) {
1577
+ forwardDebugInfo(request, newTask.id, debugInfo);
1578
+ }
1579
+ }
1344
1580
 
1345
1581
  switch (thenable.status) {
1346
1582
  case 'fulfilled':
@@ -1354,14 +1590,10 @@ function serializeThenable(request, thenable) {
1354
1590
  case 'rejected':
1355
1591
  {
1356
1592
  var x = thenable.reason;
1357
- var digest = logRecoverableError(request, x);
1358
1593
 
1359
1594
  {
1360
- var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1361
- message = _getErrorMessageAndSt.message,
1362
- stack = _getErrorMessageAndSt.stack;
1363
-
1364
- emitErrorChunkDev(request, newTask.id, digest, message, stack);
1595
+ var digest = logRecoverableError(request, x);
1596
+ emitErrorChunk(request, newTask.id, digest, x);
1365
1597
  }
1366
1598
 
1367
1599
  return newTask.id;
@@ -1399,18 +1631,16 @@ function serializeThenable(request, thenable) {
1399
1631
  newTask.model = value;
1400
1632
  pingTask(request, newTask);
1401
1633
  }, function (reason) {
1402
- newTask.status = ERRORED$1; // TODO: We should ideally do this inside performWork so it's scheduled
1403
-
1404
- var digest = logRecoverableError(request, reason);
1405
-
1406
1634
  {
1407
- var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1408
- _message = _getErrorMessageAndSt2.message,
1409
- _stack = _getErrorMessageAndSt2.stack;
1635
+ newTask.status = ERRORED$1;
1636
+
1637
+ var _digest = logRecoverableError(request, reason);
1410
1638
 
1411
- emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1639
+ emitErrorChunk(request, newTask.id, _digest, reason);
1412
1640
  }
1413
1641
 
1642
+ request.abortableTasks.delete(newTask);
1643
+
1414
1644
  if (request.destination !== null) {
1415
1645
  flushCompletedChunks(request, request.destination);
1416
1646
  }
@@ -1482,14 +1712,136 @@ function createLazyWrapperAroundWakeable(wakeable) {
1482
1712
  _payload: thenable,
1483
1713
  _init: readThenable
1484
1714
  };
1715
+
1716
+ {
1717
+ // If this came from React, transfer the debug info.
1718
+ lazyType._debugInfo = thenable._debugInfo || [];
1719
+ }
1720
+
1485
1721
  return lazyType;
1486
1722
  }
1487
1723
 
1488
- function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1724
+ function renderFunctionComponent(request, task, key, Component, props) {
1725
+ // Reset the task's thenable state before continuing, so that if a later
1726
+ // component suspends we can reuse the same task object. If the same
1727
+ // component suspends again, the thenable state will be restored.
1728
+ var prevThenableState = task.thenableState;
1729
+ task.thenableState = null;
1730
+
1731
+ {
1732
+ if (debugID === null) {
1733
+ // We don't have a chunk to assign debug info. We need to outline this
1734
+ // component to assign it an ID.
1735
+ return outlineTask(request, task);
1736
+ } else if (prevThenableState !== null) ; else {
1737
+ // This is a new component in the same task so we can emit more debug info.
1738
+ var componentName = Component.displayName || Component.name || '';
1739
+ request.pendingChunks++;
1740
+ emitDebugChunk(request, debugID, {
1741
+ name: componentName,
1742
+ env: request.environmentName
1743
+ });
1744
+ }
1745
+ }
1746
+
1747
+ prepareToUseHooksForComponent(prevThenableState); // The secondArg is always undefined in Server Components since refs error early.
1748
+
1749
+ var secondArg = undefined;
1750
+ var result = Component(props, secondArg);
1751
+
1752
+ if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1753
+ // When the return value is in children position we can resolve it immediately,
1754
+ // to its value without a wrapper if it's synchronously available.
1755
+ var thenable = result;
1756
+
1757
+ if (thenable.status === 'fulfilled') {
1758
+ return thenable.value;
1759
+ } // TODO: Once we accept Promises as children on the client, we can just return
1760
+ // the thenable here.
1761
+
1762
+
1763
+ result = createLazyWrapperAroundWakeable(result);
1764
+ } // Track this element's key on the Server Component on the keyPath context..
1765
+
1766
+
1767
+ var prevKeyPath = task.keyPath;
1768
+ var prevImplicitSlot = task.implicitSlot;
1769
+
1770
+ if (key !== null) {
1771
+ // Append the key to the path. Technically a null key should really add the child
1772
+ // index. We don't do that to hold the payload small and implementation simple.
1773
+ task.keyPath = prevKeyPath === null ? key : prevKeyPath + ',' + key;
1774
+ } else if (prevKeyPath === null) {
1775
+ // This sequence of Server Components has no keys. This means that it was rendered
1776
+ // in a slot that needs to assign an implicit key. Even if children below have
1777
+ // explicit keys, they should not be used for the outer most key since it might
1778
+ // collide with other slots in that set.
1779
+ task.implicitSlot = true;
1780
+ }
1781
+
1782
+ var json = renderModelDestructive(request, task, emptyRoot, '', result);
1783
+ task.keyPath = prevKeyPath;
1784
+ task.implicitSlot = prevImplicitSlot;
1785
+ return json;
1786
+ }
1787
+
1788
+ function renderFragment(request, task, children) {
1789
+ {
1790
+ var debugInfo = children._debugInfo;
1791
+
1792
+ if (debugInfo) {
1793
+ // If this came from Flight, forward any debug info into this new row.
1794
+ if (debugID === null) {
1795
+ // We don't have a chunk to assign debug info. We need to outline this
1796
+ // component to assign it an ID.
1797
+ return outlineTask(request, task);
1798
+ } else {
1799
+ // Forward any debug info we have the first time we see it.
1800
+ // We do this after init so that we have received all the debug info
1801
+ // from the server by the time we emit it.
1802
+ forwardDebugInfo(request, debugID, debugInfo);
1803
+ }
1804
+ }
1805
+ }
1806
+
1807
+ {
1808
+ return children;
1809
+ }
1810
+ }
1811
+
1812
+ function renderClientElement(task, type, key, props) {
1813
+ {
1814
+ return [REACT_ELEMENT_TYPE, type, key, props];
1815
+ } // We prepend the terminal client element that actually gets serialized with
1816
+ } // The chunk ID we're currently rendering that we can assign debug data to.
1817
+
1818
+
1819
+ var debugID = null;
1820
+
1821
+ function outlineTask(request, task) {
1822
+ var newTask = createTask(request, task.model, // the currently rendering element
1823
+ task.keyPath, // unlike outlineModel this one carries along context
1824
+ task.implicitSlot, request.abortableTasks);
1825
+ retryTask(request, newTask);
1826
+
1827
+ if (newTask.status === COMPLETED) {
1828
+ // We completed synchronously so we can refer to this by reference. This
1829
+ // makes it behaves the same as prod during deserialization.
1830
+ return serializeByValueID(newTask.id);
1831
+ } // This didn't complete synchronously so it wouldn't have even if we didn't
1832
+ // outline it, so this would reduce to a lazy reference even in prod.
1833
+
1834
+
1835
+ return serializeLazyID(newTask.id);
1836
+ }
1837
+
1838
+ function renderElement(request, task, type, key, ref, props) {
1489
1839
  if (ref !== null && ref !== undefined) {
1490
1840
  // When the ref moves to the regular props object this will implicitly
1491
1841
  // throw for functions. We could probably relax it to a DEV warning for other
1492
1842
  // cases.
1843
+ // TODO: `ref` is now just a prop when `enableRefAsProp` is on. Should we
1844
+ // do what the above comment says?
1493
1845
  throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1494
1846
  }
1495
1847
 
@@ -1502,49 +1854,38 @@ function attemptResolveElement(request, type, key, ref, props, prevThenableState
1502
1854
  }
1503
1855
 
1504
1856
  if (typeof type === 'function') {
1505
- if (isClientReference(type)) {
1857
+ if (isClientReference(type) || isTemporaryReference(type)) {
1506
1858
  // This is a reference to a Client Component.
1507
- return [REACT_ELEMENT_TYPE, type, key, props];
1508
- } // This is a server-side component.
1859
+ return renderClientElement(task, type, key, props);
1860
+ } // This is a Server Component.
1509
1861
 
1510
1862
 
1511
- prepareToUseHooksForComponent(prevThenableState);
1512
- var result = type(props);
1513
-
1514
- if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1515
- // When the return value is in children position we can resolve it immediately,
1516
- // to its value without a wrapper if it's synchronously available.
1517
- var thenable = result;
1518
-
1519
- if (thenable.status === 'fulfilled') {
1520
- return thenable.value;
1521
- } // TODO: Once we accept Promises as children on the client, we can just return
1522
- // the thenable here.
1523
-
1524
-
1525
- return createLazyWrapperAroundWakeable(result);
1526
- }
1527
-
1528
- return result;
1863
+ return renderFunctionComponent(request, task, key, type, props);
1529
1864
  } else if (typeof type === 'string') {
1530
1865
  // This is a host element. E.g. HTML.
1531
- return [REACT_ELEMENT_TYPE, type, key, props];
1866
+ return renderClientElement(task, type, key, props);
1532
1867
  } else if (typeof type === 'symbol') {
1533
- if (type === REACT_FRAGMENT_TYPE) {
1868
+ if (type === REACT_FRAGMENT_TYPE && key === null) {
1534
1869
  // For key-less fragments, we add a small optimization to avoid serializing
1535
1870
  // it as a wrapper.
1536
- // TODO: If a key is specified, we should propagate its key to any children.
1537
- // Same as if a Server Component has a key.
1538
- return props.children;
1871
+ var prevImplicitSlot = task.implicitSlot;
1872
+
1873
+ if (task.keyPath === null) {
1874
+ task.implicitSlot = true;
1875
+ }
1876
+
1877
+ var json = renderModelDestructive(request, task, emptyRoot, '', props.children);
1878
+ task.implicitSlot = prevImplicitSlot;
1879
+ return json;
1539
1880
  } // This might be a built-in React component. We'll let the client decide.
1540
1881
  // Any built-in works as long as its props are serializable.
1541
1882
 
1542
1883
 
1543
- return [REACT_ELEMENT_TYPE, type, key, props];
1884
+ return renderClientElement(task, type, key, props);
1544
1885
  } else if (type != null && typeof type === 'object') {
1545
1886
  if (isClientReference(type)) {
1546
1887
  // This is a reference to a Client Component.
1547
- return [REACT_ELEMENT_TYPE, type, key, props];
1888
+ return renderClientElement(task, type, key, props);
1548
1889
  }
1549
1890
 
1550
1891
  switch (type.$$typeof) {
@@ -1553,45 +1894,17 @@ function attemptResolveElement(request, type, key, ref, props, prevThenableState
1553
1894
  var payload = type._payload;
1554
1895
  var init = type._init;
1555
1896
  var wrappedType = init(payload);
1556
- return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1897
+ return renderElement(request, task, wrappedType, key, ref, props);
1557
1898
  }
1558
1899
 
1559
1900
  case REACT_FORWARD_REF_TYPE:
1560
1901
  {
1561
- var render = type.render;
1562
- prepareToUseHooksForComponent(prevThenableState);
1563
- return render(props, undefined);
1902
+ return renderFunctionComponent(request, task, key, type.render, props);
1564
1903
  }
1565
1904
 
1566
1905
  case REACT_MEMO_TYPE:
1567
1906
  {
1568
- return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1569
- }
1570
-
1571
- case REACT_PROVIDER_TYPE:
1572
- {
1573
- pushProvider(type._context, props.value);
1574
-
1575
- {
1576
- var extraKeys = Object.keys(props).filter(function (value) {
1577
- if (value === 'children' || value === 'value') {
1578
- return false;
1579
- }
1580
-
1581
- return true;
1582
- });
1583
-
1584
- if (extraKeys.length !== 0) {
1585
- error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1586
- }
1587
- }
1588
-
1589
- return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
1590
- {
1591
- value: props.value,
1592
- children: props.children,
1593
- __pop: POP
1594
- }];
1907
+ return renderElement(request, task, type.type, key, ref, props);
1595
1908
  }
1596
1909
  }
1597
1910
  }
@@ -1611,16 +1924,51 @@ function pingTask(request, task) {
1611
1924
  }
1612
1925
  }
1613
1926
 
1614
- function createTask(request, model, context, abortSet) {
1927
+ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1928
+ request.pendingChunks++;
1615
1929
  var id = request.nextChunkId++;
1930
+
1931
+ if (typeof model === 'object' && model !== null) {
1932
+ // If we're about to write this into a new task we can assign it an ID early so that
1933
+ // any other references can refer to the value we're about to write.
1934
+ {
1935
+ request.writtenObjects.set(model, id);
1936
+ }
1937
+ }
1938
+
1616
1939
  var task = {
1617
1940
  id: id,
1618
1941
  status: PENDING$1,
1619
1942
  model: model,
1620
- context: context,
1943
+ keyPath: keyPath,
1944
+ implicitSlot: implicitSlot,
1621
1945
  ping: function () {
1622
1946
  return pingTask(request, task);
1623
1947
  },
1948
+ toJSON: function (parentPropertyName, value) {
1949
+ var parent = this; // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
1950
+
1951
+ {
1952
+ // $FlowFixMe[incompatible-use]
1953
+ var originalValue = parent[parentPropertyName];
1954
+
1955
+ if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1956
+ if (objectName(originalValue) !== 'Object') {
1957
+ var jsxParentType = jsxChildrenParents.get(parent);
1958
+
1959
+ if (typeof jsxParentType === 'string') {
1960
+ error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, parentPropertyName));
1961
+ } else {
1962
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, parentPropertyName));
1963
+ }
1964
+ } else {
1965
+ 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));
1966
+ }
1967
+ }
1968
+ }
1969
+
1970
+ return renderModel(request, task, parent, parentPropertyName, value);
1971
+ },
1624
1972
  thenableState: null
1625
1973
  };
1626
1974
  abortSet.add(task);
@@ -1643,12 +1991,12 @@ function serializeServerReferenceID(id) {
1643
1991
  return '$F' + id.toString(16);
1644
1992
  }
1645
1993
 
1646
- function serializeSymbolReference(name) {
1647
- return '$S' + name;
1994
+ function serializeTemporaryReferenceID(id) {
1995
+ return '$T' + id;
1648
1996
  }
1649
1997
 
1650
- function serializeProviderReference(name) {
1651
- return '$P' + name;
1998
+ function serializeSymbolReference(name) {
1999
+ return '$S' + name;
1652
2000
  }
1653
2001
 
1654
2002
  function serializeNumber(number) {
@@ -1683,13 +2031,23 @@ function serializeBigInt(n) {
1683
2031
  return '$n' + n.toString(10);
1684
2032
  }
1685
2033
 
1686
- function serializeClientReference(request, parent, key, clientReference) {
2034
+ function serializeRowHeader(tag, id) {
2035
+ return id.toString(16) + ':' + tag;
2036
+ }
2037
+
2038
+ function encodeReferenceChunk(request, id, reference) {
2039
+ var json = stringify(reference);
2040
+ var row = id.toString(16) + ':' + json + '\n';
2041
+ return stringToChunk(row);
2042
+ }
2043
+
2044
+ function serializeClientReference(request, parent, parentPropertyName, clientReference) {
1687
2045
  var clientReferenceKey = getClientReferenceKey(clientReference);
1688
2046
  var writtenClientReferences = request.writtenClientReferences;
1689
2047
  var existingId = writtenClientReferences.get(clientReferenceKey);
1690
2048
 
1691
2049
  if (existingId !== undefined) {
1692
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
2050
+ if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1693
2051
  // If we're encoding the "type" of an element, we can refer
1694
2052
  // to that by a lazy reference instead of directly since React
1695
2053
  // knows how to deal with lazy values. This lets us suspend
@@ -1708,7 +2066,7 @@ function serializeClientReference(request, parent, key, clientReference) {
1708
2066
  emitImportChunk(request, importId, clientReferenceMetadata);
1709
2067
  writtenClientReferences.set(clientReferenceKey, importId);
1710
2068
 
1711
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
2069
+ if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1712
2070
  // If we're encoding the "type" of an element, we can refer
1713
2071
  // to that by a lazy reference instead of directly since React
1714
2072
  // knows how to deal with lazy values. This lets us suspend
@@ -1722,20 +2080,20 @@ function serializeClientReference(request, parent, key, clientReference) {
1722
2080
  request.pendingChunks++;
1723
2081
  var errorId = request.nextChunkId++;
1724
2082
  var digest = logRecoverableError(request, x);
1725
-
1726
- {
1727
- var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1728
- message = _getErrorMessageAndSt3.message,
1729
- stack = _getErrorMessageAndSt3.stack;
1730
-
1731
- emitErrorChunkDev(request, errorId, digest, message, stack);
1732
- }
1733
-
2083
+ emitErrorChunk(request, errorId, digest, x);
1734
2084
  return serializeByValueID(errorId);
1735
2085
  }
1736
2086
  }
1737
2087
 
1738
- function serializeServerReference(request, parent, key, serverReference) {
2088
+ function outlineModel(request, value) {
2089
+ var newTask = createTask(request, value, null, // The way we use outlining is for reusing an object.
2090
+ false, // It makes no sense for that use case to be contextual.
2091
+ request.abortableTasks);
2092
+ retryTask(request, newTask);
2093
+ return newTask.id;
2094
+ }
2095
+
2096
+ function serializeServerReference(request, serverReference) {
1739
2097
  var writtenServerReferences = request.writtenServerReferences;
1740
2098
  var existingId = writtenServerReferences.get(serverReference);
1741
2099
 
@@ -1748,15 +2106,69 @@ function serializeServerReference(request, parent, key, serverReference) {
1748
2106
  id: getServerReferenceId(request.bundlerConfig, serverReference),
1749
2107
  bound: bound ? Promise.resolve(bound) : null
1750
2108
  };
1751
- request.pendingChunks++;
1752
- var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1753
-
1754
- var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1755
- request.completedJSONChunks.push(processedChunk);
2109
+ var metadataId = outlineModel(request, serverReferenceMetadata);
1756
2110
  writtenServerReferences.set(serverReference, metadataId);
1757
2111
  return serializeServerReferenceID(metadataId);
1758
2112
  }
1759
2113
 
2114
+ function serializeTemporaryReference(request, temporaryReference) {
2115
+ var id = resolveTemporaryReferenceID(temporaryReference);
2116
+ return serializeTemporaryReferenceID(id);
2117
+ }
2118
+
2119
+ function serializeLargeTextString(request, text) {
2120
+ request.pendingChunks += 2;
2121
+ var textId = request.nextChunkId++;
2122
+ var textChunk = stringToChunk(text);
2123
+ var binaryLength = byteLengthOfChunk(textChunk);
2124
+ var row = textId.toString(16) + ':T' + binaryLength.toString(16) + ',';
2125
+ var headerChunk = stringToChunk(row);
2126
+ request.completedRegularChunks.push(headerChunk, textChunk);
2127
+ return serializeByValueID(textId);
2128
+ }
2129
+
2130
+ function serializeMap(request, map) {
2131
+ var entries = Array.from(map);
2132
+
2133
+ for (var i = 0; i < entries.length; i++) {
2134
+ var key = entries[i][0];
2135
+
2136
+ if (typeof key === 'object' && key !== null) {
2137
+ var writtenObjects = request.writtenObjects;
2138
+ var existingId = writtenObjects.get(key);
2139
+
2140
+ if (existingId === undefined) {
2141
+ // Mark all object keys as seen so that they're always outlined.
2142
+ writtenObjects.set(key, -1);
2143
+ }
2144
+ }
2145
+ }
2146
+
2147
+ var id = outlineModel(request, entries);
2148
+ return '$Q' + id.toString(16);
2149
+ }
2150
+
2151
+ function serializeSet(request, set) {
2152
+ var entries = Array.from(set);
2153
+
2154
+ for (var i = 0; i < entries.length; i++) {
2155
+ var key = entries[i];
2156
+
2157
+ if (typeof key === 'object' && key !== null) {
2158
+ var writtenObjects = request.writtenObjects;
2159
+ var existingId = writtenObjects.get(key);
2160
+
2161
+ if (existingId === undefined) {
2162
+ // Mark all object keys as seen so that they're always outlined.
2163
+ writtenObjects.set(key, -1);
2164
+ }
2165
+ }
2166
+ }
2167
+
2168
+ var id = outlineModel(request, entries);
2169
+ return '$W' + id.toString(16);
2170
+ }
2171
+
1760
2172
  function escapeStringValue(value) {
1761
2173
  if (value[0] === '$') {
1762
2174
  // We need to escape $ prefixed strings since we use those to encode
@@ -1767,166 +2179,262 @@ function escapeStringValue(value) {
1767
2179
  }
1768
2180
  }
1769
2181
 
1770
- var insideContextProps = null;
1771
- var isInsideContextValue = false;
1772
- function resolveModelToJSON(request, parent, key, value) {
1773
- // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
1774
- {
1775
- // $FlowFixMe[incompatible-use]
1776
- var originalValue = parent[key];
2182
+ var modelRoot = false;
1777
2183
 
1778
- if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1779
- if (objectName(originalValue) !== 'Object') {
1780
- var jsxParentType = jsxChildrenParents.get(parent);
2184
+ function renderModel(request, task, parent, key, value) {
2185
+ var prevKeyPath = task.keyPath;
2186
+ var prevImplicitSlot = task.implicitSlot;
1781
2187
 
1782
- if (typeof jsxParentType === 'string') {
1783
- error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
1784
- } else {
1785
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
2188
+ try {
2189
+ return renderModelDestructive(request, task, parent, key, value);
2190
+ } catch (thrownValue) {
2191
+ var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2192
+ // reasons, the rest of the Suspense implementation expects the thrown
2193
+ // value to be a thenable, because before `use` existed that was the
2194
+ // (unstable) API for suspending. This implementation detail can change
2195
+ // later, once we deprecate the old API in favor of `use`.
2196
+ getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
2197
+ // to a lazy reference, so that it doesn't error the parent.
2198
+
2199
+ var model = task.model;
2200
+ var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2201
+
2202
+ if (typeof x === 'object' && x !== null) {
2203
+ // $FlowFixMe[method-unbinding]
2204
+ if (typeof x.then === 'function') {
2205
+ // Something suspended, we'll need to create a new task and resolve it later.
2206
+ var newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
2207
+ var ping = newTask.ping;
2208
+ x.then(ping, ping);
2209
+ newTask.thenableState = getThenableStateAfterSuspending(); // Restore the context. We assume that this will be restored by the inner
2210
+ // functions in case nothing throws so we don't use "finally" here.
2211
+
2212
+ task.keyPath = prevKeyPath;
2213
+ task.implicitSlot = prevImplicitSlot;
2214
+
2215
+ if (wasReactNode) {
2216
+ return serializeLazyID(newTask.id);
1786
2217
  }
1787
- } else {
1788
- 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));
2218
+
2219
+ return serializeByValueID(newTask.id);
1789
2220
  }
1790
- }
1791
- } // Special Symbols
2221
+ } // Restore the context. We assume that this will be restored by the inner
2222
+ // functions in case nothing throws so we don't use "finally" here.
1792
2223
 
1793
2224
 
1794
- switch (value) {
1795
- case REACT_ELEMENT_TYPE:
1796
- return '$';
1797
- }
2225
+ task.keyPath = prevKeyPath;
2226
+ task.implicitSlot = prevImplicitSlot;
1798
2227
 
1799
- {
1800
- if (parent[0] === REACT_ELEMENT_TYPE && parent[1] && parent[1].$$typeof === REACT_PROVIDER_TYPE && key === '3') {
1801
- insideContextProps = value;
1802
- } else if (insideContextProps === parent && key === 'value') {
1803
- isInsideContextValue = true;
1804
- } else if (insideContextProps === parent && key === 'children') {
1805
- isInsideContextValue = false;
1806
- }
1807
- } // Resolve Server Components.
2228
+ if (wasReactNode) {
2229
+ // Something errored. We'll still send everything we have up until this point.
2230
+ // We'll replace this element with a lazy reference that throws on the client
2231
+ // once it gets rendered.
2232
+ request.pendingChunks++;
2233
+ var errorId = request.nextChunkId++;
2234
+ var digest = logRecoverableError(request, x);
2235
+ emitErrorChunk(request, errorId, digest, x);
2236
+ return serializeLazyID(errorId);
2237
+ } // Something errored but it was not in a React Node. There's no need to serialize
2238
+ // it by value because it'll just error the whole parent row anyway so we can
2239
+ // just stop any siblings and error the whole parent row.
1808
2240
 
1809
2241
 
1810
- while (typeof value === 'object' && value !== null && (value.$$typeof === REACT_ELEMENT_TYPE || value.$$typeof === REACT_LAZY_TYPE)) {
1811
- {
1812
- if (isInsideContextValue) {
1813
- error('React elements are not allowed in ServerContext');
1814
- }
1815
- }
2242
+ throw x;
2243
+ }
2244
+ }
1816
2245
 
1817
- try {
1818
- switch (value.$$typeof) {
1819
- case REACT_ELEMENT_TYPE:
1820
- {
1821
- // TODO: Concatenate keys of parents onto children.
1822
- var element = value; // Attempt to render the Server Component.
2246
+ function renderModelDestructive(request, task, parent, parentPropertyName, value) {
2247
+ // Set the currently rendering model
2248
+ task.model = value; // Special Symbol, that's very common.
1823
2249
 
1824
- value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, null);
1825
- break;
2250
+ if (value === REACT_ELEMENT_TYPE) {
2251
+ return '$';
2252
+ }
2253
+
2254
+ if (value === null) {
2255
+ return null;
2256
+ }
2257
+
2258
+ if (typeof value === 'object') {
2259
+ switch (value.$$typeof) {
2260
+ case REACT_ELEMENT_TYPE:
2261
+ {
2262
+ var _writtenObjects = request.writtenObjects;
2263
+
2264
+ var _existingId = _writtenObjects.get(value);
2265
+
2266
+ if (_existingId !== undefined) {
2267
+ if (modelRoot === value) {
2268
+ // This is the ID we're currently emitting so we need to write it
2269
+ // once but if we discover it again, we refer to it by id.
2270
+ modelRoot = null;
2271
+ } else if (_existingId === -1) {
2272
+ // Seen but not yet outlined.
2273
+ // TODO: If we throw here we can treat this as suspending which causes an outline
2274
+ // but that is able to reuse the same task if we're already in one but then that
2275
+ // will be a lazy future value rather than guaranteed to exist but maybe that's good.
2276
+ var newId = outlineModel(request, value);
2277
+ return serializeByValueID(newId);
2278
+ } else {
2279
+ // We've already emitted this as an outlined object, so we can refer to that by its
2280
+ // existing ID. TODO: We should use a lazy reference since, unlike plain objects,
2281
+ // elements might suspend so it might not have emitted yet even if we have the ID for
2282
+ // it. However, this creates an extra wrapper when it's not needed. We should really
2283
+ // detect whether this already was emitted and synchronously available. In that
2284
+ // case we can refer to it synchronously and only make it lazy otherwise.
2285
+ // We currently don't have a data structure that lets us see that though.
2286
+ return serializeByValueID(_existingId);
2287
+ }
2288
+ } else {
2289
+ // This is the first time we've seen this object. We may never see it again
2290
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2291
+ _writtenObjects.set(value, -1);
1826
2292
  }
1827
2293
 
1828
- case REACT_LAZY_TYPE:
2294
+ var element = value;
2295
+
1829
2296
  {
1830
- var payload = value._payload;
1831
- var init = value._init;
1832
- value = init(payload);
1833
- break;
2297
+ var debugInfo = value._debugInfo;
2298
+
2299
+ if (debugInfo) {
2300
+ // If this came from Flight, forward any debug info into this new row.
2301
+ if (debugID === null) {
2302
+ // We don't have a chunk to assign debug info. We need to outline this
2303
+ // component to assign it an ID.
2304
+ return outlineTask(request, task);
2305
+ } else {
2306
+ // Forward any debug info we have the first time we see it.
2307
+ forwardDebugInfo(request, debugID, debugInfo);
2308
+ }
2309
+ }
1834
2310
  }
1835
- }
1836
- } catch (thrownValue) {
1837
- var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
1838
- // reasons, the rest of the Suspense implementation expects the thrown
1839
- // value to be a thenable, because before `use` existed that was the
1840
- // (unstable) API for suspending. This implementation detail can change
1841
- // later, once we deprecate the old API in favor of `use`.
1842
- getSuspendedThenable() : thrownValue; // $FlowFixMe[method-unbinding]
1843
-
1844
- if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
1845
- // Something suspended, we'll need to create a new task and resolve it later.
1846
- request.pendingChunks++;
1847
- var newTask = createTask(request, value, getActiveContext(), request.abortableTasks);
1848
- var ping = newTask.ping;
1849
- x.then(ping, ping);
1850
- newTask.thenableState = getThenableStateAfterSuspending();
1851
- return serializeLazyID(newTask.id);
1852
- } else {
1853
- // Something errored. We'll still send everything we have up until this point.
1854
- // We'll replace this element with a lazy reference that throws on the client
1855
- // once it gets rendered.
1856
- request.pendingChunks++;
1857
- var errorId = request.nextChunkId++;
1858
- var digest = logRecoverableError(request, x);
1859
2311
 
2312
+ var props = element.props;
2313
+ var ref;
2314
+
2315
+ {
2316
+ ref = element.ref;
2317
+ } // Attempt to render the Server Component.
2318
+
2319
+
2320
+ return renderElement(request, task, element.type, // $FlowFixMe[incompatible-call] the key of an element is null | string
2321
+ element.key, ref, props);
2322
+ }
2323
+
2324
+ case REACT_LAZY_TYPE:
1860
2325
  {
1861
- var _getErrorMessageAndSt4 = getErrorMessageAndStackDev(x),
1862
- message = _getErrorMessageAndSt4.message,
1863
- stack = _getErrorMessageAndSt4.stack;
2326
+ // Reset the task's thenable state before continuing. If there was one, it was
2327
+ // from suspending the lazy before.
2328
+ task.thenableState = null;
2329
+ var lazy = value;
2330
+ var payload = lazy._payload;
2331
+ var init = lazy._init;
2332
+ var resolvedModel = init(payload);
2333
+
2334
+ {
2335
+ var _debugInfo = lazy._debugInfo;
2336
+
2337
+ if (_debugInfo) {
2338
+ // If this came from Flight, forward any debug info into this new row.
2339
+ if (debugID === null) {
2340
+ // We don't have a chunk to assign debug info. We need to outline this
2341
+ // component to assign it an ID.
2342
+ return outlineTask(request, task);
2343
+ } else {
2344
+ // Forward any debug info we have the first time we see it.
2345
+ // We do this after init so that we have received all the debug info
2346
+ // from the server by the time we emit it.
2347
+ forwardDebugInfo(request, debugID, _debugInfo);
2348
+ }
2349
+ }
2350
+ }
1864
2351
 
1865
- emitErrorChunkDev(request, errorId, digest, message, stack);
2352
+ return renderModelDestructive(request, task, emptyRoot, '', resolvedModel);
1866
2353
  }
2354
+ }
1867
2355
 
1868
- return serializeLazyID(errorId);
1869
- }
2356
+ if (isClientReference(value)) {
2357
+ return serializeClientReference(request, parent, parentPropertyName, value);
1870
2358
  }
1871
- }
1872
2359
 
1873
- if (value === null) {
1874
- return null;
1875
- }
2360
+ var writtenObjects = request.writtenObjects;
2361
+ var existingId = writtenObjects.get(value); // $FlowFixMe[method-unbinding]
1876
2362
 
1877
- if (typeof value === 'object') {
1878
- if (isClientReference(value)) {
1879
- return serializeClientReference(request, parent, key, value); // $FlowFixMe[method-unbinding]
1880
- } else if (typeof value.then === 'function') {
1881
- // We assume that any object with a .then property is a "Thenable" type,
2363
+ if (typeof value.then === 'function') {
2364
+ if (existingId !== undefined) {
2365
+ if (modelRoot === value) {
2366
+ // This is the ID we're currently emitting so we need to write it
2367
+ // once but if we discover it again, we refer to it by id.
2368
+ modelRoot = null;
2369
+ } else {
2370
+ // We've seen this promise before, so we can just refer to the same result.
2371
+ return serializePromiseID(existingId);
2372
+ }
2373
+ } // We assume that any object with a .then property is a "Thenable" type,
1882
2374
  // or a Promise type. Either of which can be represented by a Promise.
1883
- var promiseId = serializeThenable(request, value);
2375
+
2376
+
2377
+ var promiseId = serializeThenable(request, task, value);
2378
+ writtenObjects.set(value, promiseId);
1884
2379
  return serializePromiseID(promiseId);
1885
- } else if (value.$$typeof === REACT_PROVIDER_TYPE) {
1886
- var providerKey = value._context._globalName;
1887
- var writtenProviders = request.writtenProviders;
1888
- var providerId = writtenProviders.get(key);
1889
-
1890
- if (providerId === undefined) {
1891
- request.pendingChunks++;
1892
- providerId = request.nextChunkId++;
1893
- writtenProviders.set(providerKey, providerId);
1894
- emitProviderChunk(request, providerId, providerKey);
2380
+ }
2381
+
2382
+ if (existingId !== undefined) {
2383
+ if (modelRoot === value) {
2384
+ // This is the ID we're currently emitting so we need to write it
2385
+ // once but if we discover it again, we refer to it by id.
2386
+ modelRoot = null;
2387
+ } else if (existingId === -1) {
2388
+ // Seen but not yet outlined.
2389
+ var _newId = outlineModel(request, value);
2390
+
2391
+ return serializeByValueID(_newId);
2392
+ } else {
2393
+ // We've already emitted this as an outlined object, so we can
2394
+ // just refer to that by its existing ID.
2395
+ return serializeByValueID(existingId);
1895
2396
  }
2397
+ } else {
2398
+ // This is the first time we've seen this object. We may never see it again
2399
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2400
+ writtenObjects.set(value, -1);
2401
+ }
1896
2402
 
1897
- return serializeByValueID(providerId);
1898
- } else if (value === POP) {
1899
- popProvider();
2403
+ if (isArray(value)) {
2404
+ return renderFragment(request, task, value);
2405
+ }
1900
2406
 
1901
- {
1902
- insideContextProps = null;
1903
- isInsideContextValue = false;
1904
- }
2407
+ if (value instanceof Map) {
2408
+ return serializeMap(request, value);
2409
+ }
1905
2410
 
1906
- return undefined;
2411
+ if (value instanceof Set) {
2412
+ return serializeSet(request, value);
1907
2413
  }
1908
2414
 
1909
- if (!isArray(value)) {
1910
- var iteratorFn = getIteratorFn(value);
2415
+ var iteratorFn = getIteratorFn(value);
1911
2416
 
1912
- if (iteratorFn) {
1913
- return Array.from(value);
1914
- }
2417
+ if (iteratorFn) {
2418
+ return renderFragment(request, task, Array.from(value));
2419
+ } // Verify that this is a simple plain object.
2420
+
2421
+
2422
+ var proto = getPrototypeOf(value);
2423
+
2424
+ if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
2425
+ 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.');
1915
2426
  }
1916
2427
 
1917
2428
  {
1918
- if (value !== null && !isArray(value)) {
1919
- // Verify that this is a simple plain object.
1920
- if (objectName(value) !== 'Object') {
1921
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
1922
- } else if (!isSimpleObject(value)) {
1923
- 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));
1924
- } else if (Object.getOwnPropertySymbols) {
1925
- var symbols = Object.getOwnPropertySymbols(value);
1926
-
1927
- if (symbols.length > 0) {
1928
- 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));
1929
- }
2429
+ if (objectName(value) !== 'Object') {
2430
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, parentPropertyName));
2431
+ } else if (!isSimpleObject(value)) {
2432
+ 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));
2433
+ } else if (Object.getOwnPropertySymbols) {
2434
+ var symbols = Object.getOwnPropertySymbols(value);
2435
+
2436
+ if (symbols.length > 0) {
2437
+ 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));
1930
2438
  }
1931
2439
  }
1932
2440
  } // $FlowFixMe[incompatible-return]
@@ -1936,17 +2444,25 @@ function resolveModelToJSON(request, parent, key, value) {
1936
2444
  }
1937
2445
 
1938
2446
  if (typeof value === 'string') {
1939
- // TODO: Maybe too clever. If we support URL there's no similar trick.
2447
+
2448
+
1940
2449
  if (value[value.length - 1] === 'Z') {
1941
2450
  // Possibly a Date, whose toJSON automatically calls toISOString
1942
2451
  // $FlowFixMe[incompatible-use]
1943
- var _originalValue = parent[key]; // $FlowFixMe[method-unbinding]
2452
+ var originalValue = parent[parentPropertyName];
1944
2453
 
1945
- if (_originalValue instanceof Date) {
2454
+ if (originalValue instanceof Date) {
1946
2455
  return serializeDateFromDateJSON(value);
1947
2456
  }
1948
2457
  }
1949
2458
 
2459
+ if (value.length >= 1024) {
2460
+ // For large strings, we encode them outside the JSON payload so that we
2461
+ // don't have to double encode and double parse the strings. This can also
2462
+ // be more compact in case the string has a lot of escaped characters.
2463
+ return serializeLargeTextString(request, value);
2464
+ }
2465
+
1950
2466
  return escapeStringValue(value);
1951
2467
  }
1952
2468
 
@@ -1964,26 +2480,34 @@ function resolveModelToJSON(request, parent, key, value) {
1964
2480
 
1965
2481
  if (typeof value === 'function') {
1966
2482
  if (isClientReference(value)) {
1967
- return serializeClientReference(request, parent, key, value);
2483
+ return serializeClientReference(request, parent, parentPropertyName, value);
1968
2484
  }
1969
2485
 
1970
2486
  if (isServerReference(value)) {
1971
- return serializeServerReference(request, parent, key, value);
2487
+ return serializeServerReference(request, value);
1972
2488
  }
1973
2489
 
1974
- if (/^on[A-Z]/.test(key)) {
1975
- 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.');
2490
+ if (isTemporaryReference(value)) {
2491
+ return serializeTemporaryReference(request, value);
2492
+ }
2493
+
2494
+ if (/^on[A-Z]/.test(parentPropertyName)) {
2495
+ 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.');
2496
+ } else if ((jsxChildrenParents.has(parent) || jsxPropsParents.has(parent) && parentPropertyName === 'children')) {
2497
+ var componentName = value.displayName || value.name || 'Component';
2498
+ 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));
1976
2499
  } else {
1977
- 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));
2500
+ 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));
1978
2501
  }
1979
2502
  }
1980
2503
 
1981
2504
  if (typeof value === 'symbol') {
1982
2505
  var writtenSymbols = request.writtenSymbols;
1983
- var existingId = writtenSymbols.get(value);
1984
2506
 
1985
- if (existingId !== undefined) {
1986
- return serializeByValueID(existingId);
2507
+ var _existingId2 = writtenSymbols.get(value);
2508
+
2509
+ if (_existingId2 !== undefined) {
2510
+ return serializeByValueID(_existingId2);
1987
2511
  } // $FlowFixMe[incompatible-type] `description` might be undefined
1988
2512
 
1989
2513
 
@@ -1991,7 +2515,7 @@ function resolveModelToJSON(request, parent, key, value) {
1991
2515
 
1992
2516
  if (Symbol.for(name) !== value) {
1993
2517
  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
1994
- value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, key));
2518
+ value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, parentPropertyName));
1995
2519
  }
1996
2520
 
1997
2521
  request.pendingChunks++;
@@ -2002,15 +2526,44 @@ function resolveModelToJSON(request, parent, key, value) {
2002
2526
  }
2003
2527
 
2004
2528
  if (typeof value === 'bigint') {
2529
+
2005
2530
  return serializeBigInt(value);
2006
2531
  }
2007
2532
 
2008
- throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, key));
2533
+ throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, parentPropertyName));
2534
+ }
2535
+
2536
+ function logPostpone(request, reason) {
2537
+ var prevRequest = currentRequest;
2538
+ currentRequest = null;
2539
+
2540
+ try {
2541
+ var onPostpone = request.onPostpone;
2542
+
2543
+ if (supportsRequestStorage) {
2544
+ // Exit the request context while running callbacks.
2545
+ requestStorage.run(undefined, onPostpone, reason);
2546
+ }
2547
+ } finally {
2548
+ currentRequest = prevRequest;
2549
+ }
2009
2550
  }
2010
2551
 
2011
2552
  function logRecoverableError(request, error) {
2012
- var onError = request.onError;
2013
- var errorDigest = onError(error);
2553
+ var prevRequest = currentRequest;
2554
+ currentRequest = null;
2555
+ var errorDigest;
2556
+
2557
+ try {
2558
+ var onError = request.onError;
2559
+
2560
+ if (supportsRequestStorage) {
2561
+ // Exit the request context while running callbacks.
2562
+ errorDigest = requestStorage.run(undefined, onError, error);
2563
+ }
2564
+ } finally {
2565
+ currentRequest = prevRequest;
2566
+ }
2014
2567
 
2015
2568
  if (errorDigest != null && typeof errorDigest !== 'string') {
2016
2569
  // eslint-disable-next-line react-internal/prod-error-codes
@@ -2020,7 +2573,45 @@ function logRecoverableError(request, error) {
2020
2573
  return errorDigest || '';
2021
2574
  }
2022
2575
 
2023
- function getErrorMessageAndStackDev(error) {
2576
+ function fatalError(request, error) {
2577
+
2578
+
2579
+ if (request.destination !== null) {
2580
+ request.status = CLOSED;
2581
+ closeWithError(request.destination, error);
2582
+ } else {
2583
+ request.status = CLOSING;
2584
+ request.fatalError = error;
2585
+ }
2586
+ }
2587
+
2588
+ function emitPostponeChunk(request, id, postponeInstance) {
2589
+ var row;
2590
+
2591
+ {
2592
+ var reason = '';
2593
+ var stack = '';
2594
+
2595
+ try {
2596
+ // eslint-disable-next-line react-internal/safe-string-coercion
2597
+ reason = String(postponeInstance.message); // eslint-disable-next-line react-internal/safe-string-coercion
2598
+
2599
+ stack = String(postponeInstance.stack);
2600
+ } catch (x) {}
2601
+
2602
+ row = serializeRowHeader('P', id) + stringify({
2603
+ reason: reason,
2604
+ stack: stack
2605
+ }) + '\n';
2606
+ }
2607
+
2608
+ var processedChunk = stringToChunk(row);
2609
+ request.completedErrorChunks.push(processedChunk);
2610
+ }
2611
+
2612
+ function emitErrorChunk(request, id, digest, error) {
2613
+ var errorInfo;
2614
+
2024
2615
  {
2025
2616
  var message;
2026
2617
  var stack = '';
@@ -2031,101 +2622,123 @@ function getErrorMessageAndStackDev(error) {
2031
2622
  message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
2032
2623
 
2033
2624
  stack = String(error.stack);
2625
+ } else if (typeof error === 'object' && error !== null) {
2626
+ message = describeObjectForErrorMessage(error);
2034
2627
  } else {
2035
- message = 'Error: ' + error;
2628
+ // eslint-disable-next-line react-internal/safe-string-coercion
2629
+ message = String(error);
2036
2630
  }
2037
2631
  } catch (x) {
2038
2632
  message = 'An error occurred but serializing the error message failed.';
2039
2633
  }
2040
2634
 
2041
- return {
2635
+ errorInfo = {
2636
+ digest: digest,
2042
2637
  message: message,
2043
2638
  stack: stack
2044
2639
  };
2045
2640
  }
2046
- }
2047
-
2048
- function fatalError(request, error) {
2049
- // This is called outside error handling code such as if an error happens in React internals.
2050
- if (request.destination !== null) {
2051
- request.status = CLOSED;
2052
- closeWithError(request.destination, error);
2053
- } else {
2054
- request.status = CLOSING;
2055
- request.fatalError = error;
2056
- }
2057
- }
2058
-
2059
- function emitErrorChunkProd(request, id, digest) {
2060
- var processedChunk = processErrorChunkProd();
2061
- request.completedErrorChunks.push(processedChunk);
2062
- }
2063
2641
 
2064
- function emitErrorChunkDev(request, id, digest, message, stack) {
2065
- var processedChunk = processErrorChunkDev(request, id, digest, message, stack);
2642
+ var row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
2643
+ var processedChunk = stringToChunk(row);
2066
2644
  request.completedErrorChunks.push(processedChunk);
2067
2645
  }
2068
2646
 
2069
2647
  function emitImportChunk(request, id, clientReferenceMetadata) {
2070
- var processedChunk = processImportChunk(request, id, clientReferenceMetadata);
2648
+ // $FlowFixMe[incompatible-type] stringify can return null
2649
+ var json = stringify(clientReferenceMetadata);
2650
+ var row = serializeRowHeader('I', id) + json + '\n';
2651
+ var processedChunk = stringToChunk(row);
2071
2652
  request.completedImportChunks.push(processedChunk);
2072
2653
  }
2073
2654
 
2074
2655
  function emitHintChunk(request, code, model) {
2075
- var processedChunk = processHintChunk(request, request.nextChunkId++, code, model);
2656
+ var json = stringify(model);
2657
+ var id = request.nextChunkId++;
2658
+ var row = serializeRowHeader('H' + code, id) + json + '\n';
2659
+ var processedChunk = stringToChunk(row);
2076
2660
  request.completedHintChunks.push(processedChunk);
2077
2661
  }
2078
2662
 
2079
2663
  function emitSymbolChunk(request, id, name) {
2080
2664
  var symbolReference = serializeSymbolReference(name);
2081
- var processedChunk = processReferenceChunk(request, id, symbolReference);
2665
+ var processedChunk = encodeReferenceChunk(request, id, symbolReference);
2082
2666
  request.completedImportChunks.push(processedChunk);
2083
2667
  }
2084
2668
 
2085
- function emitProviderChunk(request, id, contextName) {
2086
- var contextReference = serializeProviderReference(contextName);
2087
- var processedChunk = processReferenceChunk(request, id, contextReference);
2088
- request.completedJSONChunks.push(processedChunk);
2669
+ function emitModelChunk(request, id, json) {
2670
+ var row = id.toString(16) + ':' + json + '\n';
2671
+ var processedChunk = stringToChunk(row);
2672
+ request.completedRegularChunks.push(processedChunk);
2673
+ }
2674
+
2675
+ function emitDebugChunk(request, id, debugInfo) {
2676
+
2677
+
2678
+ var json = stringify(debugInfo);
2679
+ var row = serializeRowHeader('D', id) + json + '\n';
2680
+ var processedChunk = stringToChunk(row);
2681
+ request.completedRegularChunks.push(processedChunk);
2682
+ }
2683
+
2684
+ function forwardDebugInfo(request, id, debugInfo) {
2685
+ for (var i = 0; i < debugInfo.length; i++) {
2686
+ request.pendingChunks++;
2687
+ emitDebugChunk(request, id, debugInfo[i]);
2688
+ }
2089
2689
  }
2090
2690
 
2691
+ var emptyRoot = {};
2692
+
2091
2693
  function retryTask(request, task) {
2092
2694
  if (task.status !== PENDING$1) {
2093
2695
  // We completed this by other means before we had a chance to retry it.
2094
2696
  return;
2095
2697
  }
2096
2698
 
2097
- switchContext(task.context);
2699
+ var prevDebugID = debugID;
2098
2700
 
2099
2701
  try {
2100
- var value = task.model;
2101
-
2102
- if (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
2103
- // TODO: Concatenate keys of parents onto children.
2104
- var element = value; // When retrying a component, reuse the thenableState from the
2105
- // previous attempt.
2106
-
2107
- var prevThenableState = task.thenableState; // Attempt to render the Server Component.
2108
- // Doing this here lets us reuse this same task if the next component
2109
- // also suspends.
2110
-
2111
- task.model = value;
2112
- value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, prevThenableState); // Successfully finished this component. We're going to keep rendering
2113
- // using the same task, but we reset its thenable state before continuing.
2114
-
2115
- task.thenableState = null; // Keep rendering and reuse the same task. This inner loop is separate
2116
- // from the render above because we don't need to reset the thenable state
2117
- // until the next time something suspends and retries.
2118
-
2119
- while (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
2120
- // TODO: Concatenate keys of parents onto children.
2121
- var nextElement = value;
2122
- task.model = value;
2123
- value = attemptResolveElement(request, nextElement.type, nextElement.key, nextElement.ref, nextElement.props, null);
2124
- }
2702
+ // Track the root so we know that we have to emit this object even though it
2703
+ // already has an ID. This is needed because we might see this object twice
2704
+ // in the same toJSON if it is cyclic.
2705
+ modelRoot = task.model;
2706
+
2707
+ if (true) {
2708
+ // Track the ID of the current task so we can assign debug info to this id.
2709
+ debugID = task.id;
2710
+ } // We call the destructive form that mutates this task. That way if something
2711
+ // suspends again, we can reuse the same task instead of spawning a new one.
2712
+
2713
+
2714
+ var resolvedModel = renderModelDestructive(request, task, emptyRoot, '', task.model);
2715
+
2716
+ if (true) {
2717
+ // We're now past rendering this task and future renders will spawn new tasks for their
2718
+ // debug info.
2719
+ debugID = null;
2720
+ } // Track the root again for the resolved object.
2721
+
2722
+
2723
+ modelRoot = resolvedModel; // The keyPath resets at any terminal child node.
2724
+
2725
+ task.keyPath = null;
2726
+ task.implicitSlot = false;
2727
+ var json;
2728
+
2729
+ if (typeof resolvedModel === 'object' && resolvedModel !== null) {
2730
+ // Object might contain unresolved values like additional elements.
2731
+ // This is simulating what the JSON loop would do if this was part of it.
2732
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2733
+ json = stringify(resolvedModel, task.toJSON);
2734
+ } else {
2735
+ // If the value is a string, it means it's a terminal value and we already escaped it
2736
+ // We don't need to escape it again so it's not passed the toJSON replacer.
2737
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2738
+ json = stringify(resolvedModel);
2125
2739
  }
2126
2740
 
2127
- var processedChunk = processModelChunk(request, task.id, value);
2128
- request.completedJSONChunks.push(processedChunk);
2741
+ emitModelChunk(request, task.id, json);
2129
2742
  request.abortableTasks.delete(task);
2130
2743
  task.status = COMPLETED;
2131
2744
  } catch (thrownValue) {
@@ -2134,27 +2747,27 @@ function retryTask(request, task) {
2134
2747
  // value to be a thenable, because before `use` existed that was the
2135
2748
  // (unstable) API for suspending. This implementation detail can change
2136
2749
  // later, once we deprecate the old API in favor of `use`.
2137
- getSuspendedThenable() : thrownValue; // $FlowFixMe[method-unbinding]
2138
-
2139
- if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
2140
- // Something suspended again, let's pick it back up later.
2141
- var ping = task.ping;
2142
- x.then(ping, ping);
2143
- task.thenableState = getThenableStateAfterSuspending();
2144
- return;
2145
- } else {
2146
- request.abortableTasks.delete(task);
2147
- task.status = ERRORED$1;
2148
- var digest = logRecoverableError(request, x);
2750
+ getSuspendedThenable() : thrownValue;
2149
2751
 
2150
- {
2151
- var _getErrorMessageAndSt5 = getErrorMessageAndStackDev(x),
2152
- message = _getErrorMessageAndSt5.message,
2153
- stack = _getErrorMessageAndSt5.stack;
2154
-
2155
- emitErrorChunkDev(request, task.id, digest, message, stack);
2752
+ if (typeof x === 'object' && x !== null) {
2753
+ // $FlowFixMe[method-unbinding]
2754
+ if (typeof x.then === 'function') {
2755
+ // Something suspended again, let's pick it back up later.
2756
+ var ping = task.ping;
2757
+ x.then(ping, ping);
2758
+ task.thenableState = getThenableStateAfterSuspending();
2759
+ return;
2156
2760
  }
2157
2761
  }
2762
+
2763
+ request.abortableTasks.delete(task);
2764
+ task.status = ERRORED$1;
2765
+ var digest = logRecoverableError(request, x);
2766
+ emitErrorChunk(request, task.id, digest, x);
2767
+ } finally {
2768
+ {
2769
+ debugID = prevDebugID;
2770
+ }
2158
2771
  }
2159
2772
  }
2160
2773
 
@@ -2192,7 +2805,7 @@ function abortTask(task, request, errorId) {
2192
2805
  // has a single value referencing the error.
2193
2806
 
2194
2807
  var ref = serializeByValueID(errorId);
2195
- var processedChunk = processReferenceChunk(request, task.id, ref);
2808
+ var processedChunk = encodeReferenceChunk(request, task.id, ref);
2196
2809
  request.completedErrorChunks.push(processedChunk);
2197
2810
  }
2198
2811
 
@@ -2236,12 +2849,12 @@ function flushCompletedChunks(request, destination) {
2236
2849
 
2237
2850
  hintChunks.splice(0, i); // Next comes model data.
2238
2851
 
2239
- var jsonChunks = request.completedJSONChunks;
2852
+ var regularChunks = request.completedRegularChunks;
2240
2853
  i = 0;
2241
2854
 
2242
- for (; i < jsonChunks.length; i++) {
2855
+ for (; i < regularChunks.length; i++) {
2243
2856
  request.pendingChunks--;
2244
- var _chunk2 = jsonChunks[i];
2857
+ var _chunk2 = regularChunks[i];
2245
2858
 
2246
2859
  var _keepWriting2 = writeChunkAndReturn(destination, _chunk2);
2247
2860
 
@@ -2252,7 +2865,7 @@ function flushCompletedChunks(request, destination) {
2252
2865
  }
2253
2866
  }
2254
2867
 
2255
- jsonChunks.splice(0, i); // Finally, errors are sent. The idea is that it's ok to delay
2868
+ regularChunks.splice(0, i); // Finally, errors are sent. The idea is that it's ok to delay
2256
2869
  // any error messages and prioritize display of other parts of
2257
2870
  // the page.
2258
2871
 
@@ -2281,7 +2894,7 @@ function flushCompletedChunks(request, destination) {
2281
2894
  flushBuffered(destination);
2282
2895
 
2283
2896
  if (request.pendingChunks === 0) {
2284
- // We're done.
2897
+
2285
2898
  close$1(destination);
2286
2899
  }
2287
2900
  }
@@ -2333,6 +2946,9 @@ function startFlowing(request, destination) {
2333
2946
  logRecoverableError(request, error);
2334
2947
  fatalError(request, error);
2335
2948
  }
2949
+ }
2950
+ function stopFlowing(request) {
2951
+ request.destination = null;
2336
2952
  } // This is called to early terminate a request. It creates an error at all pending tasks.
2337
2953
 
2338
2954
  function abort(request, reason) {
@@ -2342,17 +2958,13 @@ function abort(request, reason) {
2342
2958
  if (abortableTasks.size > 0) {
2343
2959
  // We have tasks to abort. We'll emit one error row and then emit a reference
2344
2960
  // to that row from every row that's still remaining.
2345
- var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
2346
- var digest = logRecoverableError(request, error);
2347
2961
  request.pendingChunks++;
2348
2962
  var errorId = request.nextChunkId++;
2349
2963
 
2350
- if (true) {
2351
- var _getErrorMessageAndSt6 = getErrorMessageAndStackDev(error),
2352
- message = _getErrorMessageAndSt6.message,
2353
- stack = _getErrorMessageAndSt6.stack;
2354
-
2355
- emitErrorChunkDev(request, errorId, digest, message, stack);
2964
+ var postponeInstance; if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
2965
+ var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
2966
+ var digest = logRecoverableError(request, error);
2967
+ emitErrorChunk(request, errorId, digest, error);
2356
2968
  }
2357
2969
 
2358
2970
  abortableTasks.forEach(function (task) {
@@ -2370,28 +2982,20 @@ function abort(request, reason) {
2370
2982
  }
2371
2983
  }
2372
2984
 
2373
- function importServerContexts(contexts) {
2374
- if (contexts) {
2375
- var prevContext = getActiveContext();
2376
- switchContext(rootContextSnapshot);
2377
-
2378
- for (var i = 0; i < contexts.length; i++) {
2379
- var _contexts$i = contexts[i],
2380
- name = _contexts$i[0],
2381
- value = _contexts$i[1];
2382
- var context = getOrCreateServerContext(name);
2383
- pushProvider(context, value);
2384
- }
2385
-
2386
- var importedContext = getActiveContext();
2387
- switchContext(prevContext);
2388
- return importedContext;
2389
- }
2985
+ // This is the parsed shape of the wire format which is why it is
2986
+ // condensed to only the essentialy information
2987
+ var ID = 0;
2988
+ var CHUNKS = 1;
2989
+ var NAME = 2; // export const ASYNC = 3;
2990
+ // This logic is correct because currently only include the 4th tuple member
2991
+ // when the module is async. If that changes we will need to actually assert
2992
+ // the value is true. We don't index into the 4th slot because flow does not
2993
+ // like the potential out of bounds access
2390
2994
 
2391
- return rootContextSnapshot;
2995
+ function isAsyncImport(metadata) {
2996
+ return metadata.length === 4;
2392
2997
  }
2393
2998
 
2394
- // eslint-disable-next-line no-unused-vars
2395
2999
  function resolveServerReference(bundlerConfig, id) {
2396
3000
  var name = '';
2397
3001
  var resolvedModuleData = bundlerConfig[id];
@@ -2417,19 +3021,38 @@ function resolveServerReference(bundlerConfig, id) {
2417
3021
  } // TODO: This needs to return async: true if it's an async module.
2418
3022
 
2419
3023
 
2420
- return {
2421
- id: resolvedModuleData.id,
2422
- chunks: resolvedModuleData.chunks,
2423
- name: name,
2424
- async: false
2425
- };
3024
+ return [resolvedModuleData.id, resolvedModuleData.chunks, name];
2426
3025
  } // The chunk cache contains all the chunks we've preloaded so far.
2427
3026
  // If they're still pending they're a thenable. This map also exists
2428
3027
  // in Webpack but unfortunately it's not exposed so we have to
2429
3028
  // replicate it in user space. null means that it has already loaded.
2430
3029
 
2431
3030
  var chunkCache = new Map();
2432
- var asyncModuleCache = new Map();
3031
+
3032
+ function requireAsyncModule(id) {
3033
+ // We've already loaded all the chunks. We can require the module.
3034
+ var promise = __webpack_require__(id);
3035
+
3036
+ if (typeof promise.then !== 'function') {
3037
+ // This wasn't a promise after all.
3038
+ return null;
3039
+ } else if (promise.status === 'fulfilled') {
3040
+ // This module was already resolved earlier.
3041
+ return null;
3042
+ } else {
3043
+ // Instrument the Promise to stash the result.
3044
+ promise.then(function (value) {
3045
+ var fulfilledThenable = promise;
3046
+ fulfilledThenable.status = 'fulfilled';
3047
+ fulfilledThenable.value = value;
3048
+ }, function (reason) {
3049
+ var rejectedThenable = promise;
3050
+ rejectedThenable.status = 'rejected';
3051
+ rejectedThenable.reason = reason;
3052
+ });
3053
+ return promise;
3054
+ }
3055
+ }
2433
3056
 
2434
3057
  function ignoreReject() {// We rely on rejected promises to be handled by another listener.
2435
3058
  } // Start preloading the modules since we might need them soon.
@@ -2437,16 +3060,17 @@ function ignoreReject() {// We rely on rejected promises to be handled by anothe
2437
3060
 
2438
3061
 
2439
3062
  function preloadModule(metadata) {
2440
- var chunks = metadata.chunks;
3063
+ var chunks = metadata[CHUNKS];
2441
3064
  var promises = [];
3065
+ var i = 0;
2442
3066
 
2443
- for (var i = 0; i < chunks.length; i++) {
2444
- var chunkId = chunks[i];
3067
+ while (i < chunks.length) {
3068
+ var chunkId = chunks[i++];
3069
+ chunks[i++];
2445
3070
  var entry = chunkCache.get(chunkId);
2446
3071
 
2447
3072
  if (entry === undefined) {
2448
- var thenable = __webpack_chunk_load__(chunkId);
2449
-
3073
+ var thenable = loadChunk(chunkId);
2450
3074
  promises.push(thenable); // $FlowFixMe[method-unbinding]
2451
3075
 
2452
3076
  var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
@@ -2457,30 +3081,13 @@ function preloadModule(metadata) {
2457
3081
  }
2458
3082
  }
2459
3083
 
2460
- if (metadata.async) {
2461
- var existingPromise = asyncModuleCache.get(metadata.id);
2462
-
2463
- if (existingPromise) {
2464
- if (existingPromise.status === 'fulfilled') {
2465
- return null;
2466
- }
2467
-
2468
- return existingPromise;
3084
+ if (isAsyncImport(metadata)) {
3085
+ if (promises.length === 0) {
3086
+ return requireAsyncModule(metadata[ID]);
2469
3087
  } else {
2470
- var modulePromise = Promise.all(promises).then(function () {
2471
- return __webpack_require__(metadata.id);
3088
+ return Promise.all(promises).then(function () {
3089
+ return requireAsyncModule(metadata[ID]);
2472
3090
  });
2473
- modulePromise.then(function (value) {
2474
- var fulfilledThenable = modulePromise;
2475
- fulfilledThenable.status = 'fulfilled';
2476
- fulfilledThenable.value = value;
2477
- }, function (reason) {
2478
- var rejectedThenable = modulePromise;
2479
- rejectedThenable.status = 'rejected';
2480
- rejectedThenable.reason = reason;
2481
- });
2482
- asyncModuleCache.set(metadata.id, modulePromise);
2483
- return modulePromise;
2484
3091
  }
2485
3092
  } else if (promises.length > 0) {
2486
3093
  return Promise.all(promises);
@@ -2491,35 +3098,34 @@ function preloadModule(metadata) {
2491
3098
  // Increase priority if necessary.
2492
3099
 
2493
3100
  function requireModule(metadata) {
2494
- var moduleExports;
2495
-
2496
- if (metadata.async) {
2497
- // We assume that preloadModule has been called before, which
2498
- // should have added something to the module cache.
2499
- var promise = asyncModuleCache.get(metadata.id);
3101
+ var moduleExports = __webpack_require__(metadata[ID]);
2500
3102
 
2501
- if (promise.status === 'fulfilled') {
2502
- moduleExports = promise.value;
3103
+ if (isAsyncImport(metadata)) {
3104
+ if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
3105
+ // This Promise should've been instrumented by preloadModule.
3106
+ moduleExports = moduleExports.value;
2503
3107
  } else {
2504
- throw promise.reason;
3108
+ throw moduleExports.reason;
2505
3109
  }
2506
- } else {
2507
- moduleExports = __webpack_require__(metadata.id);
2508
3110
  }
2509
3111
 
2510
- if (metadata.name === '*') {
3112
+ if (metadata[NAME] === '*') {
2511
3113
  // This is a placeholder value that represents that the caller imported this
2512
3114
  // as a CommonJS module as is.
2513
3115
  return moduleExports;
2514
3116
  }
2515
3117
 
2516
- if (metadata.name === '') {
3118
+ if (metadata[NAME] === '') {
2517
3119
  // This is a placeholder value that represents that the caller accessed the
2518
3120
  // default property of this if it was an ESM interop module.
2519
3121
  return moduleExports.__esModule ? moduleExports.default : moduleExports;
2520
3122
  }
2521
3123
 
2522
- return moduleExports[metadata.name];
3124
+ return moduleExports[metadata[NAME]];
3125
+ }
3126
+
3127
+ function loadChunk(chunkId, filename) {
3128
+ return __webpack_chunk_load__(chunkId);
2523
3129
  }
2524
3130
 
2525
3131
  // The server acts as a Client of itself when resolving Server References.
@@ -2662,11 +3268,11 @@ function resolveModelChunk(chunk, value) {
2662
3268
  }
2663
3269
  }
2664
3270
 
2665
- function bindArgs(fn, args) {
3271
+ function bindArgs$1(fn, args) {
2666
3272
  return fn.bind.apply(fn, [null].concat(args));
2667
3273
  }
2668
3274
 
2669
- function loadServerReference(response, id, bound, parentChunk, parentObject, key) {
3275
+ function loadServerReference$1(response, id, bound, parentChunk, parentObject, key) {
2670
3276
  var serverReference = resolveServerReference(response._bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
2671
3277
  // the relevant modules already loaded but it allows for lazy loading of code
2672
3278
  // if needed.
@@ -2677,7 +3283,7 @@ function loadServerReference(response, id, bound, parentChunk, parentObject, key
2677
3283
  if (bound) {
2678
3284
  promise = Promise.all([bound, preloadPromise]).then(function (_ref) {
2679
3285
  var args = _ref[0];
2680
- return bindArgs(requireModule(serverReference), args);
3286
+ return bindArgs$1(requireModule(serverReference), args);
2681
3287
  });
2682
3288
  } else {
2683
3289
  if (preloadPromise) {
@@ -2807,6 +3413,21 @@ function createModelReject(chunk) {
2807
3413
  };
2808
3414
  }
2809
3415
 
3416
+ function getOutlinedModel(response, id) {
3417
+ var chunk = getChunk(response, id);
3418
+
3419
+ if (chunk.status === RESOLVED_MODEL) {
3420
+ initializeModelChunk(chunk);
3421
+ }
3422
+
3423
+ if (chunk.status !== INITIALIZED) {
3424
+ // We know that this is emitted earlier so otherwise it's an error.
3425
+ throw chunk.reason;
3426
+ }
3427
+
3428
+ return chunk.value;
3429
+ }
3430
+
2810
3431
  function parseModelString(response, parentObject, key, value) {
2811
3432
  if (value[0] === '$') {
2812
3433
  switch (value[1]) {
@@ -2824,31 +3445,39 @@ function parseModelString(response, parentObject, key, value) {
2824
3445
  return chunk;
2825
3446
  }
2826
3447
 
2827
- case 'S':
3448
+ case 'F':
2828
3449
  {
2829
- // Symbol
2830
- return Symbol.for(value.slice(2));
3450
+ // Server Reference
3451
+ var _id = parseInt(value.slice(2), 16); // TODO: Just encode this in the reference inline instead of as a model.
3452
+
3453
+
3454
+ var metaData = getOutlinedModel(response, _id);
3455
+ return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
2831
3456
  }
2832
3457
 
2833
- case 'F':
3458
+ case 'T':
2834
3459
  {
2835
- // Server Reference
2836
- var _id = parseInt(value.slice(2), 16);
3460
+ // Temporary Reference
3461
+ return createTemporaryReference(value.slice(2));
3462
+ }
2837
3463
 
2838
- var _chunk = getChunk(response, _id);
3464
+ case 'Q':
3465
+ {
3466
+ // Map
3467
+ var _id2 = parseInt(value.slice(2), 16);
2839
3468
 
2840
- if (_chunk.status === RESOLVED_MODEL) {
2841
- initializeModelChunk(_chunk);
2842
- }
3469
+ var data = getOutlinedModel(response, _id2);
3470
+ return new Map(data);
3471
+ }
2843
3472
 
2844
- if (_chunk.status !== INITIALIZED) {
2845
- // We know that this is emitted earlier so otherwise it's an error.
2846
- throw _chunk.reason;
2847
- } // TODO: Just encode this in the reference inline instead of as a model.
3473
+ case 'W':
3474
+ {
3475
+ // Set
3476
+ var _id3 = parseInt(value.slice(2), 16);
2848
3477
 
3478
+ var _data = getOutlinedModel(response, _id3);
2849
3479
 
2850
- var metaData = _chunk.value;
2851
- return loadServerReference(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
3480
+ return new Set(_data);
2852
3481
  }
2853
3482
 
2854
3483
  case 'K':
@@ -2856,7 +3485,9 @@ function parseModelString(response, parentObject, key, value) {
2856
3485
  // FormData
2857
3486
  var stringId = value.slice(2);
2858
3487
  var formPrefix = response._prefix + stringId + '_';
2859
- var data = new FormData();
3488
+
3489
+ var _data2 = new FormData();
3490
+
2860
3491
  var backingFormData = response._formData; // We assume that the reference to FormData always comes after each
2861
3492
  // entry that it references so we can assume they all exist in the
2862
3493
  // backing store already.
@@ -2864,10 +3495,10 @@ function parseModelString(response, parentObject, key, value) {
2864
3495
 
2865
3496
  backingFormData.forEach(function (entry, entryKey) {
2866
3497
  if (entryKey.startsWith(formPrefix)) {
2867
- data.append(entryKey.slice(formPrefix.length), entry);
3498
+ _data2.append(entryKey.slice(formPrefix.length), entry);
2868
3499
  }
2869
3500
  });
2870
- return data;
3501
+ return _data2;
2871
3502
  }
2872
3503
 
2873
3504
  case 'I':
@@ -2914,31 +3545,31 @@ function parseModelString(response, parentObject, key, value) {
2914
3545
  default:
2915
3546
  {
2916
3547
  // We assume that anything else is a reference ID.
2917
- var _id2 = parseInt(value.slice(1), 16);
3548
+ var _id4 = parseInt(value.slice(1), 16);
2918
3549
 
2919
- var _chunk2 = getChunk(response, _id2);
3550
+ var _chunk = getChunk(response, _id4);
2920
3551
 
2921
- switch (_chunk2.status) {
3552
+ switch (_chunk.status) {
2922
3553
  case RESOLVED_MODEL:
2923
- initializeModelChunk(_chunk2);
3554
+ initializeModelChunk(_chunk);
2924
3555
  break;
2925
3556
  } // The status might have changed after initialization.
2926
3557
 
2927
3558
 
2928
- switch (_chunk2.status) {
3559
+ switch (_chunk.status) {
2929
3560
  case INITIALIZED:
2930
- return _chunk2.value;
3561
+ return _chunk.value;
2931
3562
 
2932
3563
  case PENDING:
2933
3564
  case BLOCKED:
2934
3565
  var parentChunk = initializingChunk;
2935
3566
 
2936
- _chunk2.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
3567
+ _chunk.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
2937
3568
 
2938
3569
  return null;
2939
3570
 
2940
3571
  default:
2941
- throw _chunk2.reason;
3572
+ throw _chunk.reason;
2942
3573
  }
2943
3574
  }
2944
3575
  }
@@ -3012,14 +3643,144 @@ function close(response) {
3012
3643
  reportGlobalError(response, new Error('Connection closed.'));
3013
3644
  }
3014
3645
 
3646
+ function bindArgs(fn, args) {
3647
+ return fn.bind.apply(fn, [null].concat(args));
3648
+ }
3649
+
3650
+ function loadServerReference(bundlerConfig, id, bound) {
3651
+ var serverReference = resolveServerReference(bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
3652
+ // the relevant modules already loaded but it allows for lazy loading of code
3653
+ // if needed.
3654
+
3655
+ var preloadPromise = preloadModule(serverReference);
3656
+
3657
+ if (bound) {
3658
+ return Promise.all([bound, preloadPromise]).then(function (_ref) {
3659
+ var args = _ref[0];
3660
+ return bindArgs(requireModule(serverReference), args);
3661
+ });
3662
+ } else if (preloadPromise) {
3663
+ return Promise.resolve(preloadPromise).then(function () {
3664
+ return requireModule(serverReference);
3665
+ });
3666
+ } else {
3667
+ // Synchronously available
3668
+ return Promise.resolve(requireModule(serverReference));
3669
+ }
3670
+ }
3671
+
3672
+ function decodeBoundActionMetaData(body, serverManifest, formFieldPrefix) {
3673
+ // The data for this reference is encoded in multiple fields under this prefix.
3674
+ var actionResponse = createResponse(serverManifest, formFieldPrefix, body);
3675
+ close(actionResponse);
3676
+ var refPromise = getRoot(actionResponse); // Force it to initialize
3677
+ // $FlowFixMe
3678
+
3679
+ refPromise.then(function () {});
3680
+
3681
+ if (refPromise.status !== 'fulfilled') {
3682
+ // $FlowFixMe
3683
+ throw refPromise.reason;
3684
+ }
3685
+
3686
+ return refPromise.value;
3687
+ }
3688
+
3689
+ function decodeAction(body, serverManifest) {
3690
+ // We're going to create a new formData object that holds all the fields except
3691
+ // the implementation details of the action data.
3692
+ var formData = new FormData();
3693
+ var action = null; // $FlowFixMe[prop-missing]
3694
+
3695
+ body.forEach(function (value, key) {
3696
+ if (!key.startsWith('$ACTION_')) {
3697
+ formData.append(key, value);
3698
+ return;
3699
+ } // Later actions may override earlier actions if a button is used to override the default
3700
+ // form action.
3701
+
3702
+
3703
+ if (key.startsWith('$ACTION_REF_')) {
3704
+ var formFieldPrefix = '$ACTION_' + key.slice(12) + ':';
3705
+ var metaData = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3706
+ action = loadServerReference(serverManifest, metaData.id, metaData.bound);
3707
+ return;
3708
+ }
3709
+
3710
+ if (key.startsWith('$ACTION_ID_')) {
3711
+ var id = key.slice(11);
3712
+ action = loadServerReference(serverManifest, id, null);
3713
+ return;
3714
+ }
3715
+ });
3716
+
3717
+ if (action === null) {
3718
+ return null;
3719
+ } // Return the action with the remaining FormData bound to the first argument.
3720
+
3721
+
3722
+ return action.then(function (fn) {
3723
+ return fn.bind(null, formData);
3724
+ });
3725
+ }
3726
+ function decodeFormState(actionResult, body, serverManifest) {
3727
+ var keyPath = body.get('$ACTION_KEY');
3728
+
3729
+ if (typeof keyPath !== 'string') {
3730
+ // This form submission did not include any form state.
3731
+ return Promise.resolve(null);
3732
+ } // Search through the form data object to get the reference id and the number
3733
+ // of bound arguments. This repeats some of the work done in decodeAction.
3734
+
3735
+
3736
+ var metaData = null; // $FlowFixMe[prop-missing]
3737
+
3738
+ body.forEach(function (value, key) {
3739
+ if (key.startsWith('$ACTION_REF_')) {
3740
+ var formFieldPrefix = '$ACTION_' + key.slice(12) + ':';
3741
+ metaData = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3742
+ } // We don't check for the simple $ACTION_ID_ case because form state actions
3743
+ // are always bound to the state argument.
3744
+
3745
+ });
3746
+
3747
+ if (metaData === null) {
3748
+ // Should be unreachable.
3749
+ return Promise.resolve(null);
3750
+ }
3751
+
3752
+ var referenceId = metaData.id;
3753
+ return Promise.resolve(metaData.bound).then(function (bound) {
3754
+ if (bound === null) {
3755
+ // Should be unreachable because form state actions are always bound to the
3756
+ // state argument.
3757
+ return null;
3758
+ } // The form action dispatch method is always bound to the initial state.
3759
+ // But when comparing signatures, we compare to the original unbound action.
3760
+ // Subtract one from the arity to account for this.
3761
+
3762
+
3763
+ var boundArity = bound.length - 1;
3764
+ return [actionResult, keyPath, referenceId, boundArity];
3765
+ });
3766
+ }
3767
+
3015
3768
  function createDrainHandler(destination, request) {
3016
3769
  return function () {
3017
3770
  return startFlowing(request, destination);
3018
3771
  };
3019
3772
  }
3020
3773
 
3774
+ function createCancelHandler(request, reason) {
3775
+ return function () {
3776
+ stopFlowing(request); // eslint-disable-next-line react-internal/prod-error-codes
3777
+
3778
+ abort(request, new Error(reason));
3779
+ };
3780
+ }
3781
+
3021
3782
  function renderToPipeableStream(model, webpackMap, options) {
3022
- var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.context : undefined, options ? options.identifierPrefix : undefined);
3783
+ var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.identifierPrefix : undefined, options ? options.onPostpone : undefined, options ? options.environmentName : undefined);
3023
3784
  var hasStartedFlowing = false;
3024
3785
  startWork(request);
3025
3786
  return {
@@ -3031,6 +3792,8 @@ function renderToPipeableStream(model, webpackMap, options) {
3031
3792
  hasStartedFlowing = true;
3032
3793
  startFlowing(request, destination);
3033
3794
  destination.on('drain', createDrainHandler(destination, request));
3795
+ destination.on('error', createCancelHandler(request, 'The destination stream errored while writing data.'));
3796
+ destination.on('close', createCancelHandler(request, 'The destination stream closed early.'));
3034
3797
  return destination;
3035
3798
  },
3036
3799
  abort: function (reason) {
@@ -3085,7 +3848,8 @@ function decodeReplyFromBusboy(busboyStream, webpackMap) {
3085
3848
  close(response);
3086
3849
  });
3087
3850
  busboyStream.on('error', function (err) {
3088
- reportGlobalError(response, err);
3851
+ reportGlobalError(response, // $FlowFixMe[incompatible-call] types Error and mixed are incompatible
3852
+ err);
3089
3853
  });
3090
3854
  return getRoot(response);
3091
3855
  }
@@ -3098,12 +3862,18 @@ function decodeReply(body, webpackMap) {
3098
3862
  }
3099
3863
 
3100
3864
  var response = createResponse(webpackMap, '', body);
3865
+ var root = getRoot(response);
3101
3866
  close(response);
3102
- return getRoot(response);
3867
+ return root;
3103
3868
  }
3104
3869
 
3870
+ exports.createClientModuleProxy = createClientModuleProxy;
3871
+ exports.decodeAction = decodeAction;
3872
+ exports.decodeFormState = decodeFormState;
3105
3873
  exports.decodeReply = decodeReply;
3106
3874
  exports.decodeReplyFromBusboy = decodeReplyFromBusboy;
3875
+ exports.registerClientReference = registerClientReference;
3876
+ exports.registerServerReference = registerServerReference;
3107
3877
  exports.renderToPipeableStream = renderToPipeableStream;
3108
3878
  })();
3109
3879
  }