react-server-dom-webpack 19.0.0-rc.1 → 19.1.0-canary-130095f7-20241212

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.
@@ -444,7 +444,7 @@ function getIteratorFn(maybeIterable) {
444
444
  }
445
445
  var ASYNC_ITERATOR = Symbol.asyncIterator,
446
446
  SuspenseException = Error(
447
- "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`"
447
+ "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`."
448
448
  );
449
449
  function noop$1() {}
450
450
  function trackUsedThenable(thenableState, thenable, index) {
@@ -777,13 +777,7 @@ function serializeThenable(request, task, thenable) {
777
777
  (newTask.model = thenable.value), pingTask(request, newTask), newTask.id
778
778
  );
779
779
  case "rejected":
780
- return (
781
- (task = logRecoverableError(request, thenable.reason, null)),
782
- emitErrorChunk(request, newTask.id, task),
783
- (newTask.status = 4),
784
- request.abortableTasks.delete(newTask),
785
- newTask.id
786
- );
780
+ return erroredTask(request, newTask, thenable.reason), newTask.id;
787
781
  default:
788
782
  if (12 === request.status)
789
783
  return (
@@ -814,11 +808,7 @@ function serializeThenable(request, task, thenable) {
814
808
  },
815
809
  function (reason) {
816
810
  0 === newTask.status &&
817
- ((reason = logRecoverableError(request, reason, newTask)),
818
- emitErrorChunk(request, newTask.id, reason),
819
- (newTask.status = 4),
820
- request.abortableTasks.delete(newTask),
821
- enqueueFlush(request));
811
+ (erroredTask(request, newTask, reason), enqueueFlush(request));
822
812
  }
823
813
  );
824
814
  return newTask.id;
@@ -839,29 +829,25 @@ function serializeReadableStream(request, task, stream) {
839
829
  emitChunk(request, streamTask, streamTask.model),
840
830
  enqueueFlush(request),
841
831
  reader.read().then(progress, error);
842
- } catch (x$8) {
843
- error(x$8);
832
+ } catch (x$7) {
833
+ error(x$7);
844
834
  }
845
835
  }
846
836
  function error(reason) {
847
- if (!aborted) {
848
- aborted = !0;
849
- request.abortListeners.delete(abortStream);
850
- var digest = logRecoverableError(request, reason, streamTask);
851
- emitErrorChunk(request, streamTask.id, digest);
852
- enqueueFlush(request);
853
- reader.cancel(reason).then(error, error);
854
- }
837
+ aborted ||
838
+ ((aborted = !0),
839
+ request.abortListeners.delete(abortStream),
840
+ erroredTask(request, streamTask, reason),
841
+ enqueueFlush(request),
842
+ reader.cancel(reason).then(error, error));
855
843
  }
856
844
  function abortStream(reason) {
857
- if (!aborted) {
858
- aborted = !0;
859
- request.abortListeners.delete(abortStream);
860
- var digest = logRecoverableError(request, reason, streamTask);
861
- emitErrorChunk(request, streamTask.id, digest);
862
- enqueueFlush(request);
863
- reader.cancel(reason).then(error, error);
864
- }
845
+ aborted ||
846
+ ((aborted = !0),
847
+ request.abortListeners.delete(abortStream),
848
+ erroredTask(request, streamTask, reason),
849
+ enqueueFlush(request),
850
+ reader.cancel(reason).then(error, error));
865
851
  }
866
852
  var supportsBYOB = stream.supportsBYOB;
867
853
  if (void 0 === supportsBYOB)
@@ -916,31 +902,27 @@ function serializeAsyncIterable(request, task, iterable, iterator) {
916
902
  emitChunk(request, streamTask, streamTask.model),
917
903
  enqueueFlush(request),
918
904
  iterator.next().then(progress, error);
919
- } catch (x$9) {
920
- error(x$9);
905
+ } catch (x$8) {
906
+ error(x$8);
921
907
  }
922
908
  }
923
909
  function error(reason) {
924
- if (!aborted) {
925
- aborted = !0;
926
- request.abortListeners.delete(abortIterable);
927
- var digest = logRecoverableError(request, reason, streamTask);
928
- emitErrorChunk(request, streamTask.id, digest);
929
- enqueueFlush(request);
910
+ aborted ||
911
+ ((aborted = !0),
912
+ request.abortListeners.delete(abortIterable),
913
+ erroredTask(request, streamTask, reason),
914
+ enqueueFlush(request),
930
915
  "function" === typeof iterator.throw &&
931
- iterator.throw(reason).then(error, error);
932
- }
916
+ iterator.throw(reason).then(error, error));
933
917
  }
934
918
  function abortIterable(reason) {
935
- if (!aborted) {
936
- aborted = !0;
937
- request.abortListeners.delete(abortIterable);
938
- var digest = logRecoverableError(request, reason, streamTask);
939
- emitErrorChunk(request, streamTask.id, digest);
940
- enqueueFlush(request);
919
+ aborted ||
920
+ ((aborted = !0),
921
+ request.abortListeners.delete(abortIterable),
922
+ erroredTask(request, streamTask, reason),
923
+ enqueueFlush(request),
941
924
  "function" === typeof iterator.throw &&
942
- iterator.throw(reason).then(error, error);
943
- }
925
+ iterator.throw(reason).then(error, error));
944
926
  }
945
927
  iterable = iterable === iterator;
946
928
  var streamTask = createTask(
@@ -961,11 +943,8 @@ function serializeAsyncIterable(request, task, iterable, iterator) {
961
943
  }
962
944
  function emitHint(request, code, model) {
963
945
  model = stringify(model);
964
- var id = request.nextChunkId++;
965
- code = "H" + code;
966
- code = id.toString(16) + ":" + code;
967
- model = stringToChunk(code + model + "\n");
968
- request.completedHintChunks.push(model);
946
+ code = stringToChunk(":H" + code + model + "\n");
947
+ request.completedHintChunks.push(code);
969
948
  enqueueFlush(request);
970
949
  }
971
950
  function readThenable(thenable) {
@@ -996,63 +975,57 @@ function createLazyWrapperAroundWakeable(wakeable) {
996
975
  return { $$typeof: REACT_LAZY_TYPE, _payload: wakeable, _init: readThenable };
997
976
  }
998
977
  function voidHandler() {}
978
+ function processServerComponentReturnValue(request, task, Component, result) {
979
+ if (
980
+ "object" !== typeof result ||
981
+ null === result ||
982
+ result.$$typeof === CLIENT_REFERENCE_TAG$1
983
+ )
984
+ return result;
985
+ if ("function" === typeof result.then)
986
+ return "fulfilled" === result.status
987
+ ? result.value
988
+ : createLazyWrapperAroundWakeable(result);
989
+ var iteratorFn = getIteratorFn(result);
990
+ return iteratorFn
991
+ ? ((request = {}),
992
+ (request[Symbol.iterator] = function () {
993
+ return iteratorFn.call(result);
994
+ }),
995
+ request)
996
+ : "function" !== typeof result[ASYNC_ITERATOR] ||
997
+ ("function" === typeof ReadableStream &&
998
+ result instanceof ReadableStream)
999
+ ? result
1000
+ : ((request = {}),
1001
+ (request[ASYNC_ITERATOR] = function () {
1002
+ return result[ASYNC_ITERATOR]();
1003
+ }),
1004
+ request);
1005
+ }
999
1006
  function renderFunctionComponent(request, task, key, Component, props) {
1000
1007
  var prevThenableState = task.thenableState;
1001
1008
  task.thenableState = null;
1002
1009
  thenableIndexCounter = 0;
1003
1010
  thenableState = prevThenableState;
1004
- Component = Component(props, void 0);
1011
+ props = Component(props, void 0);
1005
1012
  if (12 === request.status)
1006
1013
  throw (
1007
- ("object" === typeof Component &&
1008
- null !== Component &&
1009
- "function" === typeof Component.then &&
1010
- Component.$$typeof !== CLIENT_REFERENCE_TAG$1 &&
1011
- Component.then(voidHandler, voidHandler),
1014
+ ("object" === typeof props &&
1015
+ null !== props &&
1016
+ "function" === typeof props.then &&
1017
+ props.$$typeof !== CLIENT_REFERENCE_TAG$1 &&
1018
+ props.then(voidHandler, voidHandler),
1012
1019
  null)
1013
1020
  );
1014
- if (
1015
- "object" === typeof Component &&
1016
- null !== Component &&
1017
- Component.$$typeof !== CLIENT_REFERENCE_TAG$1
1018
- ) {
1019
- if ("function" === typeof Component.then) {
1020
- props = Component;
1021
- if ("fulfilled" === props.status) return props.value;
1022
- Component = createLazyWrapperAroundWakeable(Component);
1023
- }
1024
- var iteratorFn = getIteratorFn(Component);
1025
- if (iteratorFn) {
1026
- var iterableChild = Component;
1027
- Component = {};
1028
- Component =
1029
- ((Component[Symbol.iterator] = function () {
1030
- return iteratorFn.call(iterableChild);
1031
- }),
1032
- Component);
1033
- } else if (
1034
- !(
1035
- "function" !== typeof Component[ASYNC_ITERATOR] ||
1036
- ("function" === typeof ReadableStream &&
1037
- Component instanceof ReadableStream)
1038
- )
1039
- ) {
1040
- var iterableChild$10 = Component;
1041
- Component = {};
1042
- Component =
1043
- ((Component[ASYNC_ITERATOR] = function () {
1044
- return iterableChild$10[ASYNC_ITERATOR]();
1045
- }),
1046
- Component);
1047
- }
1048
- }
1049
- props = task.keyPath;
1021
+ props = processServerComponentReturnValue(request, task, Component, props);
1022
+ Component = task.keyPath;
1050
1023
  prevThenableState = task.implicitSlot;
1051
1024
  null !== key
1052
- ? (task.keyPath = null === props ? key : props + "," + key)
1053
- : null === props && (task.implicitSlot = !0);
1054
- request = renderModelDestructive(request, task, emptyRoot, "", Component);
1055
- task.keyPath = props;
1025
+ ? (task.keyPath = null === Component ? key : Component + "," + key)
1026
+ : null === Component && (task.implicitSlot = !0);
1027
+ request = renderModelDestructive(request, task, emptyRoot, "", props);
1028
+ task.keyPath = Component;
1056
1029
  task.implicitSlot = prevThenableState;
1057
1030
  return request;
1058
1031
  }
@@ -1311,24 +1284,20 @@ function serializeBlob(request, blob) {
1311
1284
  );
1312
1285
  }
1313
1286
  function error(reason) {
1314
- if (!aborted) {
1315
- aborted = !0;
1316
- request.abortListeners.delete(abortBlob);
1317
- var digest = logRecoverableError(request, reason, newTask);
1318
- emitErrorChunk(request, newTask.id, digest);
1319
- enqueueFlush(request);
1320
- reader.cancel(reason).then(error, error);
1321
- }
1287
+ aborted ||
1288
+ ((aborted = !0),
1289
+ request.abortListeners.delete(abortBlob),
1290
+ erroredTask(request, newTask, reason),
1291
+ enqueueFlush(request),
1292
+ reader.cancel(reason).then(error, error));
1322
1293
  }
1323
1294
  function abortBlob(reason) {
1324
- if (!aborted) {
1325
- aborted = !0;
1326
- request.abortListeners.delete(abortBlob);
1327
- var digest = logRecoverableError(request, reason, newTask);
1328
- emitErrorChunk(request, newTask.id, digest);
1329
- enqueueFlush(request);
1330
- reader.cancel(reason).then(error, error);
1331
- }
1295
+ aborted ||
1296
+ ((aborted = !0),
1297
+ request.abortListeners.delete(abortBlob),
1298
+ erroredTask(request, newTask, reason),
1299
+ enqueueFlush(request),
1300
+ reader.cancel(reason).then(error, error));
1332
1301
  }
1333
1302
  var model = [blob.type],
1334
1303
  newTask = createTask(request, model, null, !1, request.abortableTasks),
@@ -1730,6 +1699,12 @@ function emitChunk(request, task, value) {
1730
1699
  : ((value = stringify(value, task.toJSON)),
1731
1700
  emitModelChunk(request, task.id, value));
1732
1701
  }
1702
+ function erroredTask(request, task, error) {
1703
+ request.abortableTasks.delete(task);
1704
+ task.status = 4;
1705
+ error = logRecoverableError(request, error, task);
1706
+ emitErrorChunk(request, task.id, error);
1707
+ }
1733
1708
  var emptyRoot = {};
1734
1709
  function retryTask(request, task) {
1735
1710
  if (0 === task.status) {
@@ -1775,12 +1750,7 @@ function retryTask(request, task) {
1775
1750
  task.thenableState = getThenableStateAfterSuspending();
1776
1751
  var ping = task.ping;
1777
1752
  x.then(ping, ping);
1778
- } else {
1779
- request.abortableTasks.delete(task);
1780
- task.status = 4;
1781
- var digest = logRecoverableError(request, x, task);
1782
- emitErrorChunk(request, task.id, digest);
1783
- }
1753
+ } else erroredTask(request, task, x);
1784
1754
  }
1785
1755
  } finally {
1786
1756
  }
@@ -1869,6 +1839,18 @@ function enqueueFlush(request) {
1869
1839
  destination && flushCompletedChunks(request, destination);
1870
1840
  }));
1871
1841
  }
1842
+ function startFlowing(request, destination) {
1843
+ if (13 === request.status)
1844
+ (request.status = 14), closeWithError(destination, request.fatalError);
1845
+ else if (14 !== request.status && null === request.destination) {
1846
+ request.destination = destination;
1847
+ try {
1848
+ flushCompletedChunks(request, destination);
1849
+ } catch (error) {
1850
+ logRecoverableError(request, error, null), fatalError(request, error);
1851
+ }
1852
+ }
1853
+ }
1872
1854
  function abort(request, reason) {
1873
1855
  try {
1874
1856
  11 >= request.status && (request.status = 12);
@@ -1901,7 +1883,7 @@ function abort(request, reason) {
1901
1883
  }
1902
1884
  var abortListeners = request.abortListeners;
1903
1885
  if (0 < abortListeners.size) {
1904
- var error$23 =
1886
+ var error$22 =
1905
1887
  void 0 === reason
1906
1888
  ? Error("The render was aborted by the server without a reason.")
1907
1889
  : "object" === typeof reason &&
@@ -1910,14 +1892,14 @@ function abort(request, reason) {
1910
1892
  ? Error("The render was aborted by the server with a promise.")
1911
1893
  : reason;
1912
1894
  abortListeners.forEach(function (callback) {
1913
- return callback(error$23);
1895
+ return callback(error$22);
1914
1896
  });
1915
1897
  abortListeners.clear();
1916
1898
  }
1917
1899
  null !== request.destination &&
1918
1900
  flushCompletedChunks(request, request.destination);
1919
- } catch (error$24) {
1920
- logRecoverableError(request, error$24, null), fatalError(request, error$24);
1901
+ } catch (error$23) {
1902
+ logRecoverableError(request, error$23, null), fatalError(request, error$23);
1921
1903
  }
1922
1904
  }
1923
1905
  function resolveServerReference(bundlerConfig, id) {
@@ -2371,8 +2353,8 @@ function parseReadableStream(response, reference, type) {
2371
2353
  (previousBlockedChunk = chunk));
2372
2354
  } else {
2373
2355
  chunk = previousBlockedChunk;
2374
- var chunk$27 = createPendingChunk(response);
2375
- chunk$27.then(
2356
+ var chunk$26 = createPendingChunk(response);
2357
+ chunk$26.then(
2376
2358
  function (v) {
2377
2359
  return controller.enqueue(v);
2378
2360
  },
@@ -2380,10 +2362,10 @@ function parseReadableStream(response, reference, type) {
2380
2362
  return controller.error(e);
2381
2363
  }
2382
2364
  );
2383
- previousBlockedChunk = chunk$27;
2365
+ previousBlockedChunk = chunk$26;
2384
2366
  chunk.then(function () {
2385
- previousBlockedChunk === chunk$27 && (previousBlockedChunk = null);
2386
- resolveModelChunk(chunk$27, json, -1);
2367
+ previousBlockedChunk === chunk$26 && (previousBlockedChunk = null);
2368
+ resolveModelChunk(chunk$26, json, -1);
2387
2369
  });
2388
2370
  }
2389
2371
  },
@@ -2755,17 +2737,7 @@ exports.renderToReadableStream = function (model, webpackMap, options) {
2755
2737
  startWork(request);
2756
2738
  },
2757
2739
  pull: function (controller) {
2758
- if (13 === request.status)
2759
- (request.status = 14), closeWithError(controller, request.fatalError);
2760
- else if (14 !== request.status && null === request.destination) {
2761
- request.destination = controller;
2762
- try {
2763
- flushCompletedChunks(request, controller);
2764
- } catch (error) {
2765
- logRecoverableError(request, error, null),
2766
- fatalError(request, error);
2767
- }
2768
- }
2740
+ startFlowing(request, controller);
2769
2741
  },
2770
2742
  cancel: function (reason) {
2771
2743
  request.destination = null;
@@ -2775,3 +2747,50 @@ exports.renderToReadableStream = function (model, webpackMap, options) {
2775
2747
  { highWaterMark: 0 }
2776
2748
  );
2777
2749
  };
2750
+ exports.unstable_prerender = function (model, webpackMap, options) {
2751
+ return new Promise(function (resolve, reject) {
2752
+ var request = new RequestInstance(
2753
+ 21,
2754
+ model,
2755
+ webpackMap,
2756
+ options ? options.onError : void 0,
2757
+ options ? options.identifierPrefix : void 0,
2758
+ options ? options.onPostpone : void 0,
2759
+ options ? options.temporaryReferences : void 0,
2760
+ void 0,
2761
+ void 0,
2762
+ function () {
2763
+ var stream = new ReadableStream(
2764
+ {
2765
+ type: "bytes",
2766
+ start: function () {
2767
+ startWork(request);
2768
+ },
2769
+ pull: function (controller) {
2770
+ startFlowing(request, controller);
2771
+ },
2772
+ cancel: function (reason) {
2773
+ request.destination = null;
2774
+ abort(request, reason);
2775
+ }
2776
+ },
2777
+ { highWaterMark: 0 }
2778
+ );
2779
+ resolve({ prelude: stream });
2780
+ },
2781
+ reject
2782
+ );
2783
+ if (options && options.signal) {
2784
+ var signal = options.signal;
2785
+ if (signal.aborted) abort(request, signal.reason);
2786
+ else {
2787
+ var listener = function () {
2788
+ abort(request, signal.reason);
2789
+ signal.removeEventListener("abort", listener);
2790
+ };
2791
+ signal.addEventListener("abort", listener);
2792
+ }
2793
+ }
2794
+ startWork(request);
2795
+ });
2796
+ };