react-server-dom-webpack 19.0.0-canary-96c584661-20240412 → 19.0.0-canary-657428a9e-20240416

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 (37) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +40 -7
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +37 -6
  3. package/cjs/react-server-dom-webpack-client.browser.production.min.js +7 -7
  4. package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -1
  5. package/cjs/react-server-dom-webpack-client.edge.development.js +40 -7
  6. package/cjs/react-server-dom-webpack-client.edge.production.js +37 -6
  7. package/cjs/react-server-dom-webpack-client.edge.production.min.js +18 -18
  8. package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -1
  9. package/cjs/react-server-dom-webpack-client.node.development.js +40 -7
  10. package/cjs/react-server-dom-webpack-client.node.production.js +37 -6
  11. package/cjs/react-server-dom-webpack-client.node.production.min.js +4 -4
  12. package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -1
  13. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +40 -7
  14. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +37 -6
  15. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +16 -16
  16. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -1
  17. package/cjs/react-server-dom-webpack-server.browser.development.js +127 -86
  18. package/cjs/react-server-dom-webpack-server.browser.production.js +95 -64
  19. package/cjs/react-server-dom-webpack-server.browser.production.min.js +59 -58
  20. package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -1
  21. package/cjs/react-server-dom-webpack-server.edge.development.js +127 -86
  22. package/cjs/react-server-dom-webpack-server.edge.production.js +95 -64
  23. package/cjs/react-server-dom-webpack-server.edge.production.min.js +60 -60
  24. package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -1
  25. package/cjs/react-server-dom-webpack-server.node.development.js +127 -86
  26. package/cjs/react-server-dom-webpack-server.node.production.js +95 -64
  27. package/cjs/react-server-dom-webpack-server.node.production.min.js +60 -61
  28. package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -1
  29. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +127 -86
  30. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +95 -64
  31. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +58 -58
  32. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -1
  33. package/package.json +3 -3
  34. package/umd/react-server-dom-webpack-client.browser.development.js +40 -7
  35. package/umd/react-server-dom-webpack-client.browser.production.min.js +19 -19
  36. package/umd/react-server-dom-webpack-server.browser.development.js +127 -86
  37. package/umd/react-server-dom-webpack-server.browser.production.min.js +55 -54
@@ -972,7 +972,14 @@ function trackUsedThenable(thenableState, thenable, index) {
972
972
 
973
973
  default:
974
974
  {
975
- if (typeof thenable.status === 'string') ; else {
975
+ if (typeof thenable.status === 'string') {
976
+ // Only instrument the thenable if the status if not defined. If
977
+ // it's defined, but an unknown value, assume it's been instrumented by
978
+ // some custom userspace implementation. We treat it as "pending".
979
+ // Attach a dummy listener, to ensure that any lazy initialization can
980
+ // happen. Flight lazily parses JSON when the value is actually awaited.
981
+ thenable.then(noop, noop);
982
+ } else {
976
983
  var pendingThenable = thenable;
977
984
  pendingThenable.status = 'pending';
978
985
  pendingThenable.then(function (fulfilledValue) {
@@ -987,21 +994,22 @@ function trackUsedThenable(thenableState, thenable, index) {
987
994
  rejectedThenable.status = 'rejected';
988
995
  rejectedThenable.reason = error;
989
996
  }
990
- }); // Check one more time in case the thenable resolved synchronously
997
+ });
998
+ } // Check one more time in case the thenable resolved synchronously
991
999
 
992
- switch (thenable.status) {
993
- case 'fulfilled':
994
- {
995
- var fulfilledThenable = thenable;
996
- return fulfilledThenable.value;
997
- }
998
1000
 
999
- case 'rejected':
1000
- {
1001
- var rejectedThenable = thenable;
1002
- throw rejectedThenable.reason;
1003
- }
1004
- }
1001
+ switch (thenable.status) {
1002
+ case 'fulfilled':
1003
+ {
1004
+ var fulfilledThenable = thenable;
1005
+ return fulfilledThenable.value;
1006
+ }
1007
+
1008
+ case 'rejected':
1009
+ {
1010
+ var rejectedThenable = thenable;
1011
+ throw rejectedThenable.reason;
1012
+ }
1005
1013
  } // Suspend.
1006
1014
  //
1007
1015
  // Throwing here is an implementation detail that allows us to unwind the
@@ -1568,6 +1576,7 @@ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpo
1568
1576
  nextChunkId: 0,
1569
1577
  pendingChunks: 0,
1570
1578
  hints: hints,
1579
+ abortListeners: new Set(),
1571
1580
  abortableTasks: abortSet,
1572
1581
  pingedTasks: pingedTasks,
1573
1582
  completedImportChunks: [],
@@ -1680,10 +1689,7 @@ function serializeThenable(request, task, thenable) {
1680
1689
  }
1681
1690
 
1682
1691
  request.abortableTasks.delete(newTask);
1683
-
1684
- if (request.destination !== null) {
1685
- flushCompletedChunks(request, request.destination);
1686
- }
1692
+ enqueueFlush(request);
1687
1693
  });
1688
1694
  return newTask.id;
1689
1695
  }
@@ -1849,24 +1855,6 @@ function renderFunctionComponent(request, task, key, Component, props, owner) {
1849
1855
  }
1850
1856
 
1851
1857
  function renderFragment(request, task, children) {
1852
- {
1853
- var debugInfo = children._debugInfo;
1854
-
1855
- if (debugInfo) {
1856
- // If this came from Flight, forward any debug info into this new row.
1857
- if (debugID === null) {
1858
- // We don't have a chunk to assign debug info. We need to outline this
1859
- // component to assign it an ID.
1860
- return outlineTask(request, task);
1861
- } else {
1862
- // Forward any debug info we have the first time we see it.
1863
- // We do this after init so that we have received all the debug info
1864
- // from the server by the time we emit it.
1865
- forwardDebugInfo(request, debugID, debugInfo);
1866
- }
1867
- }
1868
- }
1869
-
1870
1858
  if (task.keyPath !== null) {
1871
1859
  // We have a Server Component that specifies a key but we're now splitting
1872
1860
  // the tree using a fragment.
@@ -1898,6 +1886,28 @@ function renderFragment(request, task, children) {
1898
1886
  // before recursing here.
1899
1887
 
1900
1888
 
1889
+ {
1890
+ var debugInfo = children._debugInfo;
1891
+
1892
+ if (debugInfo) {
1893
+ // If this came from Flight, forward any debug info into this new row.
1894
+ if (debugID === null) {
1895
+ // We don't have a chunk to assign debug info. We need to outline this
1896
+ // component to assign it an ID.
1897
+ return outlineTask(request, task);
1898
+ } else {
1899
+ // Forward any debug info we have the first time we see it.
1900
+ // We do this after init so that we have received all the debug info
1901
+ // from the server by the time we emit it.
1902
+ forwardDebugInfo(request, debugID, debugInfo);
1903
+ } // Since we're rendering this array again, create a copy that doesn't
1904
+ // have the debug info so we avoid outlining or emitting debug info again.
1905
+
1906
+
1907
+ children = Array.from(children);
1908
+ }
1909
+ }
1910
+
1901
1911
  return children;
1902
1912
  }
1903
1913
 
@@ -2239,13 +2249,9 @@ function serializeTemporaryReference(request, temporaryReference) {
2239
2249
  }
2240
2250
 
2241
2251
  function serializeLargeTextString(request, text) {
2242
- request.pendingChunks += 2;
2252
+ request.pendingChunks++;
2243
2253
  var textId = request.nextChunkId++;
2244
- var textChunk = stringToChunk(text);
2245
- var binaryLength = byteLengthOfChunk(textChunk);
2246
- var row = textId.toString(16) + ':T' + binaryLength.toString(16) + ',';
2247
- var headerChunk = stringToChunk(row);
2248
- request.completedRegularChunks.push(headerChunk, textChunk);
2254
+ emitTextChunk(request, textId, text);
2249
2255
  return serializeByValueID(textId);
2250
2256
  }
2251
2257
 
@@ -2560,7 +2566,7 @@ function renderModelDestructive(request, task, parent, parentPropertyName, value
2560
2566
 
2561
2567
  if (iteratorFn) {
2562
2568
  return renderFragment(request, task, Array.from(value));
2563
- } // Verify that this is a simple plain object.
2569
+ }
2564
2570
 
2565
2571
 
2566
2572
  var proto = getPrototypeOf(value);
@@ -2835,6 +2841,16 @@ function emitDebugChunk(request, id, debugInfo) {
2835
2841
  request.completedRegularChunks.push(processedChunk);
2836
2842
  }
2837
2843
 
2844
+ function emitTextChunk(request, id, text) {
2845
+ request.pendingChunks++; // Extra chunk for the header.
2846
+
2847
+ var textChunk = stringToChunk(text);
2848
+ var binaryLength = byteLengthOfChunk(textChunk);
2849
+ var row = id.toString(16) + ':T' + binaryLength.toString(16) + ',';
2850
+ var headerChunk = stringToChunk(row);
2851
+ request.completedRegularChunks.push(headerChunk, textChunk);
2852
+ }
2853
+
2838
2854
  function serializeEval(source) {
2839
2855
 
2840
2856
  return '$E' + source;
@@ -3034,6 +3050,22 @@ function forwardDebugInfo(request, id, debugInfo) {
3034
3050
  }
3035
3051
  }
3036
3052
 
3053
+ function emitChunk(request, task, value) {
3054
+ var id = task.id; // For certain types we have special types, we typically outlined them but
3055
+ // we can emit them directly for this row instead of through an indirection.
3056
+
3057
+ if (typeof value === 'string') {
3058
+
3059
+ emitTextChunk(request, id, value);
3060
+ return;
3061
+ }
3062
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
3063
+
3064
+
3065
+ var json = stringify(value, task.toJSON);
3066
+ emitModelChunk(request, task.id, json);
3067
+ }
3068
+
3037
3069
  var emptyRoot = {};
3038
3070
 
3039
3071
  function retryTask(request, task) {
@@ -3070,21 +3102,19 @@ function retryTask(request, task) {
3070
3102
 
3071
3103
  task.keyPath = null;
3072
3104
  task.implicitSlot = false;
3073
- var json;
3074
3105
 
3075
3106
  if (typeof resolvedModel === 'object' && resolvedModel !== null) {
3076
3107
  // Object might contain unresolved values like additional elements.
3077
3108
  // This is simulating what the JSON loop would do if this was part of it.
3078
- // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
3079
- json = stringify(resolvedModel, task.toJSON);
3109
+ emitChunk(request, task, resolvedModel);
3080
3110
  } else {
3081
3111
  // If the value is a string, it means it's a terminal value and we already escaped it
3082
3112
  // We don't need to escape it again so it's not passed the toJSON replacer.
3083
3113
  // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
3084
- json = stringify(resolvedModel);
3114
+ var json = stringify(resolvedModel);
3115
+ emitModelChunk(request, task.id, json);
3085
3116
  }
3086
3117
 
3087
- emitModelChunk(request, task.id, json);
3088
3118
  request.abortableTasks.delete(task);
3089
3119
  task.status = COMPLETED;
3090
3120
  } catch (thrownValue) {
@@ -3242,6 +3272,7 @@ function flushCompletedChunks(request, destination) {
3242
3272
  if (request.pendingChunks === 0) {
3243
3273
 
3244
3274
  close$1(destination);
3275
+ request.destination = null;
3245
3276
  }
3246
3277
  }
3247
3278
 
@@ -3299,11 +3330,10 @@ function stopFlowing(request) {
3299
3330
 
3300
3331
  function abort(request, reason) {
3301
3332
  try {
3302
- var abortableTasks = request.abortableTasks;
3333
+ var abortableTasks = request.abortableTasks; // We have tasks to abort. We'll emit one error row and then emit a reference
3334
+ // to that row from every row that's still remaining.
3303
3335
 
3304
3336
  if (abortableTasks.size > 0) {
3305
- // We have tasks to abort. We'll emit one error row and then emit a reference
3306
- // to that row from every row that's still remaining.
3307
3337
  request.pendingChunks++;
3308
3338
  var errorId = request.nextChunkId++;
3309
3339
 
@@ -3319,6 +3349,21 @@ function abort(request, reason) {
3319
3349
  abortableTasks.clear();
3320
3350
  }
3321
3351
 
3352
+ var abortListeners = request.abortListeners;
3353
+
3354
+ if (abortListeners.size > 0) {
3355
+ var _error;
3356
+
3357
+ if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
3358
+ _error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
3359
+ }
3360
+
3361
+ abortListeners.forEach(function (callback) {
3362
+ return callback(_error);
3363
+ });
3364
+ abortListeners.clear();
3365
+ }
3366
+
3322
3367
  if (request.destination !== null) {
3323
3368
  flushCompletedChunks(request, request.destination);
3324
3369
  }
@@ -3774,7 +3819,7 @@ function getOutlinedModel(response, id) {
3774
3819
  return chunk.value;
3775
3820
  }
3776
3821
 
3777
- function parseModelString(response, parentObject, key, value) {
3822
+ function parseModelString(response, obj, key, value) {
3778
3823
  if (value[0] === '$') {
3779
3824
  switch (value[1]) {
3780
3825
  case '$':
@@ -3786,19 +3831,21 @@ function parseModelString(response, parentObject, key, value) {
3786
3831
  case '@':
3787
3832
  {
3788
3833
  // Promise
3789
- var id = parseInt(value.slice(2), 16);
3790
- var chunk = getChunk(response, id);
3791
- return chunk;
3834
+ var _id = parseInt(value.slice(2), 16);
3835
+
3836
+ var _chunk = getChunk(response, _id);
3837
+
3838
+ return _chunk;
3792
3839
  }
3793
3840
 
3794
3841
  case 'F':
3795
3842
  {
3796
3843
  // Server Reference
3797
- var _id = parseInt(value.slice(2), 16); // TODO: Just encode this in the reference inline instead of as a model.
3844
+ var _id2 = parseInt(value.slice(2), 16); // TODO: Just encode this in the reference inline instead of as a model.
3798
3845
 
3799
3846
 
3800
- var metaData = getOutlinedModel(response, _id);
3801
- return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
3847
+ var metaData = getOutlinedModel(response, _id2);
3848
+ return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, obj, key);
3802
3849
  }
3803
3850
 
3804
3851
  case 'T':
@@ -3810,18 +3857,18 @@ function parseModelString(response, parentObject, key, value) {
3810
3857
  case 'Q':
3811
3858
  {
3812
3859
  // Map
3813
- var _id2 = parseInt(value.slice(2), 16);
3860
+ var _id3 = parseInt(value.slice(2), 16);
3814
3861
 
3815
- var data = getOutlinedModel(response, _id2);
3862
+ var data = getOutlinedModel(response, _id3);
3816
3863
  return new Map(data);
3817
3864
  }
3818
3865
 
3819
3866
  case 'W':
3820
3867
  {
3821
3868
  // Set
3822
- var _id3 = parseInt(value.slice(2), 16);
3869
+ var _id4 = parseInt(value.slice(2), 16);
3823
3870
 
3824
- var _data = getOutlinedModel(response, _id3);
3871
+ var _data = getOutlinedModel(response, _id4);
3825
3872
 
3826
3873
  return new Set(_data);
3827
3874
  }
@@ -3887,37 +3934,31 @@ function parseModelString(response, parentObject, key, value) {
3887
3934
  // BigInt
3888
3935
  return BigInt(value.slice(2));
3889
3936
  }
3937
+ }
3890
3938
 
3891
- default:
3892
- {
3893
- // We assume that anything else is a reference ID.
3894
- var _id4 = parseInt(value.slice(1), 16);
3895
-
3896
- var _chunk = getChunk(response, _id4);
3897
-
3898
- switch (_chunk.status) {
3899
- case RESOLVED_MODEL:
3900
- initializeModelChunk(_chunk);
3901
- break;
3902
- } // The status might have changed after initialization.
3903
3939
 
3940
+ var id = parseInt(value.slice(1), 16);
3941
+ var chunk = getChunk(response, id);
3904
3942
 
3905
- switch (_chunk.status) {
3906
- case INITIALIZED:
3907
- return _chunk.value;
3943
+ switch (chunk.status) {
3944
+ case RESOLVED_MODEL:
3945
+ initializeModelChunk(chunk);
3946
+ break;
3947
+ } // The status might have changed after initialization.
3908
3948
 
3909
- case PENDING:
3910
- case BLOCKED:
3911
- var parentChunk = initializingChunk;
3912
3949
 
3913
- _chunk.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
3950
+ switch (chunk.status) {
3951
+ case INITIALIZED:
3952
+ return chunk.value;
3914
3953
 
3915
- return null;
3954
+ case PENDING:
3955
+ case BLOCKED:
3956
+ var parentChunk = initializingChunk;
3957
+ chunk.then(createModelResolver(parentChunk, obj, key), createModelReject(parentChunk));
3958
+ return null;
3916
3959
 
3917
- default:
3918
- throw _chunk.reason;
3919
- }
3920
- }
3960
+ default:
3961
+ throw chunk.reason;
3921
3962
  }
3922
3963
  }
3923
3964
 
@@ -920,7 +920,14 @@ function trackUsedThenable(thenableState, thenable, index) {
920
920
 
921
921
  default:
922
922
  {
923
- if (typeof thenable.status === 'string') ; else {
923
+ if (typeof thenable.status === 'string') {
924
+ // Only instrument the thenable if the status if not defined. If
925
+ // it's defined, but an unknown value, assume it's been instrumented by
926
+ // some custom userspace implementation. We treat it as "pending".
927
+ // Attach a dummy listener, to ensure that any lazy initialization can
928
+ // happen. Flight lazily parses JSON when the value is actually awaited.
929
+ thenable.then(noop, noop);
930
+ } else {
924
931
  const pendingThenable = thenable;
925
932
  pendingThenable.status = 'pending';
926
933
  pendingThenable.then(fulfilledValue => {
@@ -935,21 +942,22 @@ function trackUsedThenable(thenableState, thenable, index) {
935
942
  rejectedThenable.status = 'rejected';
936
943
  rejectedThenable.reason = error;
937
944
  }
938
- }); // Check one more time in case the thenable resolved synchronously
939
-
940
- switch (thenable.status) {
941
- case 'fulfilled':
942
- {
943
- const fulfilledThenable = thenable;
944
- return fulfilledThenable.value;
945
- }
946
-
947
- case 'rejected':
948
- {
949
- const rejectedThenable = thenable;
950
- throw rejectedThenable.reason;
951
- }
952
- }
945
+ });
946
+ } // Check one more time in case the thenable resolved synchronously
947
+
948
+
949
+ switch (thenable.status) {
950
+ case 'fulfilled':
951
+ {
952
+ const fulfilledThenable = thenable;
953
+ return fulfilledThenable.value;
954
+ }
955
+
956
+ case 'rejected':
957
+ {
958
+ const rejectedThenable = thenable;
959
+ throw rejectedThenable.reason;
960
+ }
953
961
  } // Suspend.
954
962
  //
955
963
  // Throwing here is an implementation detail that allows us to unwind the
@@ -1385,6 +1393,7 @@ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpo
1385
1393
  nextChunkId: 0,
1386
1394
  pendingChunks: 0,
1387
1395
  hints,
1396
+ abortListeners: new Set(),
1388
1397
  abortableTasks: abortSet,
1389
1398
  pingedTasks: pingedTasks,
1390
1399
  completedImportChunks: [],
@@ -1482,10 +1491,7 @@ function serializeThenable(request, task, thenable) {
1482
1491
  }
1483
1492
 
1484
1493
  request.abortableTasks.delete(newTask);
1485
-
1486
- if (request.destination !== null) {
1487
- flushCompletedChunks(request, request.destination);
1488
- }
1494
+ enqueueFlush(request);
1489
1495
  });
1490
1496
  return newTask.id;
1491
1497
  }
@@ -1611,7 +1617,6 @@ function renderFunctionComponent(request, task, key, Component, props, owner) {
1611
1617
  }
1612
1618
 
1613
1619
  function renderFragment(request, task, children) {
1614
-
1615
1620
  if (task.keyPath !== null) {
1616
1621
  // We have a Server Component that specifies a key but we're now splitting
1617
1622
  // the tree using a fragment.
@@ -1638,10 +1643,6 @@ function renderFragment(request, task, children) {
1638
1643
 
1639
1644
  return [fragment];
1640
1645
  } // Since we're yielding here, that implicitly resets the keyPath context on the
1641
- // way up. Which is what we want since we've consumed it. If this changes to
1642
- // be recursive serialization, we need to reset the keyPath and implicitSlot,
1643
- // before recursing here.
1644
-
1645
1646
 
1646
1647
  return children;
1647
1648
  }
@@ -1932,13 +1933,9 @@ function serializeTemporaryReference(request, temporaryReference) {
1932
1933
  }
1933
1934
 
1934
1935
  function serializeLargeTextString(request, text) {
1935
- request.pendingChunks += 2;
1936
+ request.pendingChunks++;
1936
1937
  const textId = request.nextChunkId++;
1937
- const textChunk = stringToChunk(text);
1938
- const binaryLength = byteLengthOfChunk(textChunk);
1939
- const row = textId.toString(16) + ':T' + binaryLength.toString(16) + ',';
1940
- const headerChunk = stringToChunk(row);
1941
- request.completedRegularChunks.push(headerChunk, textChunk);
1938
+ emitTextChunk(request, textId, text);
1942
1939
  return serializeByValueID(textId);
1943
1940
  }
1944
1941
 
@@ -2215,7 +2212,7 @@ function renderModelDestructive(request, task, parent, parentPropertyName, value
2215
2212
 
2216
2213
  if (iteratorFn) {
2217
2214
  return renderFragment(request, task, Array.from(value));
2218
- } // Verify that this is a simple plain object.
2215
+ }
2219
2216
 
2220
2217
 
2221
2218
  const proto = getPrototypeOf(value);
@@ -2420,6 +2417,32 @@ function emitModelChunk(request, id, json) {
2420
2417
  request.completedRegularChunks.push(processedChunk);
2421
2418
  }
2422
2419
 
2420
+ function emitTextChunk(request, id, text) {
2421
+ request.pendingChunks++; // Extra chunk for the header.
2422
+
2423
+ const textChunk = stringToChunk(text);
2424
+ const binaryLength = byteLengthOfChunk(textChunk);
2425
+ const row = id.toString(16) + ':T' + binaryLength.toString(16) + ',';
2426
+ const headerChunk = stringToChunk(row);
2427
+ request.completedRegularChunks.push(headerChunk, textChunk);
2428
+ }
2429
+
2430
+ function emitChunk(request, task, value) {
2431
+ const id = task.id; // For certain types we have special types, we typically outlined them but
2432
+ // we can emit them directly for this row instead of through an indirection.
2433
+
2434
+ if (typeof value === 'string') {
2435
+
2436
+ emitTextChunk(request, id, value);
2437
+ return;
2438
+ }
2439
+ // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2440
+
2441
+
2442
+ const json = stringify(value, task.toJSON);
2443
+ emitModelChunk(request, task.id, json);
2444
+ }
2445
+
2423
2446
  const emptyRoot = {};
2424
2447
 
2425
2448
  function retryTask(request, task) {
@@ -2447,21 +2470,19 @@ function retryTask(request, task) {
2447
2470
 
2448
2471
  task.keyPath = null;
2449
2472
  task.implicitSlot = false;
2450
- let json;
2451
2473
 
2452
2474
  if (typeof resolvedModel === 'object' && resolvedModel !== null) {
2453
2475
  // Object might contain unresolved values like additional elements.
2454
2476
  // This is simulating what the JSON loop would do if this was part of it.
2455
- // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2456
- json = stringify(resolvedModel, task.toJSON);
2477
+ emitChunk(request, task, resolvedModel);
2457
2478
  } else {
2458
2479
  // If the value is a string, it means it's a terminal value and we already escaped it
2459
2480
  // We don't need to escape it again so it's not passed the toJSON replacer.
2460
2481
  // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2461
- json = stringify(resolvedModel);
2482
+ const json = stringify(resolvedModel);
2483
+ emitModelChunk(request, task.id, json);
2462
2484
  }
2463
2485
 
2464
- emitModelChunk(request, task.id, json);
2465
2486
  request.abortableTasks.delete(task);
2466
2487
  task.status = COMPLETED;
2467
2488
  } catch (thrownValue) {
@@ -2613,6 +2634,7 @@ function flushCompletedChunks(request, destination) {
2613
2634
  if (request.pendingChunks === 0) {
2614
2635
 
2615
2636
  close$1(destination);
2637
+ request.destination = null;
2616
2638
  }
2617
2639
  }
2618
2640
 
@@ -2666,11 +2688,10 @@ function stopFlowing(request) {
2666
2688
 
2667
2689
  function abort(request, reason) {
2668
2690
  try {
2669
- const abortableTasks = request.abortableTasks;
2691
+ const abortableTasks = request.abortableTasks; // We have tasks to abort. We'll emit one error row and then emit a reference
2692
+ // to that row from every row that's still remaining.
2670
2693
 
2671
2694
  if (abortableTasks.size > 0) {
2672
- // We have tasks to abort. We'll emit one error row and then emit a reference
2673
- // to that row from every row that's still remaining.
2674
2695
  request.pendingChunks++;
2675
2696
  const errorId = request.nextChunkId++;
2676
2697
 
@@ -2684,6 +2705,19 @@ function abort(request, reason) {
2684
2705
  abortableTasks.clear();
2685
2706
  }
2686
2707
 
2708
+ const abortListeners = request.abortListeners;
2709
+
2710
+ if (abortListeners.size > 0) {
2711
+ let error;
2712
+
2713
+ if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
2714
+ error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
2715
+ }
2716
+
2717
+ abortListeners.forEach(callback => callback(error));
2718
+ abortListeners.clear();
2719
+ }
2720
+
2687
2721
  if (request.destination !== null) {
2688
2722
  flushCompletedChunks(request, request.destination);
2689
2723
  }
@@ -3135,7 +3169,7 @@ function getOutlinedModel(response, id) {
3135
3169
  return chunk.value;
3136
3170
  }
3137
3171
 
3138
- function parseModelString(response, parentObject, key, value) {
3172
+ function parseModelString(response, obj, key, value) {
3139
3173
  if (value[0] === '$') {
3140
3174
  switch (value[1]) {
3141
3175
  case '$':
@@ -3158,7 +3192,7 @@ function parseModelString(response, parentObject, key, value) {
3158
3192
  const id = parseInt(value.slice(2), 16); // TODO: Just encode this in the reference inline instead of as a model.
3159
3193
 
3160
3194
  const metaData = getOutlinedModel(response, id);
3161
- return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
3195
+ return loadServerReference$1(response, metaData.id, metaData.bound, initializingChunk, obj, key);
3162
3196
  }
3163
3197
 
3164
3198
  case 'T':
@@ -3242,34 +3276,31 @@ function parseModelString(response, parentObject, key, value) {
3242
3276
  // BigInt
3243
3277
  return BigInt(value.slice(2));
3244
3278
  }
3279
+ }
3245
3280
 
3246
- default:
3247
- {
3248
- // We assume that anything else is a reference ID.
3249
- const id = parseInt(value.slice(1), 16);
3250
- const chunk = getChunk(response, id);
3251
3281
 
3252
- switch (chunk.status) {
3253
- case RESOLVED_MODEL:
3254
- initializeModelChunk(chunk);
3255
- break;
3256
- } // The status might have changed after initialization.
3282
+ const id = parseInt(value.slice(1), 16);
3283
+ const chunk = getChunk(response, id);
3257
3284
 
3285
+ switch (chunk.status) {
3286
+ case RESOLVED_MODEL:
3287
+ initializeModelChunk(chunk);
3288
+ break;
3289
+ } // The status might have changed after initialization.
3258
3290
 
3259
- switch (chunk.status) {
3260
- case INITIALIZED:
3261
- return chunk.value;
3262
3291
 
3263
- case PENDING:
3264
- case BLOCKED:
3265
- const parentChunk = initializingChunk;
3266
- chunk.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
3267
- return null;
3292
+ switch (chunk.status) {
3293
+ case INITIALIZED:
3294
+ return chunk.value;
3268
3295
 
3269
- default:
3270
- throw chunk.reason;
3271
- }
3272
- }
3296
+ case PENDING:
3297
+ case BLOCKED:
3298
+ const parentChunk = initializingChunk;
3299
+ chunk.then(createModelResolver(parentChunk, obj, key), createModelReject(parentChunk));
3300
+ return null;
3301
+
3302
+ default:
3303
+ throw chunk.reason;
3273
3304
  }
3274
3305
  }
3275
3306