react-server-dom-webpack 19.0.0-rc-99da76f23a-20240606 → 19.0.0-rc-cc1ec60d0d-20240607

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.
@@ -2784,9 +2784,16 @@ function stopStream(response, id, row) {
2784
2784
 
2785
2785
  function resolveErrorDev(response, id, digest, message, stack) {
2786
2786
 
2787
+ var error;
2788
+
2789
+ {
2790
+ // Executing Error within a native stack isn't really limited to owner stacks
2791
+ // but we gate it behind the same flag for now while iterating.
2792
+ // eslint-disable-next-line react-internal/prod-error-codes
2793
+ error = Error(message || 'An error occurred in the Server Components render but no message was provided');
2794
+ error.stack = stack;
2795
+ }
2787
2796
 
2788
- var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
2789
- error.stack = stack;
2790
2797
  error.digest = digest;
2791
2798
  var errorWithDigest = error;
2792
2799
  var chunks = response._chunks;
@@ -3038,9 +3038,16 @@ function stopStream(response, id, row) {
3038
3038
 
3039
3039
  function resolveErrorDev(response, id, digest, message, stack) {
3040
3040
 
3041
+ var error;
3042
+
3043
+ {
3044
+ // Executing Error within a native stack isn't really limited to owner stacks
3045
+ // but we gate it behind the same flag for now while iterating.
3046
+ // eslint-disable-next-line react-internal/prod-error-codes
3047
+ error = Error(message || 'An error occurred in the Server Components render but no message was provided');
3048
+ error.stack = stack;
3049
+ }
3041
3050
 
3042
- var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
3043
- error.stack = stack;
3044
3051
  error.digest = digest;
3045
3052
  var errorWithDigest = error;
3046
3053
  var chunks = response._chunks;
@@ -3036,9 +3036,16 @@ function stopStream(response, id, row) {
3036
3036
 
3037
3037
  function resolveErrorDev(response, id, digest, message, stack) {
3038
3038
 
3039
+ var error;
3040
+
3041
+ {
3042
+ // Executing Error within a native stack isn't really limited to owner stacks
3043
+ // but we gate it behind the same flag for now while iterating.
3044
+ // eslint-disable-next-line react-internal/prod-error-codes
3045
+ error = Error(message || 'An error occurred in the Server Components render but no message was provided');
3046
+ error.stack = stack;
3047
+ }
3039
3048
 
3040
- var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
3041
- error.stack = stack;
3042
3049
  error.digest = digest;
3043
3050
  var errorWithDigest = error;
3044
3051
  var chunks = response._chunks;
@@ -2989,9 +2989,16 @@ function stopStream(response, id, row) {
2989
2989
 
2990
2990
  function resolveErrorDev(response, id, digest, message, stack) {
2991
2991
 
2992
+ var error;
2993
+
2994
+ {
2995
+ // Executing Error within a native stack isn't really limited to owner stacks
2996
+ // but we gate it behind the same flag for now while iterating.
2997
+ // eslint-disable-next-line react-internal/prod-error-codes
2998
+ error = Error(message || 'An error occurred in the Server Components render but no message was provided');
2999
+ error.stack = stack;
3000
+ }
2992
3001
 
2993
- var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
2994
- error.stack = stack;
2995
3002
  error.digest = digest;
2996
3003
  var errorWithDigest = error;
2997
3004
  var chunks = response._chunks;
@@ -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) {