react-server-dom-webpack 19.0.0-rc-eb259b5d3b-20240605 → 19.0.0-rc-827cbea417-20240606

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.
@@ -94,9 +94,32 @@ function printWarning(level, format, args, currentStack) {
94
94
  }
95
95
  }
96
96
 
97
+ var channel = new MessageChannel();
98
+ var taskQueue = [];
99
+
100
+ channel.port1.onmessage = function () {
101
+ var task = taskQueue.shift();
102
+
103
+ if (task) {
104
+ task();
105
+ }
106
+ };
107
+
97
108
  function scheduleWork(callback) {
98
- callback();
109
+ taskQueue.push(callback);
110
+ channel.port2.postMessage(null);
111
+ }
112
+
113
+ function handleErrorInNextTick(error) {
114
+ setTimeout(function () {
115
+ throw error;
116
+ });
99
117
  }
118
+
119
+ var LocalPromise = Promise;
120
+ var scheduleMicrotask = typeof queueMicrotask === 'function' ? queueMicrotask : function (callback) {
121
+ LocalPromise.resolve(null).then(callback).catch(handleErrorInNextTick);
122
+ };
100
123
  var VIEW_SIZE = 2048;
101
124
  var currentView = null;
102
125
  var writtenBytes = 0;
@@ -1566,6 +1589,8 @@ var PENDING$1 = 0;
1566
1589
  var COMPLETED = 1;
1567
1590
  var ABORTED = 3;
1568
1591
  var ERRORED$1 = 4;
1592
+ var RENDERING = 5;
1593
+ var AbortSigil = {};
1569
1594
 
1570
1595
  function defaultErrorHandler(error) {
1571
1596
  console['error'](error); // Don't transform to our wrapper
@@ -1575,8 +1600,9 @@ function defaultPostponeHandler(reason) {// Noop
1575
1600
  }
1576
1601
 
1577
1602
  var OPEN = 0;
1578
- var CLOSING = 1;
1579
- var CLOSED = 2;
1603
+ var ABORTING = 1;
1604
+ var CLOSING = 2;
1605
+ var CLOSED = 3;
1580
1606
  function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName, temporaryReferences) {
1581
1607
  if (ReactSharedInternals.A !== null && ReactSharedInternals.A !== DefaultAsyncDispatcher) {
1582
1608
  throw new Error('Currently React only supports one RSC renderer at a time.');
@@ -1669,6 +1695,16 @@ function serializeThenable(request, task, thenable) {
1669
1695
 
1670
1696
  default:
1671
1697
  {
1698
+ if (request.status === ABORTING) {
1699
+ // We can no longer accept any resolved values
1700
+ newTask.status = ABORTED;
1701
+ var errorId = request.fatalError;
1702
+ var model = stringify(serializeByValueID(errorId));
1703
+ emitModelChunk(request, newTask.id, model);
1704
+ request.abortableTasks.delete(newTask);
1705
+ return newTask.id;
1706
+ }
1707
+
1672
1708
  if (typeof thenable.status === 'string') {
1673
1709
  // Only instrument the thenable if the status if not defined. If
1674
1710
  // it's defined, but an unknown value, assume it's been instrumented by
@@ -2042,6 +2078,13 @@ validated) // DEV-only
2042
2078
  result = callComponentInDEV(Component, props, componentDebugInfo);
2043
2079
  }
2044
2080
 
2081
+ if (request.status === ABORTING) {
2082
+ // If we aborted during rendering we should interrupt the render but
2083
+ // we don't need to provide an error because the renderer will encode
2084
+ // the abort error as the reason.
2085
+ throw AbortSigil;
2086
+ }
2087
+
2045
2088
  if (typeof result === 'object' && result !== null && !isClientReference(result)) {
2046
2089
  if (typeof result.then === 'function') {
2047
2090
  // When the return value is in children position we can resolve it immediately,
@@ -2383,6 +2426,13 @@ validated) // DEV only
2383
2426
  wrappedType = callLazyInitInDEV(type);
2384
2427
  }
2385
2428
 
2429
+ if (request.status === ABORTING) {
2430
+ // lazy initializers are user code and could abort during render
2431
+ // we don't wan to return any value resolved from the lazy initializer
2432
+ // if it aborts so we interrupt rendering here
2433
+ throw AbortSigil;
2434
+ }
2435
+
2386
2436
  return renderElement(request, task, wrappedType, key, ref, props, owner);
2387
2437
  }
2388
2438
 
@@ -2407,7 +2457,7 @@ function pingTask(request, task) {
2407
2457
 
2408
2458
  if (pingedTasks.length === 1) {
2409
2459
  request.flushScheduled = request.destination !== null;
2410
- scheduleWork(function () {
2460
+ scheduleMicrotask(function () {
2411
2461
  return performWork(request);
2412
2462
  });
2413
2463
  }
@@ -2705,21 +2755,32 @@ function renderModel(request, task, parent, key, value) {
2705
2755
  try {
2706
2756
  return renderModelDestructive(request, task, parent, key, value);
2707
2757
  } catch (thrownValue) {
2758
+ // If the suspended/errored value was an element or lazy it can be reduced
2759
+ // to a lazy reference, so that it doesn't error the parent.
2760
+ var model = task.model;
2761
+ var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2708
2762
  var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2709
2763
  // reasons, the rest of the Suspense implementation expects the thrown
2710
2764
  // value to be a thenable, because before `use` existed that was the
2711
2765
  // (unstable) API for suspending. This implementation detail can change
2712
2766
  // later, once we deprecate the old API in favor of `use`.
2713
- getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
2714
- // to a lazy reference, so that it doesn't error the parent.
2715
-
2716
- var model = task.model;
2717
- var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2767
+ getSuspendedThenable() : thrownValue;
2718
2768
 
2719
2769
  if (typeof x === 'object' && x !== null) {
2720
2770
  // $FlowFixMe[method-unbinding]
2721
2771
  if (typeof x.then === 'function') {
2722
- // Something suspended, we'll need to create a new task and resolve it later.
2772
+ if (request.status === ABORTING) {
2773
+ task.status = ABORTED;
2774
+ var errorId = request.fatalError;
2775
+
2776
+ if (wasReactNode) {
2777
+ return serializeLazyID(errorId);
2778
+ }
2779
+
2780
+ return serializeByValueID(errorId);
2781
+ } // Something suspended, we'll need to create a new task and resolve it later.
2782
+
2783
+
2723
2784
  var newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
2724
2785
  var ping = newTask.ping;
2725
2786
  x.then(ping, ping);
@@ -2735,6 +2796,17 @@ function renderModel(request, task, parent, key, value) {
2735
2796
 
2736
2797
  return serializeByValueID(newTask.id);
2737
2798
  }
2799
+ }
2800
+
2801
+ if (thrownValue === AbortSigil) {
2802
+ task.status = ABORTED;
2803
+ var _errorId = request.fatalError;
2804
+
2805
+ if (wasReactNode) {
2806
+ return serializeLazyID(_errorId);
2807
+ }
2808
+
2809
+ return serializeByValueID(_errorId);
2738
2810
  } // Restore the context. We assume that this will be restored by the inner
2739
2811
  // functions in case nothing throws so we don't use "finally" here.
2740
2812
 
@@ -2747,10 +2819,12 @@ function renderModel(request, task, parent, key, value) {
2747
2819
  // We'll replace this element with a lazy reference that throws on the client
2748
2820
  // once it gets rendered.
2749
2821
  request.pendingChunks++;
2750
- var errorId = request.nextChunkId++;
2822
+
2823
+ var _errorId2 = request.nextChunkId++;
2824
+
2751
2825
  var digest = logRecoverableError(request, x);
2752
- emitErrorChunk(request, errorId, digest, x);
2753
- return serializeLazyID(errorId);
2826
+ emitErrorChunk(request, _errorId2, digest, x);
2827
+ return serializeLazyID(_errorId2);
2754
2828
  } // Something errored but it was not in a React Node. There's no need to serialize
2755
2829
  // it by value because it'll just error the whole parent row anyway so we can
2756
2830
  // just stop any siblings and error the whole parent row.
@@ -2854,6 +2928,13 @@ function renderModelDestructive(request, task, parent, parentPropertyName, value
2854
2928
  resolvedModel = callLazyInitInDEV(lazy);
2855
2929
  }
2856
2930
 
2931
+ if (request.status === ABORTING) {
2932
+ // lazy initializers are user code and could abort during render
2933
+ // we don't wan to return any value resolved from the lazy initializer
2934
+ // if it aborts so we interrupt rendering here
2935
+ throw AbortSigil;
2936
+ }
2937
+
2857
2938
  {
2858
2939
  var _debugInfo = lazy._debugInfo;
2859
2940
 
@@ -3762,6 +3843,7 @@ function retryTask(request, task) {
3762
3843
  }
3763
3844
 
3764
3845
  var prevDebugID = debugID;
3846
+ task.status = RENDERING;
3765
3847
 
3766
3848
  try {
3767
3849
  // Track the root so we know that we have to emit this object even though it
@@ -3818,14 +3900,35 @@ function retryTask(request, task) {
3818
3900
  if (typeof x === 'object' && x !== null) {
3819
3901
  // $FlowFixMe[method-unbinding]
3820
3902
  if (typeof x.then === 'function') {
3821
- // Something suspended again, let's pick it back up later.
3903
+ if (request.status === ABORTING) {
3904
+ request.abortableTasks.delete(task);
3905
+ task.status = ABORTED;
3906
+ var errorId = request.fatalError;
3907
+ var model = stringify(serializeByValueID(errorId));
3908
+ emitModelChunk(request, task.id, model);
3909
+ return;
3910
+ } // Something suspended again, let's pick it back up later.
3911
+
3912
+
3913
+ task.status = PENDING$1;
3914
+ task.thenableState = getThenableStateAfterSuspending();
3822
3915
  var ping = task.ping;
3823
3916
  x.then(ping, ping);
3824
- task.thenableState = getThenableStateAfterSuspending();
3825
3917
  return;
3826
3918
  }
3827
3919
  }
3828
3920
 
3921
+ if (x === AbortSigil) {
3922
+ request.abortableTasks.delete(task);
3923
+ task.status = ABORTED;
3924
+ var _errorId3 = request.fatalError;
3925
+
3926
+ var _model = stringify(serializeByValueID(_errorId3));
3927
+
3928
+ emitModelChunk(request, task.id, _model);
3929
+ return;
3930
+ }
3931
+
3829
3932
  request.abortableTasks.delete(task);
3830
3933
  task.status = ERRORED$1;
3831
3934
  var digest = logRecoverableError(request, x);
@@ -3887,6 +3990,11 @@ function performWork(request) {
3887
3990
  }
3888
3991
 
3889
3992
  function abortTask(task, request, errorId) {
3993
+ if (task.status === RENDERING) {
3994
+ // This task will be aborted by the render
3995
+ return;
3996
+ }
3997
+
3890
3998
  task.status = ABORTED; // Instead of emitting an error per task.id, we emit a model that only
3891
3999
  // has a single value referencing the error.
3892
4000
 
@@ -3979,6 +4087,7 @@ function flushCompletedChunks(request, destination) {
3979
4087
 
3980
4088
  if (request.pendingChunks === 0) {
3981
4089
 
4090
+ request.status = CLOSED;
3982
4091
  close$1(destination);
3983
4092
  request.destination = null;
3984
4093
  }
@@ -3999,10 +4108,14 @@ function enqueueFlush(request) {
3999
4108
  request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
4000
4109
  // happen when we start flowing again
4001
4110
  request.destination !== null) {
4002
- var destination = request.destination;
4003
4111
  request.flushScheduled = true;
4004
4112
  scheduleWork(function () {
4005
- return flushCompletedChunks(request, destination);
4113
+ request.flushScheduled = false;
4114
+ var destination = request.destination;
4115
+
4116
+ if (destination) {
4117
+ flushCompletedChunks(request, destination);
4118
+ }
4006
4119
  });
4007
4120
  }
4008
4121
  }
@@ -4038,15 +4151,17 @@ function stopFlowing(request) {
4038
4151
 
4039
4152
  function abort(request, reason) {
4040
4153
  try {
4154
+ request.status = ABORTING;
4041
4155
  var abortableTasks = request.abortableTasks; // We have tasks to abort. We'll emit one error row and then emit a reference
4042
4156
  // to that row from every row that's still remaining.
4043
4157
 
4044
4158
  if (abortableTasks.size > 0) {
4045
4159
  request.pendingChunks++;
4046
4160
  var errorId = request.nextChunkId++;
4161
+ request.fatalError = errorId;
4047
4162
 
4048
4163
  var postponeInstance; if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
4049
- var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
4164
+ var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : typeof reason === 'object' && reason !== null && typeof reason.then === 'function' ? new Error('The render was aborted by the server with a promise.') : reason;
4050
4165
  var digest = logRecoverableError(request, error);
4051
4166
  emitErrorChunk(request, errorId, digest, error);
4052
4167
  }
@@ -4063,7 +4178,7 @@ function abort(request, reason) {
4063
4178
  var _error;
4064
4179
 
4065
4180
  if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
4066
- _error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
4181
+ _error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : typeof reason === 'object' && reason !== null && typeof reason.then === 'function' ? new Error('The render was aborted by the server with a promise.') : reason;
4067
4182
  }
4068
4183
 
4069
4184
  abortListeners.forEach(function (callback) {
@@ -11,6 +11,30 @@
11
11
  "use strict";
12
12
  var ReactDOM = require("react-dom"),
13
13
  React = require("react"),
14
+ channel = new MessageChannel(),
15
+ taskQueue = [];
16
+ channel.port1.onmessage = function () {
17
+ var task = taskQueue.shift();
18
+ task && task();
19
+ };
20
+ function scheduleWork(callback) {
21
+ taskQueue.push(callback);
22
+ channel.port2.postMessage(null);
23
+ }
24
+ function handleErrorInNextTick(error) {
25
+ setTimeout(function () {
26
+ throw error;
27
+ });
28
+ }
29
+ var LocalPromise = Promise,
30
+ scheduleMicrotask =
31
+ "function" === typeof queueMicrotask
32
+ ? queueMicrotask
33
+ : function (callback) {
34
+ LocalPromise.resolve(null)
35
+ .then(callback)
36
+ .catch(handleErrorInNextTick);
37
+ },
14
38
  currentView = null,
15
39
  writtenBytes = 0;
16
40
  function writeChunkAndReturn(destination, chunk) {
@@ -670,7 +694,8 @@ if (!ReactSharedInternalsServer)
670
694
  '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.'
671
695
  );
672
696
  var ObjectPrototype = Object.prototype,
673
- stringify = JSON.stringify;
697
+ stringify = JSON.stringify,
698
+ AbortSigil = {};
674
699
  function defaultErrorHandler(error) {
675
700
  console.error(error);
676
701
  }
@@ -746,6 +771,14 @@ function serializeThenable(request, task, thenable) {
746
771
  newTask.id
747
772
  );
748
773
  default:
774
+ if (1 === request.status)
775
+ return (
776
+ (newTask.status = 3),
777
+ (task = stringify(serializeByValueID(request.fatalError))),
778
+ emitModelChunk(request, newTask.id, task),
779
+ request.abortableTasks.delete(newTask),
780
+ newTask.id
781
+ );
749
782
  "string" !== typeof thenable.status &&
750
783
  ((thenable.status = "pending"),
751
784
  thenable.then(
@@ -932,6 +965,7 @@ function renderFunctionComponent(request, task, key, Component, props) {
932
965
  thenableIndexCounter = 0;
933
966
  thenableState = prevThenableState;
934
967
  Component = Component(props, void 0);
968
+ if (1 === request.status) throw AbortSigil;
935
969
  if (
936
970
  "object" === typeof Component &&
937
971
  null !== Component &&
@@ -1029,6 +1063,7 @@ function renderElement(request, task, type, key, ref, props) {
1029
1063
  case REACT_LAZY_TYPE:
1030
1064
  var init = type._init;
1031
1065
  type = init(type._payload);
1066
+ if (1 === request.status) throw AbortSigil;
1032
1067
  return renderElement(request, task, type, key, ref, props);
1033
1068
  case REACT_FORWARD_REF_TYPE:
1034
1069
  return renderFunctionComponent(request, task, key, type.render, props);
@@ -1045,7 +1080,9 @@ function pingTask(request, task) {
1045
1080
  pingedTasks.push(task);
1046
1081
  1 === pingedTasks.length &&
1047
1082
  ((request.flushScheduled = null !== request.destination),
1048
- performWork(request));
1083
+ scheduleMicrotask(function () {
1084
+ return performWork(request);
1085
+ }));
1049
1086
  }
1050
1087
  function createTask(request, model, keyPath, implicitSlot, abortSet) {
1051
1088
  request.pendingChunks++;
@@ -1077,50 +1114,61 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1077
1114
  );
1078
1115
  } catch (thrownValue) {
1079
1116
  if (
1080
- ((parentPropertyName =
1117
+ ((parentPropertyName = task.model),
1118
+ (parentPropertyName =
1119
+ "object" === typeof parentPropertyName &&
1120
+ null !== parentPropertyName &&
1121
+ (parentPropertyName.$$typeof === REACT_ELEMENT_TYPE ||
1122
+ parentPropertyName.$$typeof === REACT_LAZY_TYPE)),
1123
+ (value =
1081
1124
  thrownValue === SuspenseException
1082
1125
  ? getSuspendedThenable()
1083
1126
  : thrownValue),
1084
- (value = task.model),
1085
- (value =
1086
- "object" === typeof value &&
1127
+ "object" === typeof value &&
1087
1128
  null !== value &&
1088
- (value.$$typeof === REACT_ELEMENT_TYPE ||
1089
- value.$$typeof === REACT_LAZY_TYPE)),
1090
- "object" === typeof parentPropertyName &&
1091
- null !== parentPropertyName &&
1092
- "function" === typeof parentPropertyName.then)
1093
- ) {
1094
- JSCompiler_inline_result = createTask(
1095
- request,
1096
- task.model,
1097
- task.keyPath,
1098
- task.implicitSlot,
1099
- request.abortableTasks
1100
- );
1101
- var ping = JSCompiler_inline_result.ping;
1102
- parentPropertyName.then(ping, ping);
1103
- JSCompiler_inline_result.thenableState =
1104
- getThenableStateAfterSuspending();
1105
- task.keyPath = prevKeyPath;
1106
- task.implicitSlot = prevImplicitSlot;
1107
- JSCompiler_inline_result = value
1108
- ? "$L" + JSCompiler_inline_result.id.toString(16)
1109
- : serializeByValueID(JSCompiler_inline_result.id);
1110
- } else if (
1129
+ "function" === typeof value.then)
1130
+ )
1131
+ if (1 === request.status)
1132
+ (task.status = 3),
1133
+ (prevKeyPath = request.fatalError),
1134
+ (JSCompiler_inline_result = parentPropertyName
1135
+ ? "$L" + prevKeyPath.toString(16)
1136
+ : serializeByValueID(prevKeyPath));
1137
+ else {
1138
+ JSCompiler_inline_result = createTask(
1139
+ request,
1140
+ task.model,
1141
+ task.keyPath,
1142
+ task.implicitSlot,
1143
+ request.abortableTasks
1144
+ );
1145
+ var ping = JSCompiler_inline_result.ping;
1146
+ value.then(ping, ping);
1147
+ JSCompiler_inline_result.thenableState =
1148
+ getThenableStateAfterSuspending();
1149
+ task.keyPath = prevKeyPath;
1150
+ task.implicitSlot = prevImplicitSlot;
1151
+ JSCompiler_inline_result = parentPropertyName
1152
+ ? "$L" + JSCompiler_inline_result.id.toString(16)
1153
+ : serializeByValueID(JSCompiler_inline_result.id);
1154
+ }
1155
+ else if (thrownValue === AbortSigil)
1156
+ (task.status = 3),
1157
+ (prevKeyPath = request.fatalError),
1158
+ (JSCompiler_inline_result = parentPropertyName
1159
+ ? "$L" + prevKeyPath.toString(16)
1160
+ : serializeByValueID(prevKeyPath));
1161
+ else if (
1111
1162
  ((task.keyPath = prevKeyPath),
1112
1163
  (task.implicitSlot = prevImplicitSlot),
1113
- value)
1164
+ parentPropertyName)
1114
1165
  )
1115
1166
  request.pendingChunks++,
1116
1167
  (prevKeyPath = request.nextChunkId++),
1117
- (prevImplicitSlot = logRecoverableError(
1118
- request,
1119
- parentPropertyName
1120
- )),
1168
+ (prevImplicitSlot = logRecoverableError(request, value)),
1121
1169
  emitErrorChunk(request, prevKeyPath, prevImplicitSlot),
1122
1170
  (JSCompiler_inline_result = "$L" + prevKeyPath.toString(16));
1123
- else throw parentPropertyName;
1171
+ else throw value;
1124
1172
  }
1125
1173
  return JSCompiler_inline_result;
1126
1174
  },
@@ -1273,12 +1321,11 @@ function renderModelDestructive(
1273
1321
  parentPropertyName
1274
1322
  );
1275
1323
  case REACT_LAZY_TYPE:
1276
- return (
1277
- (task.thenableState = null),
1278
- (parentPropertyName = value._init),
1279
- (value = parentPropertyName(value._payload)),
1280
- renderModelDestructive(request, task, emptyRoot, "", value)
1281
- );
1324
+ task.thenableState = null;
1325
+ parentPropertyName = value._init;
1326
+ value = parentPropertyName(value._payload);
1327
+ if (1 === request.status) throw AbortSigil;
1328
+ return renderModelDestructive(request, task, emptyRoot, "", value);
1282
1329
  case REACT_LEGACY_ELEMENT_TYPE:
1283
1330
  throw Error(
1284
1331
  'A React Element from an older version of React was rendered. This is not supported. It can happen if:\n- Multiple copies of the "react" package is used.\n- A library pre-bundled an old copy of "react" or "react/jsx-runtime".\n- A compiler tries to "inline" JSX instead of using the runtime.'
@@ -1539,8 +1586,8 @@ function logRecoverableError(request, error) {
1539
1586
  }
1540
1587
  function fatalError(request, error) {
1541
1588
  null !== request.destination
1542
- ? ((request.status = 2), closeWithError(request.destination, error))
1543
- : ((request.status = 1), (request.fatalError = error));
1589
+ ? ((request.status = 3), closeWithError(request.destination, error))
1590
+ : ((request.status = 2), (request.fatalError = error));
1544
1591
  }
1545
1592
  function emitErrorChunk(request, id, digest) {
1546
1593
  digest = { digest: digest };
@@ -1609,7 +1656,8 @@ function emitChunk(request, task, value) {
1609
1656
  }
1610
1657
  var emptyRoot = {};
1611
1658
  function retryTask(request, task) {
1612
- if (0 === task.status)
1659
+ if (0 === task.status) {
1660
+ task.status = 5;
1613
1661
  try {
1614
1662
  modelRoot = task.model;
1615
1663
  var resolvedModel = renderModelDestructive(
@@ -1636,10 +1684,23 @@ function retryTask(request, task) {
1636
1684
  thrownValue === SuspenseException
1637
1685
  ? getSuspendedThenable()
1638
1686
  : thrownValue;
1639
- if ("object" === typeof x && null !== x && "function" === typeof x.then) {
1640
- var ping = task.ping;
1641
- x.then(ping, ping);
1642
- task.thenableState = getThenableStateAfterSuspending();
1687
+ if ("object" === typeof x && null !== x && "function" === typeof x.then)
1688
+ if (1 === request.status) {
1689
+ request.abortableTasks.delete(task);
1690
+ task.status = 3;
1691
+ var model = stringify(serializeByValueID(request.fatalError));
1692
+ emitModelChunk(request, task.id, model);
1693
+ } else {
1694
+ task.status = 0;
1695
+ task.thenableState = getThenableStateAfterSuspending();
1696
+ var ping = task.ping;
1697
+ x.then(ping, ping);
1698
+ }
1699
+ else if (x === AbortSigil) {
1700
+ request.abortableTasks.delete(task);
1701
+ task.status = 3;
1702
+ var model$19 = stringify(serializeByValueID(request.fatalError));
1703
+ emitModelChunk(request, task.id, model$19);
1643
1704
  } else {
1644
1705
  request.abortableTasks.delete(task);
1645
1706
  task.status = 4;
@@ -1648,6 +1709,7 @@ function retryTask(request, task) {
1648
1709
  }
1649
1710
  } finally {
1650
1711
  }
1712
+ }
1651
1713
  }
1652
1714
  function performWork(request) {
1653
1715
  var prevDispatcher = ReactSharedInternalsServer.H;
@@ -1705,54 +1767,72 @@ function flushCompletedChunks(request, destination) {
1705
1767
  (writtenBytes = 0));
1706
1768
  }
1707
1769
  0 === request.pendingChunks &&
1708
- (destination.close(), (request.destination = null));
1770
+ ((request.status = 3), destination.close(), (request.destination = null));
1771
+ }
1772
+ function startWork(request) {
1773
+ request.flushScheduled = null !== request.destination;
1774
+ scheduleWork(function () {
1775
+ return performWork(request);
1776
+ });
1709
1777
  }
1710
1778
  function enqueueFlush(request) {
1711
- if (
1712
- !1 === request.flushScheduled &&
1779
+ !1 === request.flushScheduled &&
1713
1780
  0 === request.pingedTasks.length &&
1714
- null !== request.destination
1715
- ) {
1716
- var destination = request.destination;
1717
- request.flushScheduled = !0;
1718
- flushCompletedChunks(request, destination);
1719
- }
1781
+ null !== request.destination &&
1782
+ ((request.flushScheduled = !0),
1783
+ scheduleWork(function () {
1784
+ request.flushScheduled = !1;
1785
+ var destination = request.destination;
1786
+ destination && flushCompletedChunks(request, destination);
1787
+ }));
1720
1788
  }
1721
1789
  function abort(request, reason) {
1722
1790
  try {
1791
+ request.status = 1;
1723
1792
  var abortableTasks = request.abortableTasks;
1724
1793
  if (0 < abortableTasks.size) {
1725
1794
  request.pendingChunks++;
1726
- var errorId = request.nextChunkId++,
1727
- error =
1795
+ var errorId = request.nextChunkId++;
1796
+ request.fatalError = errorId;
1797
+ var error =
1728
1798
  void 0 === reason
1729
1799
  ? Error("The render was aborted by the server without a reason.")
1800
+ : "object" === typeof reason &&
1801
+ null !== reason &&
1802
+ "function" === typeof reason.then
1803
+ ? Error("The render was aborted by the server with a promise.")
1730
1804
  : reason,
1731
1805
  digest = logRecoverableError(request, error);
1732
1806
  emitErrorChunk(request, errorId, digest, error);
1733
1807
  abortableTasks.forEach(function (task) {
1734
- task.status = 3;
1735
- var ref = serializeByValueID(errorId);
1736
- task = encodeReferenceChunk(request, task.id, ref);
1737
- request.completedErrorChunks.push(task);
1808
+ if (5 !== task.status) {
1809
+ task.status = 3;
1810
+ var ref = serializeByValueID(errorId);
1811
+ task = encodeReferenceChunk(request, task.id, ref);
1812
+ request.completedErrorChunks.push(task);
1813
+ }
1738
1814
  });
1739
1815
  abortableTasks.clear();
1740
1816
  }
1741
1817
  var abortListeners = request.abortListeners;
1742
1818
  if (0 < abortListeners.size) {
1743
- var error$22 =
1819
+ var error$26 =
1744
1820
  void 0 === reason
1745
1821
  ? Error("The render was aborted by the server without a reason.")
1822
+ : "object" === typeof reason &&
1823
+ null !== reason &&
1824
+ "function" === typeof reason.then
1825
+ ? Error("The render was aborted by the server with a promise.")
1746
1826
  : reason;
1747
1827
  abortListeners.forEach(function (callback) {
1748
- return callback(error$22);
1828
+ return callback(error$26);
1749
1829
  });
1750
1830
  abortListeners.clear();
1751
1831
  }
1752
1832
  null !== request.destination &&
1753
1833
  flushCompletedChunks(request, request.destination);
1754
- } catch (error$23) {
1755
- logRecoverableError(request, error$23), fatalError(request, error$23);
1834
+ } catch (error$27) {
1835
+ logRecoverableError(request, error$27), fatalError(request, error$27);
1756
1836
  }
1757
1837
  }
1758
1838
  function resolveServerReference(bundlerConfig, id) {
@@ -2204,8 +2284,8 @@ function parseReadableStream(response, reference, type) {
2204
2284
  (previousBlockedChunk = chunk));
2205
2285
  } else {
2206
2286
  chunk = previousBlockedChunk;
2207
- var chunk$26 = createPendingChunk(response);
2208
- chunk$26.then(
2287
+ var chunk$30 = createPendingChunk(response);
2288
+ chunk$30.then(
2209
2289
  function (v) {
2210
2290
  return controller.enqueue(v);
2211
2291
  },
@@ -2213,10 +2293,10 @@ function parseReadableStream(response, reference, type) {
2213
2293
  return controller.error(e);
2214
2294
  }
2215
2295
  );
2216
- previousBlockedChunk = chunk$26;
2296
+ previousBlockedChunk = chunk$30;
2217
2297
  chunk.then(function () {
2218
- previousBlockedChunk === chunk$26 && (previousBlockedChunk = null);
2219
- resolveModelChunk(chunk$26, json, -1);
2298
+ previousBlockedChunk === chunk$30 && (previousBlockedChunk = null);
2299
+ resolveModelChunk(chunk$30, json, -1);
2220
2300
  });
2221
2301
  }
2222
2302
  },
@@ -2581,13 +2661,12 @@ exports.renderToReadableStream = function (model, webpackMap, options) {
2581
2661
  {
2582
2662
  type: "bytes",
2583
2663
  start: function () {
2584
- request.flushScheduled = null !== request.destination;
2585
- performWork(request);
2664
+ startWork(request);
2586
2665
  },
2587
2666
  pull: function (controller) {
2588
- if (1 === request.status)
2589
- (request.status = 2), closeWithError(controller, request.fatalError);
2590
- else if (2 !== request.status && null === request.destination) {
2667
+ if (2 === request.status)
2668
+ (request.status = 3), closeWithError(controller, request.fatalError);
2669
+ else if (3 !== request.status && null === request.destination) {
2591
2670
  request.destination = controller;
2592
2671
  try {
2593
2672
  flushCompletedChunks(request, controller);