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.
@@ -39,9 +39,6 @@ if (!ReactSharedInternalsServer) {
39
39
  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.');
40
40
  }
41
41
 
42
- // -----------------------------------------------------------------------------
43
- var enablePostpone = false;
44
-
45
42
  function error(format) {
46
43
  {
47
44
  {
@@ -49,61 +46,38 @@ function error(format) {
49
46
  args[_key2 - 1] = arguments[_key2];
50
47
  }
51
48
 
52
- printWarning('error', format, args, new Error('react-stack-top-frame'));
49
+ printWarning('error', format, args);
53
50
  }
54
51
  }
55
- } // eslint-disable-next-line react-internal/no-production-logging
52
+ }
56
53
 
57
- function printWarning(level, format, args, currentStack) {
54
+ function printWarning(level, format, args) {
58
55
  // When changing this logic, you might want to also
59
56
  // update consoleWithStackDev.www.js as well.
60
57
  {
61
- var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
58
+ var stack = ReactSharedInternalsServer.getStackAddendum();
62
59
 
63
- if (ReactSharedInternalsServer.getCurrentStack) {
64
- // We only add the current stack to the console when createTask is not supported.
65
- // Since createTask requires DevTools to be open to work, this means that stacks
66
- // can be lost while DevTools isn't open but we can't detect this.
67
- var stack = ReactSharedInternalsServer.getCurrentStack(currentStack);
60
+ if (stack !== '') {
61
+ format += '%s';
62
+ args = args.concat([stack]);
63
+ } // eslint-disable-next-line react-internal/safe-string-coercion
68
64
 
69
- if (stack !== '') {
70
- format += '%s';
71
- args = args.concat([stack]);
72
- }
73
- }
74
65
 
75
- if (isErrorLogger) {
76
- // Don't prefix our default logging formatting in ReactFiberErrorLoggger.
77
- // Don't toString the arguments.
78
- args.unshift(format);
79
- } else {
80
- // TODO: Remove this prefix and stop toStringing in the wrapper and
81
- // instead do it at each callsite as needed.
82
- // Careful: RN currently depends on this prefix
83
- // eslint-disable-next-line react-internal/safe-string-coercion
84
- args = args.map(function (item) {
85
- return String(item);
86
- });
87
- args.unshift('Warning: ' + format);
88
- } // We intentionally don't use spread (or .apply) directly because it
66
+ var argsWithFormat = args.map(function (item) {
67
+ return String(item);
68
+ }); // Careful: RN currently depends on this prefix
69
+
70
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
89
71
  // breaks IE9: https://github.com/facebook/react/issues/13610
90
72
  // eslint-disable-next-line react-internal/no-production-logging
91
73
 
92
-
93
- Function.prototype.apply.call(console[level], console, args);
74
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
94
75
  }
95
76
  }
96
77
 
97
- function handleErrorInNextTick(error) {
98
- setTimeout(function () {
99
- throw error;
100
- });
101
- }
78
+ // -----------------------------------------------------------------------------
79
+ var enablePostpone = false;
102
80
 
103
- var LocalPromise = Promise;
104
- var scheduleMicrotask = typeof queueMicrotask === 'function' ? queueMicrotask : function (callback) {
105
- LocalPromise.resolve(null).then(callback).catch(handleErrorInNextTick);
106
- };
107
81
  function scheduleWork(callback) {
108
82
  setTimeout(callback, 0);
109
83
  }
@@ -1549,37 +1523,6 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1549
1523
 
1550
1524
  var ReactSharedInternals = ReactSharedInternalsServer;
1551
1525
 
1552
- function prepareStackTrace(error, structuredStackTrace) {
1553
- var name = error.name || 'Error';
1554
- var message = error.message || '';
1555
- var stack = name + ': ' + message;
1556
-
1557
- for (var i = 0; i < structuredStackTrace.length; i++) {
1558
- stack += '\n at ' + structuredStackTrace[i].toString();
1559
- }
1560
-
1561
- return stack;
1562
- }
1563
-
1564
- function getStack(error) {
1565
- // We override Error.prepareStackTrace with our own version that normalizes
1566
- // the stack to V8 formatting even if the server uses other formatting.
1567
- // It also ensures that source maps are NOT applied to this since that can
1568
- // be slow we're better off doing that lazily from the client instead of
1569
- // eagerly on the server. If the stack has already been read, then we might
1570
- // not get a normalized stack and it might still have been source mapped.
1571
- // So the client still needs to be resilient to this.
1572
- var previousPrepare = Error.prepareStackTrace;
1573
- Error.prepareStackTrace = prepareStackTrace;
1574
-
1575
- try {
1576
- // eslint-disable-next-line react-internal/safe-string-coercion
1577
- return String(error.stack);
1578
- } finally {
1579
- Error.prepareStackTrace = previousPrepare;
1580
- }
1581
- }
1582
-
1583
1526
  var ObjectPrototype = Object.prototype;
1584
1527
  var stringify = JSON.stringify; // Serializable values
1585
1528
  // Thenable<ReactClientValue>
@@ -1589,8 +1532,6 @@ var PENDING$1 = 0;
1589
1532
  var COMPLETED = 1;
1590
1533
  var ABORTED = 3;
1591
1534
  var ERRORED$1 = 4;
1592
- var RENDERING = 5;
1593
- var AbortSigil = {};
1594
1535
 
1595
1536
  function defaultErrorHandler(error) {
1596
1537
  console['error'](error); // Don't transform to our wrapper
@@ -1600,9 +1541,8 @@ function defaultPostponeHandler(reason) {// Noop
1600
1541
  }
1601
1542
 
1602
1543
  var OPEN = 0;
1603
- var ABORTING = 1;
1604
- var CLOSING = 2;
1605
- var CLOSED = 3;
1544
+ var CLOSING = 1;
1545
+ var CLOSED = 2;
1606
1546
  function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName, temporaryReferences) {
1607
1547
  if (ReactSharedInternals.A !== null && ReactSharedInternals.A !== DefaultAsyncDispatcher) {
1608
1548
  throw new Error('Currently React only supports one RSC renderer at a time.');
@@ -1645,7 +1585,6 @@ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpo
1645
1585
 
1646
1586
  {
1647
1587
  request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1648
- request.didWarnForKey = null;
1649
1588
  }
1650
1589
 
1651
1590
  var rootTask = createTask(request, model, null, false, abortSet);
@@ -1700,16 +1639,6 @@ function serializeThenable(request, task, thenable) {
1700
1639
 
1701
1640
  default:
1702
1641
  {
1703
- if (request.status === ABORTING) {
1704
- // We can no longer accept any resolved values
1705
- newTask.status = ABORTED;
1706
- var errorId = request.fatalError;
1707
- var model = stringify(serializeByValueID(errorId));
1708
- emitModelChunk(request, newTask.id, model);
1709
- request.abortableTasks.delete(newTask);
1710
- return newTask.id;
1711
- }
1712
-
1713
1642
  if (typeof thenable.status === 'string') {
1714
1643
  // Only instrument the thenable if the status if not defined. If
1715
1644
  // it's defined, but an unknown value, assume it's been instrumented by
@@ -2043,8 +1972,7 @@ function callLazyInitInDEV(lazy) {
2043
1972
  }
2044
1973
 
2045
1974
  function renderFunctionComponent(request, task, key, Component, props, owner, // DEV-only
2046
- stack, // DEV-only
2047
- validated) // DEV-only
1975
+ stack) // DEV-only
2048
1976
  {
2049
1977
  // Reset the task's thenable state before continuing, so that if a later
2050
1978
  // component suspends we can reuse the same task object. If the same
@@ -2086,30 +2014,12 @@ validated) // DEV-only
2086
2014
  result = callComponentInDEV(Component, props, componentDebugInfo);
2087
2015
  }
2088
2016
 
2089
- if (request.status === ABORTING) {
2090
- // If we aborted during rendering we should interrupt the render but
2091
- // we don't need to provide an error because the renderer will encode
2092
- // the abort error as the reason.
2093
- throw AbortSigil;
2094
- }
2095
-
2096
- if (typeof result === 'object' && result !== null && !isClientReference(result)) {
2017
+ if (typeof result === 'object' && result !== null) {
2097
2018
  if (typeof result.then === 'function') {
2098
2019
  // When the return value is in children position we can resolve it immediately,
2099
2020
  // to its value without a wrapper if it's synchronously available.
2100
2021
  var thenable = result;
2101
2022
 
2102
- {
2103
- // If the thenable resolves to an element, then it was in a static position,
2104
- // the return value of a Server Component. That doesn't need further validation
2105
- // of keys. The Server Component itself would have had a key.
2106
- thenable.then(function (resolvedValue) {
2107
- if (typeof resolvedValue === 'object' && resolvedValue !== null && resolvedValue.$$typeof === REACT_ELEMENT_TYPE) {
2108
- resolvedValue._store.validated = 1;
2109
- }
2110
- }, function () {});
2111
- }
2112
-
2113
2023
  if (thenable.status === 'fulfilled') {
2114
2024
  return thenable.value;
2115
2025
  } // TODO: Once we accept Promises as children on the client, we can just return
@@ -2180,11 +2090,6 @@ validated) // DEV-only
2180
2090
  {
2181
2091
  result._debugInfo = _iterableChild._debugInfo;
2182
2092
  }
2183
- } else if (result.$$typeof === REACT_ELEMENT_TYPE) {
2184
- // If the server component renders to an element, then it was in a static position.
2185
- // That doesn't need further validation of keys. The Server Component itself would
2186
- // have had a key.
2187
- result._store.validated = 1;
2188
2093
  }
2189
2094
  } // Track this element's key on the Server Component on the keyPath context..
2190
2095
 
@@ -2211,26 +2116,12 @@ validated) // DEV-only
2211
2116
  }
2212
2117
 
2213
2118
  function renderFragment(request, task, children) {
2214
- {
2215
- for (var i = 0; i < children.length; i++) {
2216
- var child = children[i];
2217
-
2218
- if (child !== null && typeof child === 'object' && child.$$typeof === REACT_ELEMENT_TYPE) {
2219
- var element = child;
2220
-
2221
- if (element.key === null && !element._store.validated) {
2222
- element._store.validated = 2;
2223
- }
2224
- }
2225
- }
2226
- }
2227
-
2228
2119
  if (task.keyPath !== null) {
2229
2120
  // We have a Server Component that specifies a key but we're now splitting
2230
2121
  // the tree using a fragment.
2231
2122
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2232
2123
  children: children
2233
- }, null] ;
2124
+ }];
2234
2125
 
2235
2126
  if (!task.implicitSlot) {
2236
2127
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2287,7 +2178,7 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2287
2178
  // the tree using a fragment.
2288
2179
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2289
2180
  children: children
2290
- }, null] ;
2181
+ }];
2291
2182
 
2292
2183
  if (!task.implicitSlot) {
2293
2184
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2318,8 +2209,7 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2318
2209
  }
2319
2210
 
2320
2211
  function renderClientElement(task, type, key, props, owner, // DEV-only
2321
- stack, // DEV-only
2322
- validated) // DEV-only
2212
+ stack) // DEV-only
2323
2213
  {
2324
2214
  // We prepend the terminal client element that actually gets serialized with
2325
2215
  // the keys of any Server Components which are not serialized.
@@ -2370,8 +2260,7 @@ function outlineTask(request, task) {
2370
2260
  }
2371
2261
 
2372
2262
  function renderElement(request, task, type, key, ref, props, owner, // DEV only
2373
- stack, // DEV only
2374
- validated) // DEV only
2263
+ stack) // DEV only
2375
2264
  {
2376
2265
  if (ref !== null && ref !== undefined) {
2377
2266
  // When the ref moves to the regular props object this will implicitly
@@ -2434,13 +2323,6 @@ validated) // DEV only
2434
2323
  wrappedType = callLazyInitInDEV(type);
2435
2324
  }
2436
2325
 
2437
- if (request.status === ABORTING) {
2438
- // lazy initializers are user code and could abort during render
2439
- // we don't wan to return any value resolved from the lazy initializer
2440
- // if it aborts so we interrupt rendering here
2441
- throw AbortSigil;
2442
- }
2443
-
2444
2326
  return renderElement(request, task, wrappedType, key, ref, props, owner);
2445
2327
  }
2446
2328
 
@@ -2465,7 +2347,7 @@ function pingTask(request, task) {
2465
2347
 
2466
2348
  if (pingedTasks.length === 1) {
2467
2349
  request.flushScheduled = request.destination !== null;
2468
- scheduleMicrotask(function () {
2350
+ scheduleWork(function () {
2469
2351
  return performWork(request);
2470
2352
  });
2471
2353
  }
@@ -2763,32 +2645,21 @@ function renderModel(request, task, parent, key, value) {
2763
2645
  try {
2764
2646
  return renderModelDestructive(request, task, parent, key, value);
2765
2647
  } catch (thrownValue) {
2766
- // If the suspended/errored value was an element or lazy it can be reduced
2767
- // to a lazy reference, so that it doesn't error the parent.
2768
- var model = task.model;
2769
- var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2770
2648
  var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2771
2649
  // reasons, the rest of the Suspense implementation expects the thrown
2772
2650
  // value to be a thenable, because before `use` existed that was the
2773
2651
  // (unstable) API for suspending. This implementation detail can change
2774
2652
  // later, once we deprecate the old API in favor of `use`.
2775
- getSuspendedThenable() : thrownValue;
2653
+ getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
2654
+ // to a lazy reference, so that it doesn't error the parent.
2655
+
2656
+ var model = task.model;
2657
+ var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2776
2658
 
2777
2659
  if (typeof x === 'object' && x !== null) {
2778
2660
  // $FlowFixMe[method-unbinding]
2779
2661
  if (typeof x.then === 'function') {
2780
- if (request.status === ABORTING) {
2781
- task.status = ABORTED;
2782
- var errorId = request.fatalError;
2783
-
2784
- if (wasReactNode) {
2785
- return serializeLazyID(errorId);
2786
- }
2787
-
2788
- return serializeByValueID(errorId);
2789
- } // Something suspended, we'll need to create a new task and resolve it later.
2790
-
2791
-
2662
+ // Something suspended, we'll need to create a new task and resolve it later.
2792
2663
  var newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
2793
2664
  var ping = newTask.ping;
2794
2665
  x.then(ping, ping);
@@ -2804,17 +2675,6 @@ function renderModel(request, task, parent, key, value) {
2804
2675
 
2805
2676
  return serializeByValueID(newTask.id);
2806
2677
  }
2807
- }
2808
-
2809
- if (thrownValue === AbortSigil) {
2810
- task.status = ABORTED;
2811
- var _errorId = request.fatalError;
2812
-
2813
- if (wasReactNode) {
2814
- return serializeLazyID(_errorId);
2815
- }
2816
-
2817
- return serializeByValueID(_errorId);
2818
2678
  } // Restore the context. We assume that this will be restored by the inner
2819
2679
  // functions in case nothing throws so we don't use "finally" here.
2820
2680
 
@@ -2827,12 +2687,10 @@ function renderModel(request, task, parent, key, value) {
2827
2687
  // We'll replace this element with a lazy reference that throws on the client
2828
2688
  // once it gets rendered.
2829
2689
  request.pendingChunks++;
2830
-
2831
- var _errorId2 = request.nextChunkId++;
2832
-
2690
+ var errorId = request.nextChunkId++;
2833
2691
  var digest = logRecoverableError(request, x);
2834
- emitErrorChunk(request, _errorId2, digest, x);
2835
- return serializeLazyID(_errorId2);
2692
+ emitErrorChunk(request, errorId, digest, x);
2693
+ return serializeLazyID(errorId);
2836
2694
  } // Something errored but it was not in a React Node. There's no need to serialize
2837
2695
  // it by value because it'll just error the whole parent row anyway so we can
2838
2696
  // just stop any siblings and error the whole parent row.
@@ -2936,13 +2794,6 @@ function renderModelDestructive(request, task, parent, parentPropertyName, value
2936
2794
  resolvedModel = callLazyInitInDEV(lazy);
2937
2795
  }
2938
2796
 
2939
- if (request.status === ABORTING) {
2940
- // lazy initializers are user code and could abort during render
2941
- // we don't wan to return any value resolved from the lazy initializer
2942
- // if it aborts so we interrupt rendering here
2943
- throw AbortSigil;
2944
- }
2945
-
2946
2797
  {
2947
2798
  var _debugInfo = lazy._debugInfo;
2948
2799
 
@@ -3355,8 +3206,9 @@ function emitPostponeChunk(request, id, postponeInstance) {
3355
3206
 
3356
3207
  try {
3357
3208
  // eslint-disable-next-line react-internal/safe-string-coercion
3358
- reason = String(postponeInstance.message);
3359
- stack = getStack(postponeInstance);
3209
+ reason = String(postponeInstance.message); // eslint-disable-next-line react-internal/safe-string-coercion
3210
+
3211
+ stack = String(postponeInstance.stack);
3360
3212
  } catch (x) {}
3361
3213
 
3362
3214
  row = serializeRowHeader('P', id) + stringify({
@@ -3379,8 +3231,9 @@ function emitErrorChunk(request, id, digest, error) {
3379
3231
  try {
3380
3232
  if (error instanceof Error) {
3381
3233
  // eslint-disable-next-line react-internal/safe-string-coercion
3382
- message = String(error.message);
3383
- stack = getStack(error);
3234
+ message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
3235
+
3236
+ stack = String(error.stack);
3384
3237
  } else if (typeof error === 'object' && error !== null) {
3385
3238
  message = describeObjectForErrorMessage(error);
3386
3239
  } else {
@@ -3857,7 +3710,6 @@ function retryTask(request, task) {
3857
3710
  }
3858
3711
 
3859
3712
  var prevDebugID = debugID;
3860
- task.status = RENDERING;
3861
3713
 
3862
3714
  try {
3863
3715
  // Track the root so we know that we have to emit this object even though it
@@ -3914,35 +3766,14 @@ function retryTask(request, task) {
3914
3766
  if (typeof x === 'object' && x !== null) {
3915
3767
  // $FlowFixMe[method-unbinding]
3916
3768
  if (typeof x.then === 'function') {
3917
- if (request.status === ABORTING) {
3918
- request.abortableTasks.delete(task);
3919
- task.status = ABORTED;
3920
- var errorId = request.fatalError;
3921
- var model = stringify(serializeByValueID(errorId));
3922
- emitModelChunk(request, task.id, model);
3923
- return;
3924
- } // Something suspended again, let's pick it back up later.
3925
-
3926
-
3927
- task.status = PENDING$1;
3928
- task.thenableState = getThenableStateAfterSuspending();
3769
+ // Something suspended again, let's pick it back up later.
3929
3770
  var ping = task.ping;
3930
3771
  x.then(ping, ping);
3772
+ task.thenableState = getThenableStateAfterSuspending();
3931
3773
  return;
3932
3774
  }
3933
3775
  }
3934
3776
 
3935
- if (x === AbortSigil) {
3936
- request.abortableTasks.delete(task);
3937
- task.status = ABORTED;
3938
- var _errorId3 = request.fatalError;
3939
-
3940
- var _model = stringify(serializeByValueID(_errorId3));
3941
-
3942
- emitModelChunk(request, task.id, _model);
3943
- return;
3944
- }
3945
-
3946
3777
  request.abortableTasks.delete(task);
3947
3778
  task.status = ERRORED$1;
3948
3779
  var digest = logRecoverableError(request, x);
@@ -4004,11 +3835,6 @@ function performWork(request) {
4004
3835
  }
4005
3836
 
4006
3837
  function abortTask(task, request, errorId) {
4007
- if (task.status === RENDERING) {
4008
- // This task will be aborted by the render
4009
- return;
4010
- }
4011
-
4012
3838
  task.status = ABORTED; // Instead of emitting an error per task.id, we emit a model that only
4013
3839
  // has a single value referencing the error.
4014
3840
 
@@ -4101,7 +3927,6 @@ function flushCompletedChunks(request, destination) {
4101
3927
 
4102
3928
  if (request.pendingChunks === 0) {
4103
3929
 
4104
- request.status = CLOSED;
4105
3930
  close$1(destination);
4106
3931
  request.destination = null;
4107
3932
  }
@@ -4126,14 +3951,10 @@ function enqueueFlush(request) {
4126
3951
  request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
4127
3952
  // happen when we start flowing again
4128
3953
  request.destination !== null) {
3954
+ var destination = request.destination;
4129
3955
  request.flushScheduled = true;
4130
3956
  scheduleWork(function () {
4131
- request.flushScheduled = false;
4132
- var destination = request.destination;
4133
-
4134
- if (destination) {
4135
- flushCompletedChunks(request, destination);
4136
- }
3957
+ return flushCompletedChunks(request, destination);
4137
3958
  });
4138
3959
  }
4139
3960
  }
@@ -4169,17 +3990,15 @@ function stopFlowing(request) {
4169
3990
 
4170
3991
  function abort(request, reason) {
4171
3992
  try {
4172
- request.status = ABORTING;
4173
3993
  var abortableTasks = request.abortableTasks; // We have tasks to abort. We'll emit one error row and then emit a reference
4174
3994
  // to that row from every row that's still remaining.
4175
3995
 
4176
3996
  if (abortableTasks.size > 0) {
4177
3997
  request.pendingChunks++;
4178
3998
  var errorId = request.nextChunkId++;
4179
- request.fatalError = errorId;
4180
3999
 
4181
4000
  var postponeInstance; if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
4182
- 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;
4001
+ var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
4183
4002
  var digest = logRecoverableError(request, error);
4184
4003
  emitErrorChunk(request, errorId, digest, error);
4185
4004
  }
@@ -4196,7 +4015,7 @@ function abort(request, reason) {
4196
4015
  var _error;
4197
4016
 
4198
4017
  if (enablePostpone && typeof reason === 'object' && reason !== null && reason.$$typeof === REACT_POSTPONE_TYPE) ; else {
4199
- _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;
4018
+ _error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
4200
4019
  }
4201
4020
 
4202
4021
  abortListeners.forEach(function (callback) {