@vitejs/plugin-rsc 0.4.34 → 0.5.1

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 (100) hide show
  1. package/dist/{browser-D8OPzpF5.js → browser-B4C0Zb4m.js} +1 -1
  2. package/dist/{browser-CQv7Z3J4.d.ts → browser-C8KlM-b7.d.ts} +2 -2
  3. package/dist/{browser-DwWQeoll.d.ts → browser-CDBRiZjk.d.ts} +1 -1
  4. package/dist/{browser-7NhxQxuk.js → browser-U86erGOy.js} +3 -3
  5. package/dist/browser.d.ts +3 -3
  6. package/dist/browser.js +23 -5
  7. package/dist/chunk-Cdb3zUqJ.js +30 -0
  8. package/dist/{cjs-BamOAUgw.js → cjs-zUv66MZg.js} +3 -3
  9. package/dist/core/browser.d.ts +1 -1
  10. package/dist/core/browser.js +3 -3
  11. package/dist/core/plugin.js +1 -1
  12. package/dist/core/rsc.d.ts +2 -2
  13. package/dist/core/rsc.js +3 -3
  14. package/dist/core/ssr.d.ts +2 -2
  15. package/dist/core/ssr.js +3 -3
  16. package/dist/{dist-DiJnRA1C.js → dist-CNbFy2EZ.js} +1 -1
  17. package/dist/{encryption-runtime-B8xcnJoN.d.ts → encryption-runtime-BDgc4dBr.d.ts} +1 -1
  18. package/dist/{encryption-runtime-DT6dtlC5.js → encryption-runtime-D5_PLt4C.js} +4 -4
  19. package/dist/{encryption-utils-BDwwcMVT.js → encryption-utils-DdqSKS_O.js} +1 -1
  20. package/dist/{index-CPkExgij.d.ts → index-BY8KUQhI.d.ts} +1 -1
  21. package/dist/{index-B04iFwO5.d.ts → index-DJ0AhQ9B.d.ts} +1 -1
  22. package/dist/index.d.ts +2 -2
  23. package/dist/index.js +8 -8
  24. package/dist/picocolors-BRKobevN.js +74 -0
  25. package/dist/{plugin-CZbI4rhS.js → plugin-4UFT-s0w.js} +1 -1
  26. package/dist/{plugin-BLedJFh7.js → plugin-DNwmUjn4.js} +32 -22
  27. package/dist/{plugin-DCLI7Wh8.d.ts → plugin-fbbM1muv.d.ts} +2 -6
  28. package/dist/plugin.d.ts +2 -2
  29. package/dist/plugin.js +8 -8
  30. package/dist/plugins/cjs.js +3 -3
  31. package/dist/react/browser.d.ts +3 -3
  32. package/dist/react/browser.js +4 -4
  33. package/dist/react/rsc.d.ts +3 -3
  34. package/dist/react/rsc.js +4 -4
  35. package/dist/react/ssr.d.ts +3 -3
  36. package/dist/react/ssr.js +4 -4
  37. package/dist/{rpc-CUvSZurk.js → rpc-nwJuNojy.js} +1 -1
  38. package/dist/{rsc-JJjz3Z0i.d.ts → rsc-03j1e3xp.d.ts} +4 -4
  39. package/dist/{rsc-BdCB3621.js → rsc-B_DQ_Sju.js} +2 -2
  40. package/dist/{rsc-3bkzqdsJ.d.ts → rsc-OCbFObYE.d.ts} +2 -2
  41. package/dist/{rsc-GFzFWyhT.js → rsc-bL1QvQCm.js} +3 -3
  42. package/dist/rsc.d.ts +4 -4
  43. package/dist/rsc.js +24 -7
  44. package/dist/{shared-CXg_u-4h.js → shared-C8PSRwR2.js} +1 -1
  45. package/dist/{shared-n-ykEs15.js → shared-DlspEItJ.js} +1 -1
  46. package/dist/{ssr-BrSGyrxe.d.ts → ssr-Dgbl_mOS.d.ts} +1 -1
  47. package/dist/{ssr-Cd4SbAaO.js → ssr-DzY6rnEv.js} +2 -2
  48. package/dist/{ssr-Cm2FP2zD.js → ssr-EH7rBPkK.js} +3 -3
  49. package/dist/{ssr-CMjeQ9AS.d.ts → ssr-fBV4xXen.d.ts} +2 -2
  50. package/dist/ssr.d.ts +3 -3
  51. package/dist/ssr.js +54 -6
  52. package/dist/transforms/index.d.ts +1 -1
  53. package/dist/transforms/index.js +2 -2
  54. package/dist/{transforms-CpF3zNE0.js → transforms-CSPqW3RX.js} +3 -2
  55. package/dist/utils/encryption-runtime.d.ts +1 -1
  56. package/dist/utils/encryption-runtime.js +6 -6
  57. package/dist/utils/rpc.js +1 -1
  58. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.development.js +2964 -774
  59. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.production.js +554 -312
  60. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.edge.development.js +2721 -724
  61. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.edge.production.js +541 -300
  62. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.development.js +2955 -858
  63. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.production.js +652 -332
  64. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2956 -861
  65. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.unbundled.production.js +652 -332
  66. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-plugin.js +6 -2
  67. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.development.js +1931 -713
  68. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.production.js +544 -295
  69. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.development.js +1926 -715
  70. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.production.js +542 -299
  71. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.development.js +2719 -743
  72. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.production.js +725 -338
  73. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2703 -727
  74. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.unbundled.production.js +725 -338
  75. package/dist/vendor/react-server-dom/package.json +3 -3
  76. package/dist/vendor/react-server-dom/server.node.js +3 -1
  77. package/dist/vendor/react-server-dom/server.node.unbundled.js +3 -1
  78. package/dist/vendor/react-server-dom/static.browser.js +1 -3
  79. package/dist/vendor/react-server-dom/static.edge.js +1 -3
  80. package/dist/vendor/react-server-dom/static.node.js +2 -3
  81. package/dist/vendor/react-server-dom/static.node.unbundled.js +1 -3
  82. package/package.json +11 -10
  83. package/types/index.d.ts +0 -4
  84. package/dist/browser--ZREVnM9.js +0 -22
  85. package/dist/client-C7Eok9hc.js +0 -23
  86. package/dist/extra/browser.d.ts +0 -14
  87. package/dist/extra/browser.js +0 -88
  88. package/dist/extra/rsc.d.ts +0 -2
  89. package/dist/extra/rsc.js +0 -56
  90. package/dist/extra/ssr.d.ts +0 -14
  91. package/dist/extra/ssr.js +0 -37
  92. package/dist/rsc-CiAoLCx8.js +0 -21
  93. package/dist/rsc-c22DF1A7.d.ts +0 -16
  94. package/dist/rsc-html-stream/browser.d.ts +0 -5
  95. package/dist/rsc-html-stream/browser.js +0 -8
  96. package/dist/rsc-html-stream/ssr.d.ts +0 -7
  97. package/dist/rsc-html-stream/ssr.js +0 -8
  98. package/dist/server-DMhFuTz_.js +0 -72
  99. package/dist/ssr-BQwZitKq.js +0 -53
  100. package/types/virtual.d.ts +0 -5
@@ -127,6 +127,8 @@ var PROMISE_PROTOTYPE = Promise.prototype,
127
127
  return;
128
128
  case "defaultProps":
129
129
  return;
130
+ case "_debugInfo":
131
+ return;
130
132
  case "toJSON":
131
133
  return;
132
134
  case Symbol.toPrimitive:
@@ -164,6 +166,8 @@ function getReference(target, name) {
164
166
  return target.name;
165
167
  case "defaultProps":
166
168
  return;
169
+ case "_debugInfo":
170
+ return;
167
171
  case "toJSON":
168
172
  return;
169
173
  case Symbol.toPrimitive:
@@ -385,15 +389,108 @@ function trimOptions(options) {
385
389
  ((hasProperties = !0), (trimmed[key] = options[key]));
386
390
  return hasProperties ? trimmed : null;
387
391
  }
392
+ function getChildFormatContext(parentContext, type, props) {
393
+ switch (type) {
394
+ case "img":
395
+ type = props.src;
396
+ var srcSet = props.srcSet;
397
+ if (
398
+ !(
399
+ "lazy" === props.loading ||
400
+ (!type && !srcSet) ||
401
+ ("string" !== typeof type && null != type) ||
402
+ ("string" !== typeof srcSet && null != srcSet) ||
403
+ "low" === props.fetchPriority ||
404
+ parentContext & 3
405
+ ) &&
406
+ ("string" !== typeof type ||
407
+ ":" !== type[4] ||
408
+ ("d" !== type[0] && "D" !== type[0]) ||
409
+ ("a" !== type[1] && "A" !== type[1]) ||
410
+ ("t" !== type[2] && "T" !== type[2]) ||
411
+ ("a" !== type[3] && "A" !== type[3])) &&
412
+ ("string" !== typeof srcSet ||
413
+ ":" !== srcSet[4] ||
414
+ ("d" !== srcSet[0] && "D" !== srcSet[0]) ||
415
+ ("a" !== srcSet[1] && "A" !== srcSet[1]) ||
416
+ ("t" !== srcSet[2] && "T" !== srcSet[2]) ||
417
+ ("a" !== srcSet[3] && "A" !== srcSet[3]))
418
+ ) {
419
+ var sizes = "string" === typeof props.sizes ? props.sizes : void 0;
420
+ var input = props.crossOrigin;
421
+ preload(type || "", "image", {
422
+ imageSrcSet: srcSet,
423
+ imageSizes: sizes,
424
+ crossOrigin:
425
+ "string" === typeof input
426
+ ? "use-credentials" === input
427
+ ? input
428
+ : ""
429
+ : void 0,
430
+ integrity: props.integrity,
431
+ type: props.type,
432
+ fetchPriority: props.fetchPriority,
433
+ referrerPolicy: props.referrerPolicy
434
+ });
435
+ }
436
+ return parentContext;
437
+ case "link":
438
+ type = props.rel;
439
+ srcSet = props.href;
440
+ if (
441
+ !(
442
+ parentContext & 1 ||
443
+ null != props.itemProp ||
444
+ "string" !== typeof type ||
445
+ "string" !== typeof srcSet ||
446
+ "" === srcSet
447
+ )
448
+ )
449
+ switch (type) {
450
+ case "preload":
451
+ preload(srcSet, props.as, {
452
+ crossOrigin: props.crossOrigin,
453
+ integrity: props.integrity,
454
+ nonce: props.nonce,
455
+ type: props.type,
456
+ fetchPriority: props.fetchPriority,
457
+ referrerPolicy: props.referrerPolicy,
458
+ imageSrcSet: props.imageSrcSet,
459
+ imageSizes: props.imageSizes,
460
+ media: props.media
461
+ });
462
+ break;
463
+ case "modulepreload":
464
+ preloadModule$1(srcSet, {
465
+ as: props.as,
466
+ crossOrigin: props.crossOrigin,
467
+ integrity: props.integrity,
468
+ nonce: props.nonce
469
+ });
470
+ break;
471
+ case "stylesheet":
472
+ preload(srcSet, "stylesheet", {
473
+ crossOrigin: props.crossOrigin,
474
+ integrity: props.integrity,
475
+ nonce: props.nonce,
476
+ type: props.type,
477
+ fetchPriority: props.fetchPriority,
478
+ referrerPolicy: props.referrerPolicy,
479
+ media: props.media
480
+ });
481
+ }
482
+ return parentContext;
483
+ case "picture":
484
+ return parentContext | 2;
485
+ case "noscript":
486
+ return parentContext | 1;
487
+ default:
488
+ return parentContext;
489
+ }
490
+ }
388
491
  var supportsRequestStorage = "function" === typeof AsyncLocalStorage,
389
- requestStorage = supportsRequestStorage ? new AsyncLocalStorage() : null;
390
- "object" === typeof async_hooks
391
- ? async_hooks.createHook
392
- : function () {
393
- return { enable: function () {}, disable: function () {} };
394
- };
395
- "object" === typeof async_hooks ? async_hooks.executionAsyncId : null;
396
- var TEMPORARY_REFERENCE_TAG = Symbol.for("react.temporary.reference"),
492
+ requestStorage = supportsRequestStorage ? new AsyncLocalStorage() : null,
493
+ TEMPORARY_REFERENCE_TAG = Symbol.for("react.temporary.reference"),
397
494
  proxyHandlers = {
398
495
  get: function (target, name) {
399
496
  switch (name) {
@@ -405,6 +502,8 @@ var TEMPORARY_REFERENCE_TAG = Symbol.for("react.temporary.reference"),
405
502
  return;
406
503
  case "defaultProps":
407
504
  return;
505
+ case "_debugInfo":
506
+ return;
408
507
  case "toJSON":
409
508
  return;
410
509
  case Symbol.toPrimitive:
@@ -415,6 +514,8 @@ var TEMPORARY_REFERENCE_TAG = Symbol.for("react.temporary.reference"),
415
514
  throw Error(
416
515
  "Cannot render a Client Context Provider on the Server. Instead, you can export a Client Component wrapper that itself renders a Client Context Provider."
417
516
  );
517
+ case "then":
518
+ return;
418
519
  }
419
520
  throw Error(
420
521
  "Cannot access " +
@@ -441,15 +542,15 @@ function createTemporaryReference(temporaryReferences, id) {
441
542
  temporaryReferences.set(reference, id);
442
543
  return reference;
443
544
  }
545
+ function noop() {}
444
546
  var SuspenseException = Error(
445
547
  "Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary, or call the promise's `.catch` method and pass the result to `use`."
446
548
  );
447
- function noop$1() {}
448
549
  function trackUsedThenable(thenableState, thenable, index) {
449
550
  index = thenableState[index];
450
551
  void 0 === index
451
552
  ? thenableState.push(thenable)
452
- : index !== thenable && (thenable.then(noop$1, noop$1), (thenable = index));
553
+ : index !== thenable && (thenable.then(noop, noop), (thenable = index));
453
554
  switch (thenable.status) {
454
555
  case "fulfilled":
455
556
  return thenable.value;
@@ -457,7 +558,7 @@ function trackUsedThenable(thenableState, thenable, index) {
457
558
  throw thenable.reason;
458
559
  default:
459
560
  "string" === typeof thenable.status
460
- ? thenable.then(noop$1, noop$1)
561
+ ? thenable.then(noop, noop)
461
562
  : ((thenableState = thenable),
462
563
  (thenableState.status = "pending"),
463
564
  thenableState.then(
@@ -539,6 +640,7 @@ var HooksDispatcher = {
539
640
  return unsupportedRefresh;
540
641
  }
541
642
  };
643
+ HooksDispatcher.useEffectEvent = unsupportedHook;
542
644
  function unsupportedHook() {
543
645
  throw Error("This Hook is not supported in Server Components.");
544
646
  }
@@ -552,7 +654,7 @@ function useId() {
552
654
  if (null === currentRequest$1)
553
655
  throw Error("useId can only be used while React is rendering");
554
656
  var id = currentRequest$1.identifierCount++;
555
- return ":" + currentRequest$1.identifierPrefix + "S" + id.toString(32) + ":";
657
+ return "_" + currentRequest$1.identifierPrefix + "S_" + id.toString(32) + "_";
556
658
  }
557
659
  function use(usable) {
558
660
  if (
@@ -585,6 +687,10 @@ var DefaultAsyncDispatcher = {
585
687
  ((entry = resourceType()),
586
688
  JSCompiler_inline_result.set(resourceType, entry));
587
689
  return entry;
690
+ },
691
+ cacheSignal: function () {
692
+ var request = resolveRequest();
693
+ return request ? request.cacheController.signal : null;
588
694
  }
589
695
  },
590
696
  ReactSharedInternalsServer =
@@ -596,11 +702,8 @@ if (!ReactSharedInternalsServer)
596
702
  var isArrayImpl = Array.isArray,
597
703
  getPrototypeOf = Object.getPrototypeOf;
598
704
  function objectName(object) {
599
- return Object.prototype.toString
600
- .call(object)
601
- .replace(/^\[object (.*)\]$/, function (m, p0) {
602
- return p0;
603
- });
705
+ object = Object.prototype.toString.call(object);
706
+ return object.slice(8, object.length - 1);
604
707
  }
605
708
  function describeValueForErrorMessage(value) {
606
709
  switch (typeof value) {
@@ -704,24 +807,22 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
704
807
  "\n " + str + "\n " + objectOrArray)
705
808
  : "\n " + str;
706
809
  }
707
- var ObjectPrototype = Object.prototype,
810
+ var hasOwnProperty = Object.prototype.hasOwnProperty,
811
+ ObjectPrototype = Object.prototype,
708
812
  stringify = JSON.stringify;
709
813
  function defaultErrorHandler(error) {
710
814
  console.error(error);
711
815
  }
712
- function defaultPostponeHandler() {}
713
816
  function RequestInstance(
714
817
  type,
715
818
  model,
716
819
  bundlerConfig,
717
820
  onError,
718
- identifierPrefix,
719
821
  onPostpone,
720
- temporaryReferences,
721
- environmentName,
722
- filterStackFrame,
723
822
  onAllReady,
724
- onFatalError
823
+ onFatalError,
824
+ identifierPrefix,
825
+ temporaryReferences
725
826
  ) {
726
827
  if (
727
828
  null !== ReactSharedInternalsServer.A &&
@@ -729,20 +830,20 @@ function RequestInstance(
729
830
  )
730
831
  throw Error("Currently React only supports one RSC renderer at a time.");
731
832
  ReactSharedInternalsServer.A = DefaultAsyncDispatcher;
732
- filterStackFrame = new Set();
733
- environmentName = [];
734
- var hints = new Set();
833
+ var abortSet = new Set(),
834
+ pingedTasks = [],
835
+ hints = new Set();
735
836
  this.type = type;
736
837
  this.status = 10;
737
838
  this.flushScheduled = !1;
738
839
  this.destination = this.fatalError = null;
739
840
  this.bundlerConfig = bundlerConfig;
740
841
  this.cache = new Map();
842
+ this.cacheController = new AbortController();
741
843
  this.pendingChunks = this.nextChunkId = 0;
742
844
  this.hints = hints;
743
- this.abortListeners = new Set();
744
- this.abortableTasks = filterStackFrame;
745
- this.pingedTasks = environmentName;
845
+ this.abortableTasks = abortSet;
846
+ this.pingedTasks = pingedTasks;
746
847
  this.completedImportChunks = [];
747
848
  this.completedHintChunks = [];
748
849
  this.completedRegularChunks = [];
@@ -756,13 +857,12 @@ function RequestInstance(
756
857
  this.identifierCount = 1;
757
858
  this.taintCleanupQueue = [];
758
859
  this.onError = void 0 === onError ? defaultErrorHandler : onError;
759
- this.onPostpone = void 0 === onPostpone ? defaultPostponeHandler : onPostpone;
860
+ this.onPostpone = void 0 === onPostpone ? noop : onPostpone;
760
861
  this.onAllReady = onAllReady;
761
862
  this.onFatalError = onFatalError;
762
- type = createTask(this, model, null, !1, filterStackFrame);
763
- environmentName.push(type);
863
+ type = createTask(this, model, null, !1, 0, abortSet);
864
+ pingedTasks.push(type);
764
865
  }
765
- function noop() {}
766
866
  var currentRequest = null;
767
867
  function resolveRequest() {
768
868
  if (currentRequest) return currentRequest;
@@ -775,9 +875,10 @@ function resolveRequest() {
775
875
  function serializeThenable(request, task, thenable) {
776
876
  var newTask = createTask(
777
877
  request,
778
- null,
878
+ thenable,
779
879
  task.keyPath,
780
880
  task.implicitSlot,
881
+ task.formatContext,
781
882
  request.abortableTasks
782
883
  );
783
884
  switch (thenable.status) {
@@ -791,9 +892,11 @@ function serializeThenable(request, task, thenable) {
791
892
  if (12 === request.status)
792
893
  return (
793
894
  request.abortableTasks.delete(newTask),
794
- (newTask.status = 3),
795
- (task = stringify(serializeByValueID(request.fatalError))),
796
- emitModelChunk(request, newTask.id, task),
895
+ 21 === request.type
896
+ ? (haltTask(newTask), finishHaltedTask(newTask, request))
897
+ : ((task = request.fatalError),
898
+ abortTask(newTask),
899
+ finishAbortedTask(newTask, request, task)),
797
900
  newTask.id
798
901
  );
799
902
  "string" !== typeof thenable.status &&
@@ -824,39 +927,48 @@ function serializeThenable(request, task, thenable) {
824
927
  }
825
928
  function serializeReadableStream(request, task, stream) {
826
929
  function progress(entry) {
827
- if (!aborted)
930
+ if (0 === streamTask.status)
828
931
  if (entry.done)
829
- request.abortListeners.delete(abortStream),
932
+ (streamTask.status = 1),
830
933
  (entry = streamTask.id.toString(16) + ":C\n"),
831
934
  request.completedRegularChunks.push(stringToChunk(entry)),
935
+ request.abortableTasks.delete(streamTask),
936
+ request.cacheController.signal.removeEventListener(
937
+ "abort",
938
+ abortStream
939
+ ),
832
940
  enqueueFlush(request),
833
- (aborted = !0);
941
+ callOnAllReadyIfReady(request);
834
942
  else
835
943
  try {
836
944
  (streamTask.model = entry.value),
837
945
  request.pendingChunks++,
838
- emitChunk(request, streamTask, streamTask.model),
946
+ tryStreamTask(request, streamTask),
839
947
  enqueueFlush(request),
840
948
  reader.read().then(progress, error);
841
- } catch (x$7) {
842
- error(x$7);
949
+ } catch (x$8) {
950
+ error(x$8);
843
951
  }
844
952
  }
845
953
  function error(reason) {
846
- aborted ||
847
- ((aborted = !0),
848
- request.abortListeners.delete(abortStream),
954
+ 0 === streamTask.status &&
955
+ (request.cacheController.signal.removeEventListener("abort", abortStream),
849
956
  erroredTask(request, streamTask, reason),
850
957
  enqueueFlush(request),
851
958
  reader.cancel(reason).then(error, error));
852
959
  }
853
- function abortStream(reason) {
854
- aborted ||
855
- ((aborted = !0),
856
- request.abortListeners.delete(abortStream),
857
- erroredTask(request, streamTask, reason),
858
- enqueueFlush(request),
859
- reader.cancel(reason).then(error, error));
960
+ function abortStream() {
961
+ if (0 === streamTask.status) {
962
+ var signal = request.cacheController.signal;
963
+ signal.removeEventListener("abort", abortStream);
964
+ signal = signal.reason;
965
+ 21 === request.type
966
+ ? (request.abortableTasks.delete(streamTask),
967
+ haltTask(streamTask),
968
+ finishHaltedTask(streamTask, request))
969
+ : (erroredTask(request, streamTask, signal), enqueueFlush(request));
970
+ reader.cancel(signal).then(error, error);
971
+ }
860
972
  }
861
973
  var supportsBYOB = stream.supportsBYOB;
862
974
  if (void 0 === supportsBYOB)
@@ -871,27 +983,30 @@ function serializeReadableStream(request, task, stream) {
871
983
  task.model,
872
984
  task.keyPath,
873
985
  task.implicitSlot,
986
+ task.formatContext,
874
987
  request.abortableTasks
875
988
  );
876
- request.abortableTasks.delete(streamTask);
877
989
  request.pendingChunks++;
878
990
  task = streamTask.id.toString(16) + ":" + (supportsBYOB ? "r" : "R") + "\n";
879
991
  request.completedRegularChunks.push(stringToChunk(task));
880
- var aborted = !1;
881
- request.abortListeners.add(abortStream);
992
+ request.cacheController.signal.addEventListener("abort", abortStream);
882
993
  reader.read().then(progress, error);
883
994
  return serializeByValueID(streamTask.id);
884
995
  }
885
996
  function serializeAsyncIterable(request, task, iterable, iterator) {
886
997
  function progress(entry) {
887
- if (!aborted)
998
+ if (0 === streamTask.status)
888
999
  if (entry.done) {
889
- request.abortListeners.delete(abortIterable);
1000
+ streamTask.status = 1;
890
1001
  if (void 0 === entry.value)
891
1002
  var endStreamRow = streamTask.id.toString(16) + ":C\n";
892
1003
  else
893
1004
  try {
894
- var chunkId = outlineModel(request, entry.value);
1005
+ var chunkId = outlineModelWithFormatContext(
1006
+ request,
1007
+ entry.value,
1008
+ 0
1009
+ );
895
1010
  endStreamRow =
896
1011
  streamTask.id.toString(16) +
897
1012
  ":C" +
@@ -902,36 +1017,49 @@ function serializeAsyncIterable(request, task, iterable, iterator) {
902
1017
  return;
903
1018
  }
904
1019
  request.completedRegularChunks.push(stringToChunk(endStreamRow));
1020
+ request.abortableTasks.delete(streamTask);
1021
+ request.cacheController.signal.removeEventListener(
1022
+ "abort",
1023
+ abortIterable
1024
+ );
905
1025
  enqueueFlush(request);
906
- aborted = !0;
1026
+ callOnAllReadyIfReady(request);
907
1027
  } else
908
1028
  try {
909
1029
  (streamTask.model = entry.value),
910
1030
  request.pendingChunks++,
911
- emitChunk(request, streamTask, streamTask.model),
1031
+ tryStreamTask(request, streamTask),
912
1032
  enqueueFlush(request),
913
1033
  iterator.next().then(progress, error);
914
- } catch (x$8) {
915
- error(x$8);
1034
+ } catch (x$9) {
1035
+ error(x$9);
916
1036
  }
917
1037
  }
918
1038
  function error(reason) {
919
- aborted ||
920
- ((aborted = !0),
921
- request.abortListeners.delete(abortIterable),
1039
+ 0 === streamTask.status &&
1040
+ (request.cacheController.signal.removeEventListener(
1041
+ "abort",
1042
+ abortIterable
1043
+ ),
922
1044
  erroredTask(request, streamTask, reason),
923
1045
  enqueueFlush(request),
924
1046
  "function" === typeof iterator.throw &&
925
1047
  iterator.throw(reason).then(error, error));
926
1048
  }
927
- function abortIterable(reason) {
928
- aborted ||
929
- ((aborted = !0),
930
- request.abortListeners.delete(abortIterable),
931
- erroredTask(request, streamTask, reason),
932
- enqueueFlush(request),
1049
+ function abortIterable() {
1050
+ if (0 === streamTask.status) {
1051
+ var signal = request.cacheController.signal;
1052
+ signal.removeEventListener("abort", abortIterable);
1053
+ var reason = signal.reason;
1054
+ 21 === request.type
1055
+ ? (request.abortableTasks.delete(streamTask),
1056
+ haltTask(streamTask),
1057
+ finishHaltedTask(streamTask, request))
1058
+ : (erroredTask(request, streamTask, signal.reason),
1059
+ enqueueFlush(request));
933
1060
  "function" === typeof iterator.throw &&
934
- iterator.throw(reason).then(error, error));
1061
+ iterator.throw(reason).then(error, error);
1062
+ }
935
1063
  }
936
1064
  iterable = iterable === iterator;
937
1065
  var streamTask = createTask(
@@ -939,14 +1067,13 @@ function serializeAsyncIterable(request, task, iterable, iterator) {
939
1067
  task.model,
940
1068
  task.keyPath,
941
1069
  task.implicitSlot,
1070
+ task.formatContext,
942
1071
  request.abortableTasks
943
1072
  );
944
- request.abortableTasks.delete(streamTask);
945
1073
  request.pendingChunks++;
946
1074
  task = streamTask.id.toString(16) + ":" + (iterable ? "x" : "X") + "\n";
947
1075
  request.completedRegularChunks.push(stringToChunk(task));
948
- var aborted = !1;
949
- request.abortListeners.add(abortIterable);
1076
+ request.cacheController.signal.addEventListener("abort", abortIterable);
950
1077
  iterator.next().then(progress, error);
951
1078
  return serializeByValueID(streamTask.id);
952
1079
  }
@@ -961,9 +1088,10 @@ function readThenable(thenable) {
961
1088
  if ("rejected" === thenable.status) throw thenable.reason;
962
1089
  throw thenable;
963
1090
  }
964
- function createLazyWrapperAroundWakeable(wakeable) {
1091
+ function createLazyWrapperAroundWakeable(request, task, wakeable) {
965
1092
  switch (wakeable.status) {
966
1093
  case "fulfilled":
1094
+ return wakeable.value;
967
1095
  case "rejected":
968
1096
  break;
969
1097
  default:
@@ -992,9 +1120,7 @@ function processServerComponentReturnValue(request, task, Component, result) {
992
1120
  )
993
1121
  return result;
994
1122
  if ("function" === typeof result.then)
995
- return "fulfilled" === result.status
996
- ? result.value
997
- : createLazyWrapperAroundWakeable(result);
1123
+ return createLazyWrapperAroundWakeable(request, task, result);
998
1124
  var iteratorFn = getIteratorFn(result);
999
1125
  return iteratorFn
1000
1126
  ? ((request = {}),
@@ -1049,6 +1175,19 @@ function renderFragment(request, task, children) {
1049
1175
  task.implicitSlot ? [request] : request)
1050
1176
  : children;
1051
1177
  }
1178
+ var serializedSize = 0;
1179
+ function deferTask(request, task) {
1180
+ task = createTask(
1181
+ request,
1182
+ task.model,
1183
+ task.keyPath,
1184
+ task.implicitSlot,
1185
+ task.formatContext,
1186
+ request.abortableTasks
1187
+ );
1188
+ pingTask(request, task);
1189
+ return serializeLazyID(task.id);
1190
+ }
1052
1191
  function renderElement(request, task, type, key, ref, props) {
1053
1192
  if (null !== ref && void 0 !== ref)
1054
1193
  throw Error(
@@ -1090,6 +1229,13 @@ function renderElement(request, task, type, key, ref, props) {
1090
1229
  case REACT_MEMO_TYPE:
1091
1230
  return renderElement(request, task, type.type, key, ref, props);
1092
1231
  }
1232
+ else
1233
+ "string" === typeof type &&
1234
+ ((ref = task.formatContext),
1235
+ (init = getChildFormatContext(ref, type, props)),
1236
+ ref !== init &&
1237
+ null != props.children &&
1238
+ outlineModelWithFormatContext(request, props.children, init));
1093
1239
  request = key;
1094
1240
  key = task.keyPath;
1095
1241
  null === request
@@ -1112,7 +1258,14 @@ function pingTask(request, task) {
1112
1258
  return performWork(request);
1113
1259
  }, 0));
1114
1260
  }
1115
- function createTask(request, model, keyPath, implicitSlot, abortSet) {
1261
+ function createTask(
1262
+ request,
1263
+ model,
1264
+ keyPath,
1265
+ implicitSlot,
1266
+ formatContext,
1267
+ abortSet
1268
+ ) {
1116
1269
  request.pendingChunks++;
1117
1270
  var id = request.nextChunkId++;
1118
1271
  "object" !== typeof model ||
@@ -1126,10 +1279,12 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1126
1279
  model: model,
1127
1280
  keyPath: keyPath,
1128
1281
  implicitSlot: implicitSlot,
1282
+ formatContext: formatContext,
1129
1283
  ping: function () {
1130
1284
  return pingTask(request, task);
1131
1285
  },
1132
1286
  toJSON: function (parentPropertyName, value) {
1287
+ serializedSize += parentPropertyName.length;
1133
1288
  var prevKeyPath = task.keyPath,
1134
1289
  prevImplicitSlot = task.implicitSlot;
1135
1290
  try {
@@ -1151,10 +1306,16 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1151
1306
  12 === request.status)
1152
1307
  )
1153
1308
  (task.status = 3),
1154
- (prevKeyPath = request.fatalError),
1155
- (JSCompiler_inline_result = parentPropertyName
1156
- ? "$L" + prevKeyPath.toString(16)
1157
- : serializeByValueID(prevKeyPath));
1309
+ 21 === request.type
1310
+ ? ((prevKeyPath = request.nextChunkId++),
1311
+ (prevKeyPath = parentPropertyName
1312
+ ? serializeLazyID(prevKeyPath)
1313
+ : serializeByValueID(prevKeyPath)),
1314
+ (JSCompiler_inline_result = prevKeyPath))
1315
+ : ((prevKeyPath = request.fatalError),
1316
+ (JSCompiler_inline_result = parentPropertyName
1317
+ ? serializeLazyID(prevKeyPath)
1318
+ : serializeByValueID(prevKeyPath)));
1158
1319
  else if (
1159
1320
  ((value =
1160
1321
  thrownValue === SuspenseException
@@ -1169,6 +1330,7 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1169
1330
  task.model,
1170
1331
  task.keyPath,
1171
1332
  task.implicitSlot,
1333
+ task.formatContext,
1172
1334
  request.abortableTasks
1173
1335
  );
1174
1336
  var ping = JSCompiler_inline_result.ping;
@@ -1178,7 +1340,7 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1178
1340
  task.keyPath = prevKeyPath;
1179
1341
  task.implicitSlot = prevImplicitSlot;
1180
1342
  JSCompiler_inline_result = parentPropertyName
1181
- ? "$L" + JSCompiler_inline_result.id.toString(16)
1343
+ ? serializeLazyID(JSCompiler_inline_result.id)
1182
1344
  : serializeByValueID(JSCompiler_inline_result.id);
1183
1345
  } else
1184
1346
  (task.keyPath = prevKeyPath),
@@ -1188,7 +1350,7 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1188
1350
  (prevImplicitSlot = logRecoverableError(request, value, task)),
1189
1351
  emitErrorChunk(request, prevKeyPath, prevImplicitSlot),
1190
1352
  (JSCompiler_inline_result = parentPropertyName
1191
- ? "$L" + prevKeyPath.toString(16)
1353
+ ? serializeLazyID(prevKeyPath)
1192
1354
  : serializeByValueID(prevKeyPath));
1193
1355
  }
1194
1356
  return JSCompiler_inline_result;
@@ -1201,6 +1363,9 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1201
1363
  function serializeByValueID(id) {
1202
1364
  return "$" + id.toString(16);
1203
1365
  }
1366
+ function serializeLazyID(id) {
1367
+ return "$L" + id.toString(16);
1368
+ }
1204
1369
  function encodeReferenceChunk(request, id, reference) {
1205
1370
  request = stringify(reference);
1206
1371
  id = id.toString(16) + ":" + request + "\n";
@@ -1219,7 +1384,7 @@ function serializeClientReference(
1219
1384
  existingId = writtenClientReferences.get(clientReferenceKey);
1220
1385
  if (void 0 !== existingId)
1221
1386
  return parent[0] === REACT_ELEMENT_TYPE && "1" === parentPropertyName
1222
- ? "$L" + existingId.toString(16)
1387
+ ? serializeLazyID(existingId)
1223
1388
  : serializeByValueID(existingId);
1224
1389
  try {
1225
1390
  var config = request.bundlerConfig,
@@ -1257,7 +1422,7 @@ function serializeClientReference(
1257
1422
  request.completedImportChunks.push(processedChunk);
1258
1423
  writtenClientReferences.set(clientReferenceKey, importId);
1259
1424
  return parent[0] === REACT_ELEMENT_TYPE && "1" === parentPropertyName
1260
- ? "$L" + importId.toString(16)
1425
+ ? serializeLazyID(importId)
1261
1426
  : serializeByValueID(importId);
1262
1427
  } catch (x) {
1263
1428
  return (
@@ -1269,23 +1434,29 @@ function serializeClientReference(
1269
1434
  );
1270
1435
  }
1271
1436
  }
1272
- function outlineModel(request, value) {
1273
- value = createTask(request, value, null, !1, request.abortableTasks);
1437
+ function outlineModelWithFormatContext(request, value, formatContext) {
1438
+ value = createTask(
1439
+ request,
1440
+ value,
1441
+ null,
1442
+ !1,
1443
+ formatContext,
1444
+ request.abortableTasks
1445
+ );
1274
1446
  retryTask(request, value);
1275
1447
  return value.id;
1276
1448
  }
1277
1449
  function serializeTypedArray(request, tag, typedArray) {
1278
1450
  request.pendingChunks++;
1279
1451
  var bufferId = request.nextChunkId++;
1280
- emitTypedArrayChunk(request, bufferId, tag, typedArray);
1452
+ emitTypedArrayChunk(request, bufferId, tag, typedArray, !1);
1281
1453
  return serializeByValueID(bufferId);
1282
1454
  }
1283
1455
  function serializeBlob(request, blob) {
1284
1456
  function progress(entry) {
1285
- if (!aborted)
1457
+ if (0 === newTask.status)
1286
1458
  if (entry.done)
1287
- request.abortListeners.delete(abortBlob),
1288
- (aborted = !0),
1459
+ request.cacheController.signal.removeEventListener("abort", abortBlob),
1289
1460
  pingTask(request, newTask);
1290
1461
  else
1291
1462
  return (
@@ -1293,26 +1464,29 @@ function serializeBlob(request, blob) {
1293
1464
  );
1294
1465
  }
1295
1466
  function error(reason) {
1296
- aborted ||
1297
- ((aborted = !0),
1298
- request.abortListeners.delete(abortBlob),
1467
+ 0 === newTask.status &&
1468
+ (request.cacheController.signal.removeEventListener("abort", abortBlob),
1299
1469
  erroredTask(request, newTask, reason),
1300
1470
  enqueueFlush(request),
1301
1471
  reader.cancel(reason).then(error, error));
1302
1472
  }
1303
- function abortBlob(reason) {
1304
- aborted ||
1305
- ((aborted = !0),
1306
- request.abortListeners.delete(abortBlob),
1307
- erroredTask(request, newTask, reason),
1308
- enqueueFlush(request),
1309
- reader.cancel(reason).then(error, error));
1473
+ function abortBlob() {
1474
+ if (0 === newTask.status) {
1475
+ var signal = request.cacheController.signal;
1476
+ signal.removeEventListener("abort", abortBlob);
1477
+ signal = signal.reason;
1478
+ 21 === request.type
1479
+ ? (request.abortableTasks.delete(newTask),
1480
+ haltTask(newTask),
1481
+ finishHaltedTask(newTask, request))
1482
+ : (erroredTask(request, newTask, signal), enqueueFlush(request));
1483
+ reader.cancel(signal).then(error, error);
1484
+ }
1310
1485
  }
1311
1486
  var model = [blob.type],
1312
- newTask = createTask(request, model, null, !1, request.abortableTasks),
1313
- reader = blob.stream().getReader(),
1314
- aborted = !1;
1315
- request.abortListeners.add(abortBlob);
1487
+ newTask = createTask(request, model, null, !1, 0, request.abortableTasks),
1488
+ reader = blob.stream().getReader();
1489
+ request.cacheController.signal.addEventListener("abort", abortBlob);
1316
1490
  reader.read().then(progress).catch(error);
1317
1491
  return "$B" + newTask.id.toString(16);
1318
1492
  }
@@ -1344,6 +1518,7 @@ function renderModelDestructive(
1344
1518
  ((elementReference = parent + ":" + parentPropertyName),
1345
1519
  writtenObjects.set(value, elementReference)));
1346
1520
  }
1521
+ if (3200 < serializedSize) return deferTask(request, task);
1347
1522
  parentPropertyName = value.props;
1348
1523
  parent = parentPropertyName.ref;
1349
1524
  request = renderElement(
@@ -1361,6 +1536,7 @@ function renderModelDestructive(
1361
1536
  writtenObjects.set(request, elementReference));
1362
1537
  return request;
1363
1538
  case REACT_LAZY_TYPE:
1539
+ if (3200 < serializedSize) return deferTask(request, task);
1364
1540
  task.thenableState = null;
1365
1541
  parentPropertyName = value._init;
1366
1542
  value = parentPropertyName(value._payload);
@@ -1398,8 +1574,11 @@ function renderModelDestructive(
1398
1574
  return request;
1399
1575
  }
1400
1576
  if (void 0 !== writtenObjects)
1401
- if (modelRoot === value) modelRoot = null;
1402
- else return writtenObjects;
1577
+ if (modelRoot === value) {
1578
+ if (writtenObjects !== serializeByValueID(task.id))
1579
+ return writtenObjects;
1580
+ modelRoot = null;
1581
+ } else return writtenObjects;
1403
1582
  else if (
1404
1583
  -1 === parentPropertyName.indexOf(":") &&
1405
1584
  ((writtenObjects = elementReference.get(parent)),
@@ -1426,17 +1605,17 @@ function renderModelDestructive(
1426
1605
  if (value instanceof Map)
1427
1606
  return (
1428
1607
  (value = Array.from(value)),
1429
- "$Q" + outlineModel(request, value).toString(16)
1608
+ "$Q" + outlineModelWithFormatContext(request, value, 0).toString(16)
1430
1609
  );
1431
1610
  if (value instanceof Set)
1432
1611
  return (
1433
1612
  (value = Array.from(value)),
1434
- "$W" + outlineModel(request, value).toString(16)
1613
+ "$W" + outlineModelWithFormatContext(request, value, 0).toString(16)
1435
1614
  );
1436
1615
  if ("function" === typeof FormData && value instanceof FormData)
1437
1616
  return (
1438
1617
  (value = Array.from(value.entries())),
1439
- "$K" + outlineModel(request, value).toString(16)
1618
+ "$K" + outlineModelWithFormatContext(request, value, 0).toString(16)
1440
1619
  );
1441
1620
  if (value instanceof Error) return "$Z";
1442
1621
  if (value instanceof ArrayBuffer)
@@ -1471,8 +1650,9 @@ function renderModelDestructive(
1471
1650
  return (
1472
1651
  (parentPropertyName = elementReference.call(value)),
1473
1652
  parentPropertyName === value
1474
- ? "$i" +
1475
- outlineModel(request, Array.from(parentPropertyName)).toString(16)
1653
+ ? ((value = Array.from(parentPropertyName)),
1654
+ "$i" +
1655
+ outlineModelWithFormatContext(request, value, 0).toString(16))
1476
1656
  : renderFragment(request, task, Array.from(parentPropertyName))
1477
1657
  );
1478
1658
  if ("function" === typeof ReadableStream && value instanceof ReadableStream)
@@ -1510,6 +1690,7 @@ function renderModelDestructive(
1510
1690
  return value;
1511
1691
  }
1512
1692
  if ("string" === typeof value) {
1693
+ serializedSize += value.length;
1513
1694
  if (
1514
1695
  "Z" === value[value.length - 1] &&
1515
1696
  parent[parentPropertyName] instanceof Date
@@ -1519,7 +1700,7 @@ function renderModelDestructive(
1519
1700
  return (
1520
1701
  request.pendingChunks++,
1521
1702
  (task = request.nextChunkId++),
1522
- emitTextChunk(request, task, value),
1703
+ emitTextChunk(request, task, value, !1),
1523
1704
  serializeByValueID(task)
1524
1705
  );
1525
1706
  request = "$" === value[0] ? "$" + value : value;
@@ -1556,10 +1737,11 @@ function renderModelDestructive(
1556
1737
  null === parentPropertyName
1557
1738
  ? null
1558
1739
  : Promise.resolve(parentPropertyName)),
1559
- (request = outlineModel(request, {
1560
- id: value.$$id,
1561
- bound: parentPropertyName
1562
- })),
1740
+ (request = outlineModelWithFormatContext(
1741
+ request,
1742
+ { id: value.$$id, bound: parentPropertyName },
1743
+ 0
1744
+ )),
1563
1745
  task.set(value, request),
1564
1746
  (request = "$F" + request.toString(16))),
1565
1747
  request
@@ -1640,6 +1822,9 @@ function fatalError(request, error) {
1640
1822
  null !== request.destination
1641
1823
  ? ((request.status = 14), closeWithError(request.destination, error))
1642
1824
  : ((request.status = 13), (request.fatalError = error));
1825
+ request.cacheController.abort(
1826
+ Error("The render was aborted due to a fatal error.", { cause: error })
1827
+ );
1643
1828
  }
1644
1829
  function emitErrorChunk(request, id, digest) {
1645
1830
  digest = { digest: digest };
@@ -1652,74 +1837,76 @@ function emitModelChunk(request, id, json) {
1652
1837
  id = stringToChunk(id);
1653
1838
  request.completedRegularChunks.push(id);
1654
1839
  }
1655
- function emitTypedArrayChunk(request, id, tag, typedArray) {
1656
- request.pendingChunks++;
1657
- var buffer = new Uint8Array(
1840
+ function emitTypedArrayChunk(request, id, tag, typedArray, debug) {
1841
+ debug ? request.pendingDebugChunks++ : request.pendingChunks++;
1842
+ debug = new Uint8Array(
1658
1843
  typedArray.buffer,
1659
1844
  typedArray.byteOffset,
1660
1845
  typedArray.byteLength
1661
1846
  );
1662
- typedArray = 2048 < typedArray.byteLength ? buffer.slice() : buffer;
1663
- buffer = typedArray.byteLength;
1664
- id = id.toString(16) + ":" + tag + buffer.toString(16) + ",";
1847
+ typedArray = 2048 < typedArray.byteLength ? debug.slice() : debug;
1848
+ debug = typedArray.byteLength;
1849
+ id = id.toString(16) + ":" + tag + debug.toString(16) + ",";
1665
1850
  id = stringToChunk(id);
1666
1851
  request.completedRegularChunks.push(id, typedArray);
1667
1852
  }
1668
- function emitTextChunk(request, id, text) {
1853
+ function emitTextChunk(request, id, text, debug) {
1669
1854
  if (null === byteLengthOfChunk)
1670
1855
  throw Error(
1671
1856
  "Existence of byteLengthOfChunk should have already been checked. This is a bug in React."
1672
1857
  );
1673
- request.pendingChunks++;
1858
+ debug ? request.pendingDebugChunks++ : request.pendingChunks++;
1674
1859
  text = stringToChunk(text);
1675
- var binaryLength = text.byteLength;
1676
- id = id.toString(16) + ":T" + binaryLength.toString(16) + ",";
1860
+ debug = text.byteLength;
1861
+ id = id.toString(16) + ":T" + debug.toString(16) + ",";
1677
1862
  id = stringToChunk(id);
1678
1863
  request.completedRegularChunks.push(id, text);
1679
1864
  }
1680
1865
  function emitChunk(request, task, value) {
1681
1866
  var id = task.id;
1682
1867
  "string" === typeof value && null !== byteLengthOfChunk
1683
- ? emitTextChunk(request, id, value)
1868
+ ? emitTextChunk(request, id, value, !1)
1684
1869
  : value instanceof ArrayBuffer
1685
- ? emitTypedArrayChunk(request, id, "A", new Uint8Array(value))
1870
+ ? emitTypedArrayChunk(request, id, "A", new Uint8Array(value), !1)
1686
1871
  : value instanceof Int8Array
1687
- ? emitTypedArrayChunk(request, id, "O", value)
1872
+ ? emitTypedArrayChunk(request, id, "O", value, !1)
1688
1873
  : value instanceof Uint8Array
1689
- ? emitTypedArrayChunk(request, id, "o", value)
1874
+ ? emitTypedArrayChunk(request, id, "o", value, !1)
1690
1875
  : value instanceof Uint8ClampedArray
1691
- ? emitTypedArrayChunk(request, id, "U", value)
1876
+ ? emitTypedArrayChunk(request, id, "U", value, !1)
1692
1877
  : value instanceof Int16Array
1693
- ? emitTypedArrayChunk(request, id, "S", value)
1878
+ ? emitTypedArrayChunk(request, id, "S", value, !1)
1694
1879
  : value instanceof Uint16Array
1695
- ? emitTypedArrayChunk(request, id, "s", value)
1880
+ ? emitTypedArrayChunk(request, id, "s", value, !1)
1696
1881
  : value instanceof Int32Array
1697
- ? emitTypedArrayChunk(request, id, "L", value)
1882
+ ? emitTypedArrayChunk(request, id, "L", value, !1)
1698
1883
  : value instanceof Uint32Array
1699
- ? emitTypedArrayChunk(request, id, "l", value)
1884
+ ? emitTypedArrayChunk(request, id, "l", value, !1)
1700
1885
  : value instanceof Float32Array
1701
- ? emitTypedArrayChunk(request, id, "G", value)
1886
+ ? emitTypedArrayChunk(request, id, "G", value, !1)
1702
1887
  : value instanceof Float64Array
1703
- ? emitTypedArrayChunk(request, id, "g", value)
1888
+ ? emitTypedArrayChunk(request, id, "g", value, !1)
1704
1889
  : value instanceof BigInt64Array
1705
- ? emitTypedArrayChunk(request, id, "M", value)
1890
+ ? emitTypedArrayChunk(request, id, "M", value, !1)
1706
1891
  : value instanceof BigUint64Array
1707
- ? emitTypedArrayChunk(request, id, "m", value)
1892
+ ? emitTypedArrayChunk(request, id, "m", value, !1)
1708
1893
  : value instanceof DataView
1709
- ? emitTypedArrayChunk(request, id, "V", value)
1894
+ ? emitTypedArrayChunk(request, id, "V", value, !1)
1710
1895
  : ((value = stringify(value, task.toJSON)),
1711
1896
  emitModelChunk(request, task.id, value));
1712
1897
  }
1713
1898
  function erroredTask(request, task, error) {
1714
- request.abortableTasks.delete(task);
1715
1899
  task.status = 4;
1716
1900
  error = logRecoverableError(request, error, task);
1717
1901
  emitErrorChunk(request, task.id, error);
1902
+ request.abortableTasks.delete(task);
1903
+ callOnAllReadyIfReady(request);
1718
1904
  }
1719
1905
  var emptyRoot = {};
1720
1906
  function retryTask(request, task) {
1721
1907
  if (0 === task.status) {
1722
1908
  task.status = 5;
1909
+ var parentSerializedSize = serializedSize;
1723
1910
  try {
1724
1911
  modelRoot = task.model;
1725
1912
  var resolvedModel = renderModelDestructive(
@@ -1739,15 +1926,23 @@ function retryTask(request, task) {
1739
1926
  var json = stringify(resolvedModel);
1740
1927
  emitModelChunk(request, task.id, json);
1741
1928
  }
1742
- request.abortableTasks.delete(task);
1743
1929
  task.status = 1;
1930
+ request.abortableTasks.delete(task);
1931
+ callOnAllReadyIfReady(request);
1744
1932
  } catch (thrownValue) {
1745
- if (12 === request.status) {
1746
- request.abortableTasks.delete(task);
1747
- task.status = 3;
1748
- var model = stringify(serializeByValueID(request.fatalError));
1749
- emitModelChunk(request, task.id, model);
1750
- } else {
1933
+ if (12 === request.status)
1934
+ if (
1935
+ (request.abortableTasks.delete(task),
1936
+ (task.status = 0),
1937
+ 21 === request.type)
1938
+ )
1939
+ haltTask(task), finishHaltedTask(task, request);
1940
+ else {
1941
+ var errorId = request.fatalError;
1942
+ abortTask(task);
1943
+ finishAbortedTask(task, request, errorId);
1944
+ }
1945
+ else {
1751
1946
  var x =
1752
1947
  thrownValue === SuspenseException
1753
1948
  ? getSuspendedThenable()
@@ -1764,26 +1959,29 @@ function retryTask(request, task) {
1764
1959
  } else erroredTask(request, task, x);
1765
1960
  }
1766
1961
  } finally {
1962
+ serializedSize = parentSerializedSize;
1767
1963
  }
1768
1964
  }
1769
1965
  }
1966
+ function tryStreamTask(request, task) {
1967
+ var parentSerializedSize = serializedSize;
1968
+ try {
1969
+ emitChunk(request, task, task.model);
1970
+ } finally {
1971
+ serializedSize = parentSerializedSize;
1972
+ }
1973
+ }
1770
1974
  function performWork(request) {
1771
1975
  var prevDispatcher = ReactSharedInternalsServer.H;
1772
1976
  ReactSharedInternalsServer.H = HooksDispatcher;
1773
1977
  var prevRequest = currentRequest;
1774
1978
  currentRequest$1 = currentRequest = request;
1775
- var hadAbortableTasks = 0 < request.abortableTasks.size;
1776
1979
  try {
1777
1980
  var pingedTasks = request.pingedTasks;
1778
1981
  request.pingedTasks = [];
1779
1982
  for (var i = 0; i < pingedTasks.length; i++)
1780
1983
  retryTask(request, pingedTasks[i]);
1781
- null !== request.destination &&
1782
- flushCompletedChunks(request, request.destination);
1783
- if (hadAbortableTasks && 0 === request.abortableTasks.size) {
1784
- var onAllReady = request.onAllReady;
1785
- onAllReady();
1786
- }
1984
+ flushCompletedChunks(request);
1787
1985
  } catch (error) {
1788
1986
  logRecoverableError(request, error, null), fatalError(request, error);
1789
1987
  } finally {
@@ -1792,43 +1990,71 @@ function performWork(request) {
1792
1990
  (currentRequest = prevRequest);
1793
1991
  }
1794
1992
  }
1795
- function flushCompletedChunks(request, destination) {
1796
- currentView = new Uint8Array(2048);
1797
- writtenBytes = 0;
1798
- try {
1799
- for (
1800
- var importsChunks = request.completedImportChunks, i = 0;
1801
- i < importsChunks.length;
1802
- i++
1803
- )
1804
- request.pendingChunks--,
1805
- writeChunkAndReturn(destination, importsChunks[i]);
1806
- importsChunks.splice(0, i);
1807
- var hintChunks = request.completedHintChunks;
1808
- for (i = 0; i < hintChunks.length; i++)
1809
- writeChunkAndReturn(destination, hintChunks[i]);
1810
- hintChunks.splice(0, i);
1811
- var regularChunks = request.completedRegularChunks;
1812
- for (i = 0; i < regularChunks.length; i++)
1813
- request.pendingChunks--,
1814
- writeChunkAndReturn(destination, regularChunks[i]);
1815
- regularChunks.splice(0, i);
1816
- var errorChunks = request.completedErrorChunks;
1817
- for (i = 0; i < errorChunks.length; i++)
1818
- request.pendingChunks--, writeChunkAndReturn(destination, errorChunks[i]);
1819
- errorChunks.splice(0, i);
1820
- } finally {
1821
- (request.flushScheduled = !1),
1822
- currentView &&
1823
- 0 < writtenBytes &&
1824
- (destination.enqueue(
1825
- new Uint8Array(currentView.buffer, 0, writtenBytes)
1826
- ),
1827
- (currentView = null),
1828
- (writtenBytes = 0));
1993
+ function abortTask(task) {
1994
+ 0 === task.status && (task.status = 3);
1995
+ }
1996
+ function finishAbortedTask(task, request, errorId) {
1997
+ 3 === task.status &&
1998
+ ((errorId = serializeByValueID(errorId)),
1999
+ (task = encodeReferenceChunk(request, task.id, errorId)),
2000
+ request.completedErrorChunks.push(task));
2001
+ }
2002
+ function haltTask(task) {
2003
+ 0 === task.status && (task.status = 3);
2004
+ }
2005
+ function finishHaltedTask(task, request) {
2006
+ 3 === task.status && request.pendingChunks--;
2007
+ }
2008
+ function flushCompletedChunks(request) {
2009
+ var destination = request.destination;
2010
+ if (null !== destination) {
2011
+ currentView = new Uint8Array(2048);
2012
+ writtenBytes = 0;
2013
+ try {
2014
+ for (
2015
+ var importsChunks = request.completedImportChunks, i = 0;
2016
+ i < importsChunks.length;
2017
+ i++
2018
+ )
2019
+ request.pendingChunks--,
2020
+ writeChunkAndReturn(destination, importsChunks[i]);
2021
+ importsChunks.splice(0, i);
2022
+ var hintChunks = request.completedHintChunks;
2023
+ for (i = 0; i < hintChunks.length; i++)
2024
+ writeChunkAndReturn(destination, hintChunks[i]);
2025
+ hintChunks.splice(0, i);
2026
+ var regularChunks = request.completedRegularChunks;
2027
+ for (i = 0; i < regularChunks.length; i++)
2028
+ request.pendingChunks--,
2029
+ writeChunkAndReturn(destination, regularChunks[i]);
2030
+ regularChunks.splice(0, i);
2031
+ var errorChunks = request.completedErrorChunks;
2032
+ for (i = 0; i < errorChunks.length; i++)
2033
+ request.pendingChunks--,
2034
+ writeChunkAndReturn(destination, errorChunks[i]);
2035
+ errorChunks.splice(0, i);
2036
+ } finally {
2037
+ (request.flushScheduled = !1),
2038
+ currentView &&
2039
+ 0 < writtenBytes &&
2040
+ (destination.enqueue(
2041
+ new Uint8Array(currentView.buffer, 0, writtenBytes)
2042
+ ),
2043
+ (currentView = null),
2044
+ (writtenBytes = 0));
2045
+ }
1829
2046
  }
1830
2047
  0 === request.pendingChunks &&
1831
- ((request.status = 14), destination.close(), (request.destination = null));
2048
+ (12 > request.status &&
2049
+ request.cacheController.abort(
2050
+ Error(
2051
+ "This render completed successfully. All cacheSignals are now aborted to allow clean up of any unused resources."
2052
+ )
2053
+ ),
2054
+ null !== request.destination &&
2055
+ ((request.status = 14),
2056
+ request.destination.close(),
2057
+ (request.destination = null)));
1832
2058
  }
1833
2059
  function startWork(request) {
1834
2060
  request.flushScheduled = null !== request.destination;
@@ -1850,72 +2076,97 @@ function enqueueFlush(request) {
1850
2076
  ((request.flushScheduled = !0),
1851
2077
  setTimeout(function () {
1852
2078
  request.flushScheduled = !1;
1853
- var destination = request.destination;
1854
- destination && flushCompletedChunks(request, destination);
2079
+ flushCompletedChunks(request);
1855
2080
  }, 0));
1856
2081
  }
2082
+ function callOnAllReadyIfReady(request) {
2083
+ 0 === request.abortableTasks.size &&
2084
+ ((request = request.onAllReady), request());
2085
+ }
1857
2086
  function startFlowing(request, destination) {
1858
2087
  if (13 === request.status)
1859
2088
  (request.status = 14), closeWithError(destination, request.fatalError);
1860
2089
  else if (14 !== request.status && null === request.destination) {
1861
2090
  request.destination = destination;
1862
2091
  try {
1863
- flushCompletedChunks(request, destination);
2092
+ flushCompletedChunks(request);
1864
2093
  } catch (error) {
1865
2094
  logRecoverableError(request, error, null), fatalError(request, error);
1866
2095
  }
1867
2096
  }
1868
2097
  }
1869
- function abort(request, reason) {
2098
+ function finishHalt(request, abortedTasks) {
1870
2099
  try {
1871
- 11 >= request.status && (request.status = 12);
1872
- var abortableTasks = request.abortableTasks;
1873
- if (0 < abortableTasks.size) {
1874
- var error =
1875
- void 0 === reason
1876
- ? Error("The render was aborted by the server without a reason.")
1877
- : "object" === typeof reason &&
1878
- null !== reason &&
1879
- "function" === typeof reason.then
1880
- ? Error("The render was aborted by the server with a promise.")
1881
- : reason,
1882
- digest = logRecoverableError(request, error, null),
1883
- errorId = request.nextChunkId++;
1884
- request.fatalError = errorId;
1885
- request.pendingChunks++;
1886
- emitErrorChunk(request, errorId, digest, error);
1887
- abortableTasks.forEach(function (task) {
1888
- if (5 !== task.status) {
1889
- task.status = 3;
1890
- var ref = serializeByValueID(errorId);
1891
- task = encodeReferenceChunk(request, task.id, ref);
1892
- request.completedErrorChunks.push(task);
2100
+ abortedTasks.forEach(function (task) {
2101
+ return finishHaltedTask(task, request);
2102
+ });
2103
+ var onAllReady = request.onAllReady;
2104
+ onAllReady();
2105
+ flushCompletedChunks(request);
2106
+ } catch (error) {
2107
+ logRecoverableError(request, error, null), fatalError(request, error);
2108
+ }
2109
+ }
2110
+ function finishAbort(request, abortedTasks, errorId) {
2111
+ try {
2112
+ abortedTasks.forEach(function (task) {
2113
+ return finishAbortedTask(task, request, errorId);
2114
+ });
2115
+ var onAllReady = request.onAllReady;
2116
+ onAllReady();
2117
+ flushCompletedChunks(request);
2118
+ } catch (error) {
2119
+ logRecoverableError(request, error, null), fatalError(request, error);
2120
+ }
2121
+ }
2122
+ function abort(request, reason) {
2123
+ if (!(11 < request.status))
2124
+ try {
2125
+ request.status = 12;
2126
+ request.cacheController.abort(reason);
2127
+ var abortableTasks = request.abortableTasks;
2128
+ if (0 < abortableTasks.size)
2129
+ if (21 === request.type)
2130
+ abortableTasks.forEach(function (task) {
2131
+ return haltTask(task, request);
2132
+ }),
2133
+ setTimeout(function () {
2134
+ return finishHalt(request, abortableTasks);
2135
+ }, 0);
2136
+ else {
2137
+ var error =
2138
+ void 0 === reason
2139
+ ? Error(
2140
+ "The render was aborted by the server without a reason."
2141
+ )
2142
+ : "object" === typeof reason &&
2143
+ null !== reason &&
2144
+ "function" === typeof reason.then
2145
+ ? Error(
2146
+ "The render was aborted by the server with a promise."
2147
+ )
2148
+ : reason,
2149
+ digest = logRecoverableError(request, error, null),
2150
+ errorId = request.nextChunkId++;
2151
+ request.fatalError = errorId;
2152
+ request.pendingChunks++;
2153
+ emitErrorChunk(request, errorId, digest, error, !1, null);
2154
+ abortableTasks.forEach(function (task) {
2155
+ return abortTask(task, request, errorId);
2156
+ });
2157
+ setTimeout(function () {
2158
+ return finishAbort(request, abortableTasks, errorId);
2159
+ }, 0);
1893
2160
  }
1894
- });
1895
- abortableTasks.clear();
1896
- var onAllReady = request.onAllReady;
1897
- onAllReady();
1898
- }
1899
- var abortListeners = request.abortListeners;
1900
- if (0 < abortListeners.size) {
1901
- var error$22 =
1902
- void 0 === reason
1903
- ? Error("The render was aborted by the server without a reason.")
1904
- : "object" === typeof reason &&
1905
- null !== reason &&
1906
- "function" === typeof reason.then
1907
- ? Error("The render was aborted by the server with a promise.")
1908
- : reason;
1909
- abortListeners.forEach(function (callback) {
1910
- return callback(error$22);
1911
- });
1912
- abortListeners.clear();
2161
+ else {
2162
+ var onAllReady = request.onAllReady;
2163
+ onAllReady();
2164
+ flushCompletedChunks(request);
2165
+ }
2166
+ } catch (error$23) {
2167
+ logRecoverableError(request, error$23, null),
2168
+ fatalError(request, error$23);
1913
2169
  }
1914
- null !== request.destination &&
1915
- flushCompletedChunks(request, request.destination);
1916
- } catch (error$23) {
1917
- logRecoverableError(request, error$23, null), fatalError(request, error$23);
1918
- }
1919
2170
  }
1920
2171
  function resolveServerReference(bundlerConfig, id) {
1921
2172
  var name = "",
@@ -1992,7 +2243,6 @@ function requireModule(metadata) {
1992
2243
  : moduleExports
1993
2244
  : moduleExports[metadata[2]];
1994
2245
  }
1995
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1996
2246
  function Chunk(status, value, reason, response) {
1997
2247
  this.status = status;
1998
2248
  this.value = value;
@@ -2732,6 +2982,48 @@ exports.decodeReplyFromAsyncIterable = function (
2732
2982
  iterator.next().then(progress, error);
2733
2983
  return getChunk(response, 0);
2734
2984
  };
2985
+ exports.prerender = function (model, webpackMap, options) {
2986
+ return new Promise(function (resolve, reject) {
2987
+ var request = new RequestInstance(
2988
+ 21,
2989
+ model,
2990
+ webpackMap,
2991
+ options ? options.onError : void 0,
2992
+ options ? options.onPostpone : void 0,
2993
+ function () {
2994
+ var stream = new ReadableStream(
2995
+ {
2996
+ type: "bytes",
2997
+ pull: function (controller) {
2998
+ startFlowing(request, controller);
2999
+ },
3000
+ cancel: function (reason) {
3001
+ request.destination = null;
3002
+ abort(request, reason);
3003
+ }
3004
+ },
3005
+ { highWaterMark: 0 }
3006
+ );
3007
+ resolve({ prelude: stream });
3008
+ },
3009
+ reject,
3010
+ options ? options.identifierPrefix : void 0,
3011
+ options ? options.temporaryReferences : void 0
3012
+ );
3013
+ if (options && options.signal) {
3014
+ var signal = options.signal;
3015
+ if (signal.aborted) abort(request, signal.reason);
3016
+ else {
3017
+ var listener = function () {
3018
+ abort(request, signal.reason);
3019
+ signal.removeEventListener("abort", listener);
3020
+ };
3021
+ signal.addEventListener("abort", listener);
3022
+ }
3023
+ }
3024
+ startWork(request);
3025
+ });
3026
+ };
2735
3027
  exports.registerClientReference = function (
2736
3028
  proxyImplementation,
2737
3029
  id,
@@ -2760,13 +3052,11 @@ exports.renderToReadableStream = function (model, webpackMap, options) {
2760
3052
  model,
2761
3053
  webpackMap,
2762
3054
  options ? options.onError : void 0,
2763
- options ? options.identifierPrefix : void 0,
2764
3055
  options ? options.onPostpone : void 0,
2765
- options ? options.temporaryReferences : void 0,
2766
- void 0,
2767
- void 0,
2768
3056
  noop,
2769
- noop
3057
+ noop,
3058
+ options ? options.identifierPrefix : void 0,
3059
+ options ? options.temporaryReferences : void 0
2770
3060
  );
2771
3061
  if (options && options.signal) {
2772
3062
  var signal = options.signal;
@@ -2796,50 +3086,3 @@ exports.renderToReadableStream = function (model, webpackMap, options) {
2796
3086
  { highWaterMark: 0 }
2797
3087
  );
2798
3088
  };
2799
- exports.unstable_prerender = function (model, webpackMap, options) {
2800
- return new Promise(function (resolve, reject) {
2801
- var request = new RequestInstance(
2802
- 21,
2803
- model,
2804
- webpackMap,
2805
- options ? options.onError : void 0,
2806
- options ? options.identifierPrefix : void 0,
2807
- options ? options.onPostpone : void 0,
2808
- options ? options.temporaryReferences : void 0,
2809
- void 0,
2810
- void 0,
2811
- function () {
2812
- var stream = new ReadableStream(
2813
- {
2814
- type: "bytes",
2815
- start: function () {
2816
- startWork(request);
2817
- },
2818
- pull: function (controller) {
2819
- startFlowing(request, controller);
2820
- },
2821
- cancel: function (reason) {
2822
- request.destination = null;
2823
- abort(request, reason);
2824
- }
2825
- },
2826
- { highWaterMark: 0 }
2827
- );
2828
- resolve({ prelude: stream });
2829
- },
2830
- reject
2831
- );
2832
- if (options && options.signal) {
2833
- var signal = options.signal;
2834
- if (signal.aborted) abort(request, signal.reason);
2835
- else {
2836
- var listener = function () {
2837
- abort(request, signal.reason);
2838
- signal.removeEventListener("abort", listener);
2839
- };
2840
- signal.addEventListener("abort", listener);
2841
- }
2842
- }
2843
- startWork(request);
2844
- });
2845
- };