react-server-dom-webpack 19.0.0-rc-6230622a1a-20240610 → 19.0.0-rc-a26e3f403e-20240611

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.
@@ -10,7 +10,21 @@
10
10
 
11
11
  "use strict";
12
12
  var ReactDOM = require("react-dom"),
13
- React = require("react"),
13
+ React = require("react");
14
+ function handleErrorInNextTick(error) {
15
+ setTimeout(function () {
16
+ throw error;
17
+ });
18
+ }
19
+ var LocalPromise = Promise,
20
+ scheduleMicrotask =
21
+ "function" === typeof queueMicrotask
22
+ ? queueMicrotask
23
+ : function (callback) {
24
+ LocalPromise.resolve(null)
25
+ .then(callback)
26
+ .catch(handleErrorInNextTick);
27
+ },
14
28
  currentView = null,
15
29
  writtenBytes = 0;
16
30
  function writeChunkAndReturn(destination, chunk) {
@@ -677,12 +691,13 @@ if (!ReactSharedInternalsServer)
677
691
  '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.'
678
692
  );
679
693
  var ObjectPrototype = Object.prototype,
680
- stringify = JSON.stringify;
694
+ stringify = JSON.stringify,
695
+ AbortSigil = {};
681
696
  function defaultErrorHandler(error) {
682
697
  console.error(error);
683
698
  }
684
699
  function defaultPostponeHandler() {}
685
- function createRequest(
700
+ function RequestInstance(
686
701
  model,
687
702
  bundlerConfig,
688
703
  onError,
@@ -700,37 +715,32 @@ function createRequest(
700
715
  var abortSet = new Set();
701
716
  environmentName = [];
702
717
  var hints = new Set();
703
- bundlerConfig = {
704
- status: 0,
705
- flushScheduled: !1,
706
- fatalError: null,
707
- destination: null,
708
- bundlerConfig: bundlerConfig,
709
- cache: new Map(),
710
- nextChunkId: 0,
711
- pendingChunks: 0,
712
- hints: hints,
713
- abortListeners: new Set(),
714
- abortableTasks: abortSet,
715
- pingedTasks: environmentName,
716
- completedImportChunks: [],
717
- completedHintChunks: [],
718
- completedRegularChunks: [],
719
- completedErrorChunks: [],
720
- writtenSymbols: new Map(),
721
- writtenClientReferences: new Map(),
722
- writtenServerReferences: new Map(),
723
- writtenObjects: new WeakMap(),
724
- temporaryReferences: temporaryReferences,
725
- identifierPrefix: identifierPrefix || "",
726
- identifierCount: 1,
727
- taintCleanupQueue: [],
728
- onError: void 0 === onError ? defaultErrorHandler : onError,
729
- onPostpone: void 0 === onPostpone ? defaultPostponeHandler : onPostpone
730
- };
731
- model = createTask(bundlerConfig, model, null, !1, abortSet);
718
+ this.status = 0;
719
+ this.flushScheduled = !1;
720
+ this.destination = this.fatalError = null;
721
+ this.bundlerConfig = bundlerConfig;
722
+ this.cache = new Map();
723
+ this.pendingChunks = this.nextChunkId = 0;
724
+ this.hints = hints;
725
+ this.abortListeners = new Set();
726
+ this.abortableTasks = abortSet;
727
+ this.pingedTasks = environmentName;
728
+ this.completedImportChunks = [];
729
+ this.completedHintChunks = [];
730
+ this.completedRegularChunks = [];
731
+ this.completedErrorChunks = [];
732
+ this.writtenSymbols = new Map();
733
+ this.writtenClientReferences = new Map();
734
+ this.writtenServerReferences = new Map();
735
+ this.writtenObjects = new WeakMap();
736
+ this.temporaryReferences = temporaryReferences;
737
+ this.identifierPrefix = identifierPrefix || "";
738
+ this.identifierCount = 1;
739
+ this.taintCleanupQueue = [];
740
+ this.onError = void 0 === onError ? defaultErrorHandler : onError;
741
+ this.onPostpone = void 0 === onPostpone ? defaultPostponeHandler : onPostpone;
742
+ model = createTask(this, model, null, !1, abortSet);
732
743
  environmentName.push(model);
733
- return bundlerConfig;
734
744
  }
735
745
  var currentRequest = null;
736
746
  function resolveRequest() {
@@ -761,6 +771,14 @@ function serializeThenable(request, task, thenable) {
761
771
  newTask.id
762
772
  );
763
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
+ );
764
782
  "string" !== typeof thenable.status &&
765
783
  ((thenable.status = "pending"),
766
784
  thenable.then(
@@ -947,6 +965,7 @@ function renderFunctionComponent(request, task, key, Component, props) {
947
965
  thenableIndexCounter = 0;
948
966
  thenableState = prevThenableState;
949
967
  Component = Component(props, void 0);
968
+ if (1 === request.status) throw AbortSigil;
950
969
  if (
951
970
  "object" === typeof Component &&
952
971
  null !== Component &&
@@ -1044,6 +1063,7 @@ function renderElement(request, task, type, key, ref, props) {
1044
1063
  case REACT_LAZY_TYPE:
1045
1064
  var init = type._init;
1046
1065
  type = init(type._payload);
1066
+ if (1 === request.status) throw AbortSigil;
1047
1067
  return renderElement(request, task, type, key, ref, props);
1048
1068
  case REACT_FORWARD_REF_TYPE:
1049
1069
  return renderFunctionComponent(request, task, key, type.render, props);
@@ -1060,9 +1080,9 @@ function pingTask(request, task) {
1060
1080
  pingedTasks.push(task);
1061
1081
  1 === pingedTasks.length &&
1062
1082
  ((request.flushScheduled = null !== request.destination),
1063
- setTimeout(function () {
1083
+ scheduleMicrotask(function () {
1064
1084
  return performWork(request);
1065
- }, 0));
1085
+ }));
1066
1086
  }
1067
1087
  function createTask(request, model, keyPath, implicitSlot, abortSet) {
1068
1088
  request.pendingChunks++;
@@ -1094,50 +1114,61 @@ function createTask(request, model, keyPath, implicitSlot, abortSet) {
1094
1114
  );
1095
1115
  } catch (thrownValue) {
1096
1116
  if (
1097
- ((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 =
1098
1124
  thrownValue === SuspenseException
1099
1125
  ? getSuspendedThenable()
1100
1126
  : thrownValue),
1101
- (value = task.model),
1102
- (value =
1103
- "object" === typeof value &&
1127
+ "object" === typeof value &&
1104
1128
  null !== value &&
1105
- (value.$$typeof === REACT_ELEMENT_TYPE ||
1106
- value.$$typeof === REACT_LAZY_TYPE)),
1107
- "object" === typeof parentPropertyName &&
1108
- null !== parentPropertyName &&
1109
- "function" === typeof parentPropertyName.then)
1110
- ) {
1111
- JSCompiler_inline_result = createTask(
1112
- request,
1113
- task.model,
1114
- task.keyPath,
1115
- task.implicitSlot,
1116
- request.abortableTasks
1117
- );
1118
- var ping = JSCompiler_inline_result.ping;
1119
- parentPropertyName.then(ping, ping);
1120
- JSCompiler_inline_result.thenableState =
1121
- getThenableStateAfterSuspending();
1122
- task.keyPath = prevKeyPath;
1123
- task.implicitSlot = prevImplicitSlot;
1124
- JSCompiler_inline_result = value
1125
- ? "$L" + JSCompiler_inline_result.id.toString(16)
1126
- : serializeByValueID(JSCompiler_inline_result.id);
1127
- } 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 (
1128
1162
  ((task.keyPath = prevKeyPath),
1129
1163
  (task.implicitSlot = prevImplicitSlot),
1130
- value)
1164
+ parentPropertyName)
1131
1165
  )
1132
1166
  request.pendingChunks++,
1133
1167
  (prevKeyPath = request.nextChunkId++),
1134
- (prevImplicitSlot = logRecoverableError(
1135
- request,
1136
- parentPropertyName
1137
- )),
1168
+ (prevImplicitSlot = logRecoverableError(request, value)),
1138
1169
  emitErrorChunk(request, prevKeyPath, prevImplicitSlot),
1139
1170
  (JSCompiler_inline_result = "$L" + prevKeyPath.toString(16));
1140
- else throw parentPropertyName;
1171
+ else throw value;
1141
1172
  }
1142
1173
  return JSCompiler_inline_result;
1143
1174
  },
@@ -1290,12 +1321,11 @@ function renderModelDestructive(
1290
1321
  parentPropertyName
1291
1322
  );
1292
1323
  case REACT_LAZY_TYPE:
1293
- return (
1294
- (task.thenableState = null),
1295
- (parentPropertyName = value._init),
1296
- (value = parentPropertyName(value._payload)),
1297
- renderModelDestructive(request, task, emptyRoot, "", value)
1298
- );
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);
1299
1329
  case REACT_LEGACY_ELEMENT_TYPE:
1300
1330
  throw Error(
1301
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.'
@@ -1558,8 +1588,8 @@ function logRecoverableError(request, error) {
1558
1588
  }
1559
1589
  function fatalError(request, error) {
1560
1590
  null !== request.destination
1561
- ? ((request.status = 2), closeWithError(request.destination, error))
1562
- : ((request.status = 1), (request.fatalError = error));
1591
+ ? ((request.status = 3), closeWithError(request.destination, error))
1592
+ : ((request.status = 2), (request.fatalError = error));
1563
1593
  }
1564
1594
  function emitErrorChunk(request, id, digest) {
1565
1595
  digest = { digest: digest };
@@ -1628,7 +1658,8 @@ function emitChunk(request, task, value) {
1628
1658
  }
1629
1659
  var emptyRoot = {};
1630
1660
  function retryTask(request, task) {
1631
- if (0 === task.status)
1661
+ if (0 === task.status) {
1662
+ task.status = 5;
1632
1663
  try {
1633
1664
  modelRoot = task.model;
1634
1665
  var resolvedModel = renderModelDestructive(
@@ -1655,10 +1686,23 @@ function retryTask(request, task) {
1655
1686
  thrownValue === SuspenseException
1656
1687
  ? getSuspendedThenable()
1657
1688
  : thrownValue;
1658
- if ("object" === typeof x && null !== x && "function" === typeof x.then) {
1659
- var ping = task.ping;
1660
- x.then(ping, ping);
1661
- task.thenableState = getThenableStateAfterSuspending();
1689
+ if ("object" === typeof x && null !== x && "function" === typeof x.then)
1690
+ if (1 === request.status) {
1691
+ request.abortableTasks.delete(task);
1692
+ task.status = 3;
1693
+ var model = stringify(serializeByValueID(request.fatalError));
1694
+ emitModelChunk(request, task.id, model);
1695
+ } else {
1696
+ task.status = 0;
1697
+ task.thenableState = getThenableStateAfterSuspending();
1698
+ var ping = task.ping;
1699
+ x.then(ping, ping);
1700
+ }
1701
+ else if (x === AbortSigil) {
1702
+ request.abortableTasks.delete(task);
1703
+ task.status = 3;
1704
+ var model$19 = stringify(serializeByValueID(request.fatalError));
1705
+ emitModelChunk(request, task.id, model$19);
1662
1706
  } else {
1663
1707
  request.abortableTasks.delete(task);
1664
1708
  task.status = 4;
@@ -1667,6 +1711,7 @@ function retryTask(request, task) {
1667
1711
  }
1668
1712
  } finally {
1669
1713
  }
1714
+ }
1670
1715
  }
1671
1716
  function performWork(request) {
1672
1717
  var prevDispatcher = ReactSharedInternalsServer.H;
@@ -1724,7 +1769,7 @@ function flushCompletedChunks(request, destination) {
1724
1769
  (writtenBytes = 0));
1725
1770
  }
1726
1771
  0 === request.pendingChunks &&
1727
- (destination.close(), (request.destination = null));
1772
+ ((request.status = 3), destination.close(), (request.destination = null));
1728
1773
  }
1729
1774
  function startWork(request) {
1730
1775
  request.flushScheduled = null !== request.destination;
@@ -1737,53 +1782,63 @@ function startWork(request) {
1737
1782
  }, 0);
1738
1783
  }
1739
1784
  function enqueueFlush(request) {
1740
- if (
1741
- !1 === request.flushScheduled &&
1785
+ !1 === request.flushScheduled &&
1742
1786
  0 === request.pingedTasks.length &&
1743
- null !== request.destination
1744
- ) {
1745
- var destination = request.destination;
1746
- request.flushScheduled = !0;
1787
+ null !== request.destination &&
1788
+ ((request.flushScheduled = !0),
1747
1789
  setTimeout(function () {
1748
- return flushCompletedChunks(request, destination);
1749
- }, 0);
1750
- }
1790
+ request.flushScheduled = !1;
1791
+ var destination = request.destination;
1792
+ destination && flushCompletedChunks(request, destination);
1793
+ }, 0));
1751
1794
  }
1752
1795
  function abort(request, reason) {
1753
1796
  try {
1797
+ request.status = 1;
1754
1798
  var abortableTasks = request.abortableTasks;
1755
1799
  if (0 < abortableTasks.size) {
1756
1800
  request.pendingChunks++;
1757
- var errorId = request.nextChunkId++,
1758
- error =
1801
+ var errorId = request.nextChunkId++;
1802
+ request.fatalError = errorId;
1803
+ var error =
1759
1804
  void 0 === reason
1760
1805
  ? Error("The render was aborted by the server without a reason.")
1806
+ : "object" === typeof reason &&
1807
+ null !== reason &&
1808
+ "function" === typeof reason.then
1809
+ ? Error("The render was aborted by the server with a promise.")
1761
1810
  : reason,
1762
1811
  digest = logRecoverableError(request, error);
1763
1812
  emitErrorChunk(request, errorId, digest, error);
1764
1813
  abortableTasks.forEach(function (task) {
1765
- task.status = 3;
1766
- var ref = serializeByValueID(errorId);
1767
- task = encodeReferenceChunk(request, task.id, ref);
1768
- request.completedErrorChunks.push(task);
1814
+ if (5 !== task.status) {
1815
+ task.status = 3;
1816
+ var ref = serializeByValueID(errorId);
1817
+ task = encodeReferenceChunk(request, task.id, ref);
1818
+ request.completedErrorChunks.push(task);
1819
+ }
1769
1820
  });
1770
1821
  abortableTasks.clear();
1771
1822
  }
1772
1823
  var abortListeners = request.abortListeners;
1773
1824
  if (0 < abortListeners.size) {
1774
- var error$22 =
1825
+ var error$26 =
1775
1826
  void 0 === reason
1776
1827
  ? Error("The render was aborted by the server without a reason.")
1828
+ : "object" === typeof reason &&
1829
+ null !== reason &&
1830
+ "function" === typeof reason.then
1831
+ ? Error("The render was aborted by the server with a promise.")
1777
1832
  : reason;
1778
1833
  abortListeners.forEach(function (callback) {
1779
- return callback(error$22);
1834
+ return callback(error$26);
1780
1835
  });
1781
1836
  abortListeners.clear();
1782
1837
  }
1783
1838
  null !== request.destination &&
1784
1839
  flushCompletedChunks(request, request.destination);
1785
- } catch (error$23) {
1786
- logRecoverableError(request, error$23), fatalError(request, error$23);
1840
+ } catch (error$27) {
1841
+ logRecoverableError(request, error$27), fatalError(request, error$27);
1787
1842
  }
1788
1843
  }
1789
1844
  function resolveServerReference(bundlerConfig, id) {
@@ -2226,8 +2281,8 @@ function parseReadableStream(response, reference, type) {
2226
2281
  (previousBlockedChunk = chunk));
2227
2282
  } else {
2228
2283
  chunk = previousBlockedChunk;
2229
- var chunk$26 = createPendingChunk(response);
2230
- chunk$26.then(
2284
+ var chunk$30 = createPendingChunk(response);
2285
+ chunk$30.then(
2231
2286
  function (v) {
2232
2287
  return controller.enqueue(v);
2233
2288
  },
@@ -2235,10 +2290,10 @@ function parseReadableStream(response, reference, type) {
2235
2290
  return controller.error(e);
2236
2291
  }
2237
2292
  );
2238
- previousBlockedChunk = chunk$26;
2293
+ previousBlockedChunk = chunk$30;
2239
2294
  chunk.then(function () {
2240
- previousBlockedChunk === chunk$26 && (previousBlockedChunk = null);
2241
- resolveModelChunk(chunk$26, json, -1);
2295
+ previousBlockedChunk === chunk$30 && (previousBlockedChunk = null);
2296
+ resolveModelChunk(chunk$30, json, -1);
2242
2297
  });
2243
2298
  }
2244
2299
  },
@@ -2579,7 +2634,7 @@ exports.registerServerReference = function (reference, id, exportName) {
2579
2634
  });
2580
2635
  };
2581
2636
  exports.renderToReadableStream = function (model, webpackMap, options) {
2582
- var request = createRequest(
2637
+ var request = new RequestInstance(
2583
2638
  model,
2584
2639
  webpackMap,
2585
2640
  options ? options.onError : void 0,
@@ -2606,9 +2661,9 @@ exports.renderToReadableStream = function (model, webpackMap, options) {
2606
2661
  startWork(request);
2607
2662
  },
2608
2663
  pull: function (controller) {
2609
- if (1 === request.status)
2610
- (request.status = 2), closeWithError(controller, request.fatalError);
2611
- else if (2 !== request.status && null === request.destination) {
2664
+ if (2 === request.status)
2665
+ (request.status = 3), closeWithError(controller, request.fatalError);
2666
+ else if (3 !== request.status && null === request.destination) {
2612
2667
  request.destination = controller;
2613
2668
  try {
2614
2669
  flushCompletedChunks(request, controller);