react-server-dom-webpack 19.0.0-rc-20b6f4c0e8-20240607 → 19.0.0-rc-34d0c5e357-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.
@@ -42,9 +42,6 @@ if (!ReactSharedInternalsServer) {
42
42
  throw new Error('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.');
43
43
  }
44
44
 
45
- // -----------------------------------------------------------------------------
46
- var enablePostpone = false;
47
-
48
45
  function error(format) {
49
46
  {
50
47
  {
@@ -52,55 +49,41 @@ function error(format) {
52
49
  args[_key2 - 1] = arguments[_key2];
53
50
  }
54
51
 
55
- printWarning('error', format, args, new Error('react-stack-top-frame'));
52
+ printWarning('error', format, args);
56
53
  }
57
54
  }
58
- } // eslint-disable-next-line react-internal/no-production-logging
55
+ }
59
56
 
60
- function printWarning(level, format, args, currentStack) {
57
+ function printWarning(level, format, args) {
61
58
  // When changing this logic, you might want to also
62
59
  // update consoleWithStackDev.www.js as well.
63
60
  {
64
- var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
61
+ var stack = ReactSharedInternalsServer.getStackAddendum();
65
62
 
66
- if (ReactSharedInternalsServer.getCurrentStack) {
67
- // We only add the current stack to the console when createTask is not supported.
68
- // Since createTask requires DevTools to be open to work, this means that stacks
69
- // can be lost while DevTools isn't open but we can't detect this.
70
- var stack = ReactSharedInternalsServer.getCurrentStack(currentStack);
63
+ if (stack !== '') {
64
+ format += '%s';
65
+ args = args.concat([stack]);
66
+ } // eslint-disable-next-line react-internal/safe-string-coercion
71
67
 
72
- if (stack !== '') {
73
- format += '%s';
74
- args = args.concat([stack]);
75
- }
76
- }
77
68
 
78
- if (isErrorLogger) {
79
- // Don't prefix our default logging formatting in ReactFiberErrorLoggger.
80
- // Don't toString the arguments.
81
- args.unshift(format);
82
- } else {
83
- // TODO: Remove this prefix and stop toStringing in the wrapper and
84
- // instead do it at each callsite as needed.
85
- // Careful: RN currently depends on this prefix
86
- // eslint-disable-next-line react-internal/safe-string-coercion
87
- args = args.map(function (item) {
88
- return String(item);
89
- });
90
- args.unshift('Warning: ' + format);
91
- } // We intentionally don't use spread (or .apply) directly because it
69
+ var argsWithFormat = args.map(function (item) {
70
+ return String(item);
71
+ }); // Careful: RN currently depends on this prefix
72
+
73
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
92
74
  // breaks IE9: https://github.com/facebook/react/issues/13610
93
75
  // eslint-disable-next-line react-internal/no-production-logging
94
76
 
95
-
96
- Function.prototype.apply.call(console[level], console, args);
77
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
97
78
  }
98
79
  }
99
80
 
81
+ // -----------------------------------------------------------------------------
82
+ var enablePostpone = false;
83
+
100
84
  function scheduleWork(callback) {
101
85
  setImmediate(callback);
102
86
  }
103
- var scheduleMicrotask = queueMicrotask;
104
87
  function flushBuffered(destination) {
105
88
  // If we don't have any more data to send right now.
106
89
  // Flush whatever is in the buffer to the wire.
@@ -1593,37 +1576,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1593
1576
 
1594
1577
  var ReactSharedInternals = ReactSharedInternalsServer;
1595
1578
 
1596
- function prepareStackTrace(error, structuredStackTrace) {
1597
- var name = error.name || 'Error';
1598
- var message = error.message || '';
1599
- var stack = name + ': ' + message;
1600
-
1601
- for (var i = 0; i < structuredStackTrace.length; i++) {
1602
- stack += '\n at ' + structuredStackTrace[i].toString();
1603
- }
1604
-
1605
- return stack;
1606
- }
1607
-
1608
- function getStack(error) {
1609
- // We override Error.prepareStackTrace with our own version that normalizes
1610
- // the stack to V8 formatting even if the server uses other formatting.
1611
- // It also ensures that source maps are NOT applied to this since that can
1612
- // be slow we're better off doing that lazily from the client instead of
1613
- // eagerly on the server. If the stack has already been read, then we might
1614
- // not get a normalized stack and it might still have been source mapped.
1615
- // So the client still needs to be resilient to this.
1616
- var previousPrepare = Error.prepareStackTrace;
1617
- Error.prepareStackTrace = prepareStackTrace;
1618
-
1619
- try {
1620
- // eslint-disable-next-line react-internal/safe-string-coercion
1621
- return String(error.stack);
1622
- } finally {
1623
- Error.prepareStackTrace = previousPrepare;
1624
- }
1625
- }
1626
-
1627
1579
  var ObjectPrototype = Object.prototype;
1628
1580
  var stringify = JSON.stringify; // Serializable values
1629
1581
  // Thenable<ReactClientValue>
@@ -1633,8 +1585,6 @@ var PENDING$1 = 0;
1633
1585
  var COMPLETED = 1;
1634
1586
  var ABORTED = 3;
1635
1587
  var ERRORED$1 = 4;
1636
- var RENDERING = 5;
1637
- var AbortSigil = {};
1638
1588
 
1639
1589
  function defaultErrorHandler(error) {
1640
1590
  console['error'](error); // Don't transform to our wrapper
@@ -1644,9 +1594,8 @@ function defaultPostponeHandler(reason) {// Noop
1644
1594
  }
1645
1595
 
1646
1596
  var OPEN = 0;
1647
- var ABORTING = 1;
1648
- var CLOSING = 2;
1649
- var CLOSED = 3;
1597
+ var CLOSING = 1;
1598
+ var CLOSED = 2;
1650
1599
  function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName, temporaryReferences) {
1651
1600
  if (ReactSharedInternals.A !== null && ReactSharedInternals.A !== DefaultAsyncDispatcher) {
1652
1601
  throw new Error('Currently React only supports one RSC renderer at a time.');
@@ -1689,7 +1638,6 @@ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpo
1689
1638
 
1690
1639
  {
1691
1640
  request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1692
- request.didWarnForKey = null;
1693
1641
  }
1694
1642
 
1695
1643
  var rootTask = createTask(request, model, null, false, abortSet);
@@ -1744,16 +1692,6 @@ function serializeThenable(request, task, thenable) {
1744
1692
 
1745
1693
  default:
1746
1694
  {
1747
- if (request.status === ABORTING) {
1748
- // We can no longer accept any resolved values
1749
- newTask.status = ABORTED;
1750
- var errorId = request.fatalError;
1751
- var model = stringify(serializeByValueID(errorId));
1752
- emitModelChunk(request, newTask.id, model);
1753
- request.abortableTasks.delete(newTask);
1754
- return newTask.id;
1755
- }
1756
-
1757
1695
  if (typeof thenable.status === 'string') {
1758
1696
  // Only instrument the thenable if the status if not defined. If
1759
1697
  // it's defined, but an unknown value, assume it's been instrumented by
@@ -2085,8 +2023,7 @@ function callLazyInitInDEV(lazy) {
2085
2023
  }
2086
2024
 
2087
2025
  function renderFunctionComponent(request, task, key, Component, props, owner, // DEV-only
2088
- stack, // DEV-only
2089
- validated) // DEV-only
2026
+ stack) // DEV-only
2090
2027
  {
2091
2028
  // Reset the task's thenable state before continuing, so that if a later
2092
2029
  // component suspends we can reuse the same task object. If the same
@@ -2128,30 +2065,12 @@ validated) // DEV-only
2128
2065
  result = callComponentInDEV(Component, props, componentDebugInfo);
2129
2066
  }
2130
2067
 
2131
- if (request.status === ABORTING) {
2132
- // If we aborted during rendering we should interrupt the render but
2133
- // we don't need to provide an error because the renderer will encode
2134
- // the abort error as the reason.
2135
- throw AbortSigil;
2136
- }
2137
-
2138
- if (typeof result === 'object' && result !== null && !isClientReference(result)) {
2068
+ if (typeof result === 'object' && result !== null) {
2139
2069
  if (typeof result.then === 'function') {
2140
2070
  // When the return value is in children position we can resolve it immediately,
2141
2071
  // to its value without a wrapper if it's synchronously available.
2142
2072
  var thenable = result;
2143
2073
 
2144
- {
2145
- // If the thenable resolves to an element, then it was in a static position,
2146
- // the return value of a Server Component. That doesn't need further validation
2147
- // of keys. The Server Component itself would have had a key.
2148
- thenable.then(function (resolvedValue) {
2149
- if (typeof resolvedValue === 'object' && resolvedValue !== null && resolvedValue.$$typeof === REACT_ELEMENT_TYPE) {
2150
- resolvedValue._store.validated = 1;
2151
- }
2152
- }, function () {});
2153
- }
2154
-
2155
2074
  if (thenable.status === 'fulfilled') {
2156
2075
  return thenable.value;
2157
2076
  } // TODO: Once we accept Promises as children on the client, we can just return
@@ -2222,11 +2141,6 @@ validated) // DEV-only
2222
2141
  {
2223
2142
  result._debugInfo = _iterableChild._debugInfo;
2224
2143
  }
2225
- } else if (result.$$typeof === REACT_ELEMENT_TYPE) {
2226
- // If the server component renders to an element, then it was in a static position.
2227
- // That doesn't need further validation of keys. The Server Component itself would
2228
- // have had a key.
2229
- result._store.validated = 1;
2230
2144
  }
2231
2145
  } // Track this element's key on the Server Component on the keyPath context..
2232
2146
 
@@ -2253,26 +2167,12 @@ validated) // DEV-only
2253
2167
  }
2254
2168
 
2255
2169
  function renderFragment(request, task, children) {
2256
- {
2257
- for (var i = 0; i < children.length; i++) {
2258
- var child = children[i];
2259
-
2260
- if (child !== null && typeof child === 'object' && child.$$typeof === REACT_ELEMENT_TYPE) {
2261
- var element = child;
2262
-
2263
- if (element.key === null && !element._store.validated) {
2264
- element._store.validated = 2;
2265
- }
2266
- }
2267
- }
2268
- }
2269
-
2270
2170
  if (task.keyPath !== null) {
2271
2171
  // We have a Server Component that specifies a key but we're now splitting
2272
2172
  // the tree using a fragment.
2273
2173
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2274
2174
  children: children
2275
- }, null] ;
2175
+ }];
2276
2176
 
2277
2177
  if (!task.implicitSlot) {
2278
2178
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2329,7 +2229,7 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2329
2229
  // the tree using a fragment.
2330
2230
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2331
2231
  children: children
2332
- }, null] ;
2232
+ }];
2333
2233
 
2334
2234
  if (!task.implicitSlot) {
2335
2235
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2360,8 +2260,7 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2360
2260
  }
2361
2261
 
2362
2262
  function renderClientElement(task, type, key, props, owner, // DEV-only
2363
- stack, // DEV-only
2364
- validated) // DEV-only
2263
+ stack) // DEV-only
2365
2264
  {
2366
2265
  // We prepend the terminal client element that actually gets serialized with
2367
2266
  // the keys of any Server Components which are not serialized.
@@ -2412,8 +2311,7 @@ function outlineTask(request, task) {
2412
2311
  }
2413
2312
 
2414
2313
  function renderElement(request, task, type, key, ref, props, owner, // DEV only
2415
- stack, // DEV only
2416
- validated) // DEV only
2314
+ stack) // DEV only
2417
2315
  {
2418
2316
  if (ref !== null && ref !== undefined) {
2419
2317
  // When the ref moves to the regular props object this will implicitly
@@ -2476,13 +2374,6 @@ validated) // DEV only
2476
2374
  wrappedType = callLazyInitInDEV(type);
2477
2375
  }
2478
2376
 
2479
- if (request.status === ABORTING) {
2480
- // lazy initializers are user code and could abort during render
2481
- // we don't wan to return any value resolved from the lazy initializer
2482
- // if it aborts so we interrupt rendering here
2483
- throw AbortSigil;
2484
- }
2485
-
2486
2377
  return renderElement(request, task, wrappedType, key, ref, props, owner);
2487
2378
  }
2488
2379
 
@@ -2507,7 +2398,7 @@ function pingTask(request, task) {
2507
2398
 
2508
2399
  if (pingedTasks.length === 1) {
2509
2400
  request.flushScheduled = request.destination !== null;
2510
- scheduleMicrotask(function () {
2401
+ scheduleWork(function () {
2511
2402
  return performWork(request);
2512
2403
  });
2513
2404
  }
@@ -2805,32 +2696,21 @@ function renderModel(request, task, parent, key, value) {
2805
2696
  try {
2806
2697
  return renderModelDestructive(request, task, parent, key, value);
2807
2698
  } catch (thrownValue) {
2808
- // If the suspended/errored value was an element or lazy it can be reduced
2809
- // to a lazy reference, so that it doesn't error the parent.
2810
- var model = task.model;
2811
- var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2812
2699
  var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2813
2700
  // reasons, the rest of the Suspense implementation expects the thrown
2814
2701
  // value to be a thenable, because before `use` existed that was the
2815
2702
  // (unstable) API for suspending. This implementation detail can change
2816
2703
  // later, once we deprecate the old API in favor of `use`.
2817
- getSuspendedThenable() : thrownValue;
2704
+ getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
2705
+ // to a lazy reference, so that it doesn't error the parent.
2706
+
2707
+ var model = task.model;
2708
+ var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2818
2709
 
2819
2710
  if (typeof x === 'object' && x !== null) {
2820
2711
  // $FlowFixMe[method-unbinding]
2821
2712
  if (typeof x.then === 'function') {
2822
- if (request.status === ABORTING) {
2823
- task.status = ABORTED;
2824
- var errorId = request.fatalError;
2825
-
2826
- if (wasReactNode) {
2827
- return serializeLazyID(errorId);
2828
- }
2829
-
2830
- return serializeByValueID(errorId);
2831
- } // Something suspended, we'll need to create a new task and resolve it later.
2832
-
2833
-
2713
+ // Something suspended, we'll need to create a new task and resolve it later.
2834
2714
  var newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
2835
2715
  var ping = newTask.ping;
2836
2716
  x.then(ping, ping);
@@ -2846,17 +2726,6 @@ function renderModel(request, task, parent, key, value) {
2846
2726
 
2847
2727
  return serializeByValueID(newTask.id);
2848
2728
  }
2849
- }
2850
-
2851
- if (thrownValue === AbortSigil) {
2852
- task.status = ABORTED;
2853
- var _errorId = request.fatalError;
2854
-
2855
- if (wasReactNode) {
2856
- return serializeLazyID(_errorId);
2857
- }
2858
-
2859
- return serializeByValueID(_errorId);
2860
2729
  } // Restore the context. We assume that this will be restored by the inner
2861
2730
  // functions in case nothing throws so we don't use "finally" here.
2862
2731
 
@@ -2869,12 +2738,10 @@ function renderModel(request, task, parent, key, value) {
2869
2738
  // We'll replace this element with a lazy reference that throws on the client
2870
2739
  // once it gets rendered.
2871
2740
  request.pendingChunks++;
2872
-
2873
- var _errorId2 = request.nextChunkId++;
2874
-
2741
+ var errorId = request.nextChunkId++;
2875
2742
  var digest = logRecoverableError(request, x);
2876
- emitErrorChunk(request, _errorId2, digest, x);
2877
- return serializeLazyID(_errorId2);
2743
+ emitErrorChunk(request, errorId, digest, x);
2744
+ return serializeLazyID(errorId);
2878
2745
  } // Something errored but it was not in a React Node. There's no need to serialize
2879
2746
  // it by value because it'll just error the whole parent row anyway so we can
2880
2747
  // just stop any siblings and error the whole parent row.
@@ -2978,13 +2845,6 @@ function renderModelDestructive(request, task, parent, parentPropertyName, value
2978
2845
  resolvedModel = callLazyInitInDEV(lazy);
2979
2846
  }
2980
2847
 
2981
- if (request.status === ABORTING) {
2982
- // lazy initializers are user code and could abort during render
2983
- // we don't wan to return any value resolved from the lazy initializer
2984
- // if it aborts so we interrupt rendering here
2985
- throw AbortSigil;
2986
- }
2987
-
2988
2848
  {
2989
2849
  var _debugInfo = lazy._debugInfo;
2990
2850
 
@@ -3393,8 +3253,9 @@ function emitPostponeChunk(request, id, postponeInstance) {
3393
3253
 
3394
3254
  try {
3395
3255
  // eslint-disable-next-line react-internal/safe-string-coercion
3396
- reason = String(postponeInstance.message);
3397
- stack = getStack(postponeInstance);
3256
+ reason = String(postponeInstance.message); // eslint-disable-next-line react-internal/safe-string-coercion
3257
+
3258
+ stack = String(postponeInstance.stack);
3398
3259
  } catch (x) {}
3399
3260
 
3400
3261
  row = serializeRowHeader('P', id) + stringify({
@@ -3417,8 +3278,9 @@ function emitErrorChunk(request, id, digest, error) {
3417
3278
  try {
3418
3279
  if (error instanceof Error) {
3419
3280
  // eslint-disable-next-line react-internal/safe-string-coercion
3420
- message = String(error.message);
3421
- stack = getStack(error);
3281
+ message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
3282
+
3283
+ stack = String(error.stack);
3422
3284
  } else if (typeof error === 'object' && error !== null) {
3423
3285
  message = describeObjectForErrorMessage(error);
3424
3286
  } else {
@@ -3895,7 +3757,6 @@ function retryTask(request, task) {
3895
3757
  }
3896
3758
 
3897
3759
  var prevDebugID = debugID;
3898
- task.status = RENDERING;
3899
3760
 
3900
3761
  try {
3901
3762
  // Track the root so we know that we have to emit this object even though it
@@ -3952,35 +3813,14 @@ function retryTask(request, task) {
3952
3813
  if (typeof x === 'object' && x !== null) {
3953
3814
  // $FlowFixMe[method-unbinding]
3954
3815
  if (typeof x.then === 'function') {
3955
- if (request.status === ABORTING) {
3956
- request.abortableTasks.delete(task);
3957
- task.status = ABORTED;
3958
- var errorId = request.fatalError;
3959
- var model = stringify(serializeByValueID(errorId));
3960
- emitModelChunk(request, task.id, model);
3961
- return;
3962
- } // Something suspended again, let's pick it back up later.
3963
-
3964
-
3965
- task.status = PENDING$1;
3966
- task.thenableState = getThenableStateAfterSuspending();
3816
+ // Something suspended again, let's pick it back up later.
3967
3817
  var ping = task.ping;
3968
3818
  x.then(ping, ping);
3819
+ task.thenableState = getThenableStateAfterSuspending();
3969
3820
  return;
3970
3821
  }
3971
3822
  }
3972
3823
 
3973
- if (x === AbortSigil) {
3974
- request.abortableTasks.delete(task);
3975
- task.status = ABORTED;
3976
- var _errorId3 = request.fatalError;
3977
-
3978
- var _model = stringify(serializeByValueID(_errorId3));
3979
-
3980
- emitModelChunk(request, task.id, _model);
3981
- return;
3982
- }
3983
-
3984
3824
  request.abortableTasks.delete(task);
3985
3825
  task.status = ERRORED$1;
3986
3826
  var digest = logRecoverableError(request, x);
@@ -4042,11 +3882,6 @@ function performWork(request) {
4042
3882
  }
4043
3883
 
4044
3884
  function abortTask(task, request, errorId) {
4045
- if (task.status === RENDERING) {
4046
- // This task will be aborted by the render
4047
- return;
4048
- }
4049
-
4050
3885
  task.status = ABORTED; // Instead of emitting an error per task.id, we emit a model that only
4051
3886
  // has a single value referencing the error.
4052
3887
 
@@ -4141,7 +3976,6 @@ function flushCompletedChunks(request, destination) {
4141
3976
 
4142
3977
  if (request.pendingChunks === 0) {
4143
3978
 
4144
- request.status = CLOSED;
4145
3979
  close$1(destination);
4146
3980
  request.destination = null;
4147
3981
  }
@@ -4162,14 +3996,10 @@ function enqueueFlush(request) {
4162
3996
  request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
4163
3997
  // happen when we start flowing again
4164
3998
  request.destination !== null) {
3999
+ var destination = request.destination;
4165
4000
  request.flushScheduled = true;
4166
4001
  scheduleWork(function () {
4167
- request.flushScheduled = false;
4168
- var destination = request.destination;
4169
-
4170
- if (destination) {
4171
- flushCompletedChunks(request, destination);
4172
- }
4002
+ return flushCompletedChunks(request, destination);
4173
4003
  });
4174
4004
  }
4175
4005
  }
@@ -4205,17 +4035,15 @@ function stopFlowing(request) {
4205
4035
 
4206
4036
  function abort(request, reason) {
4207
4037
  try {
4208
- request.status = ABORTING;
4209
4038
  var abortableTasks = request.abortableTasks; // We have tasks to abort. We'll emit one error row and then emit a reference
4210
4039
  // to that row from every row that's still remaining.
4211
4040
 
4212
4041
  if (abortableTasks.size > 0) {
4213
4042
  request.pendingChunks++;
4214
4043
  var errorId = request.nextChunkId++;
4215
- request.fatalError = errorId;
4216
4044
 
4217
4045
  var postponeInstance; if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
4218
- 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;
4046
+ var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
4219
4047
  var digest = logRecoverableError(request, error);
4220
4048
  emitErrorChunk(request, errorId, digest, error);
4221
4049
  }
@@ -4232,7 +4060,7 @@ function abort(request, reason) {
4232
4060
  var _error;
4233
4061
 
4234
4062
  if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
4235
- _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;
4063
+ _error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
4236
4064
  }
4237
4065
 
4238
4066
  abortListeners.forEach(function (callback) {