react-server-dom-webpack 19.0.0-rc-34d0c5e357-20240607 → 19.0.0-rc-6230622a1a-20240610

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,6 +39,9 @@ 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
+
42
45
  function error(format) {
43
46
  {
44
47
  {
@@ -46,38 +49,51 @@ function error(format) {
46
49
  args[_key2 - 1] = arguments[_key2];
47
50
  }
48
51
 
49
- printWarning('error', format, args);
52
+ printWarning('error', format, args, new Error('react-stack-top-frame'));
50
53
  }
51
54
  }
52
- }
55
+ } // eslint-disable-next-line react-internal/no-production-logging
53
56
 
54
- function printWarning(level, format, args) {
57
+ function printWarning(level, format, args, currentStack) {
55
58
  // When changing this logic, you might want to also
56
59
  // update consoleWithStackDev.www.js as well.
57
60
  {
58
- var stack = ReactSharedInternalsServer.getStackAddendum();
59
-
60
- if (stack !== '') {
61
- format += '%s';
62
- args = args.concat([stack]);
63
- } // eslint-disable-next-line react-internal/safe-string-coercion
61
+ var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
64
62
 
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);
65
68
 
66
- var argsWithFormat = args.map(function (item) {
67
- return String(item);
68
- }); // Careful: RN currently depends on this prefix
69
+ if (stack !== '') {
70
+ format += '%s';
71
+ args = args.concat([stack]);
72
+ }
73
+ }
69
74
 
70
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
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
71
89
  // breaks IE9: https://github.com/facebook/react/issues/13610
72
90
  // eslint-disable-next-line react-internal/no-production-logging
73
91
 
74
- Function.prototype.apply.call(console[level], console, argsWithFormat);
92
+
93
+ Function.prototype.apply.call(console[level], console, args);
75
94
  }
76
95
  }
77
96
 
78
- // -----------------------------------------------------------------------------
79
- var enablePostpone = false;
80
-
81
97
  function scheduleWork(callback) {
82
98
  callback();
83
99
  }
@@ -1510,6 +1526,37 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1510
1526
 
1511
1527
  var ReactSharedInternals = ReactSharedInternalsServer;
1512
1528
 
1529
+ function prepareStackTrace(error, structuredStackTrace) {
1530
+ var name = error.name || 'Error';
1531
+ var message = error.message || '';
1532
+ var stack = name + ': ' + message;
1533
+
1534
+ for (var i = 0; i < structuredStackTrace.length; i++) {
1535
+ stack += '\n at ' + structuredStackTrace[i].toString();
1536
+ }
1537
+
1538
+ return stack;
1539
+ }
1540
+
1541
+ function getStack(error) {
1542
+ // We override Error.prepareStackTrace with our own version that normalizes
1543
+ // the stack to V8 formatting even if the server uses other formatting.
1544
+ // It also ensures that source maps are NOT applied to this since that can
1545
+ // be slow we're better off doing that lazily from the client instead of
1546
+ // eagerly on the server. If the stack has already been read, then we might
1547
+ // not get a normalized stack and it might still have been source mapped.
1548
+ // So the client still needs to be resilient to this.
1549
+ var previousPrepare = Error.prepareStackTrace;
1550
+ Error.prepareStackTrace = prepareStackTrace;
1551
+
1552
+ try {
1553
+ // eslint-disable-next-line react-internal/safe-string-coercion
1554
+ return String(error.stack);
1555
+ } finally {
1556
+ Error.prepareStackTrace = previousPrepare;
1557
+ }
1558
+ }
1559
+
1513
1560
  var ObjectPrototype = Object.prototype;
1514
1561
  var stringify = JSON.stringify; // Serializable values
1515
1562
  // Thenable<ReactClientValue>
@@ -1572,6 +1619,7 @@ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpo
1572
1619
 
1573
1620
  {
1574
1621
  request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1622
+ request.didWarnForKey = null;
1575
1623
  }
1576
1624
 
1577
1625
  var rootTask = createTask(request, model, null, false, abortSet);
@@ -1951,7 +1999,8 @@ function callLazyInitInDEV(lazy) {
1951
1999
  }
1952
2000
 
1953
2001
  function renderFunctionComponent(request, task, key, Component, props, owner, // DEV-only
1954
- stack) // DEV-only
2002
+ stack, // DEV-only
2003
+ validated) // DEV-only
1955
2004
  {
1956
2005
  // Reset the task's thenable state before continuing, so that if a later
1957
2006
  // component suspends we can reuse the same task object. If the same
@@ -1993,12 +2042,23 @@ stack) // DEV-only
1993
2042
  result = callComponentInDEV(Component, props, componentDebugInfo);
1994
2043
  }
1995
2044
 
1996
- if (typeof result === 'object' && result !== null) {
2045
+ if (typeof result === 'object' && result !== null && !isClientReference(result)) {
1997
2046
  if (typeof result.then === 'function') {
1998
2047
  // When the return value is in children position we can resolve it immediately,
1999
2048
  // to its value without a wrapper if it's synchronously available.
2000
2049
  var thenable = result;
2001
2050
 
2051
+ {
2052
+ // If the thenable resolves to an element, then it was in a static position,
2053
+ // the return value of a Server Component. That doesn't need further validation
2054
+ // of keys. The Server Component itself would have had a key.
2055
+ thenable.then(function (resolvedValue) {
2056
+ if (typeof resolvedValue === 'object' && resolvedValue !== null && resolvedValue.$$typeof === REACT_ELEMENT_TYPE) {
2057
+ resolvedValue._store.validated = 1;
2058
+ }
2059
+ }, function () {});
2060
+ }
2061
+
2002
2062
  if (thenable.status === 'fulfilled') {
2003
2063
  return thenable.value;
2004
2064
  } // TODO: Once we accept Promises as children on the client, we can just return
@@ -2069,6 +2129,11 @@ stack) // DEV-only
2069
2129
  {
2070
2130
  result._debugInfo = _iterableChild._debugInfo;
2071
2131
  }
2132
+ } else if (result.$$typeof === REACT_ELEMENT_TYPE) {
2133
+ // If the server component renders to an element, then it was in a static position.
2134
+ // That doesn't need further validation of keys. The Server Component itself would
2135
+ // have had a key.
2136
+ result._store.validated = 1;
2072
2137
  }
2073
2138
  } // Track this element's key on the Server Component on the keyPath context..
2074
2139
 
@@ -2095,12 +2160,26 @@ stack) // DEV-only
2095
2160
  }
2096
2161
 
2097
2162
  function renderFragment(request, task, children) {
2163
+ {
2164
+ for (var i = 0; i < children.length; i++) {
2165
+ var child = children[i];
2166
+
2167
+ if (child !== null && typeof child === 'object' && child.$$typeof === REACT_ELEMENT_TYPE) {
2168
+ var element = child;
2169
+
2170
+ if (element.key === null && !element._store.validated) {
2171
+ element._store.validated = 2;
2172
+ }
2173
+ }
2174
+ }
2175
+ }
2176
+
2098
2177
  if (task.keyPath !== null) {
2099
2178
  // We have a Server Component that specifies a key but we're now splitting
2100
2179
  // the tree using a fragment.
2101
2180
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2102
2181
  children: children
2103
- }];
2182
+ }, null] ;
2104
2183
 
2105
2184
  if (!task.implicitSlot) {
2106
2185
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2157,7 +2236,7 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2157
2236
  // the tree using a fragment.
2158
2237
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2159
2238
  children: children
2160
- }];
2239
+ }, null] ;
2161
2240
 
2162
2241
  if (!task.implicitSlot) {
2163
2242
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2188,7 +2267,8 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2188
2267
  }
2189
2268
 
2190
2269
  function renderClientElement(task, type, key, props, owner, // DEV-only
2191
- stack) // DEV-only
2270
+ stack, // DEV-only
2271
+ validated) // DEV-only
2192
2272
  {
2193
2273
  // We prepend the terminal client element that actually gets serialized with
2194
2274
  // the keys of any Server Components which are not serialized.
@@ -2239,7 +2319,8 @@ function outlineTask(request, task) {
2239
2319
  }
2240
2320
 
2241
2321
  function renderElement(request, task, type, key, ref, props, owner, // DEV only
2242
- stack) // DEV only
2322
+ stack, // DEV only
2323
+ validated) // DEV only
2243
2324
  {
2244
2325
  if (ref !== null && ref !== undefined) {
2245
2326
  // When the ref moves to the regular props object this will implicitly
@@ -3179,9 +3260,8 @@ function emitPostponeChunk(request, id, postponeInstance) {
3179
3260
 
3180
3261
  try {
3181
3262
  // eslint-disable-next-line react-internal/safe-string-coercion
3182
- reason = String(postponeInstance.message); // eslint-disable-next-line react-internal/safe-string-coercion
3183
-
3184
- stack = String(postponeInstance.stack);
3263
+ reason = String(postponeInstance.message);
3264
+ stack = getStack(postponeInstance);
3185
3265
  } catch (x) {}
3186
3266
 
3187
3267
  row = serializeRowHeader('P', id) + stringify({
@@ -3204,9 +3284,8 @@ function emitErrorChunk(request, id, digest, error) {
3204
3284
  try {
3205
3285
  if (error instanceof Error) {
3206
3286
  // eslint-disable-next-line react-internal/safe-string-coercion
3207
- message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
3208
-
3209
- stack = String(error.stack);
3287
+ message = String(error.message);
3288
+ stack = getStack(error);
3210
3289
  } else if (typeof error === 'object' && error !== null) {
3211
3290
  message = describeObjectForErrorMessage(error);
3212
3291
  } else {
@@ -932,7 +932,11 @@ function renderFunctionComponent(request, task, key, Component, props) {
932
932
  thenableIndexCounter = 0;
933
933
  thenableState = prevThenableState;
934
934
  Component = Component(props, void 0);
935
- if ("object" === typeof Component && null !== Component) {
935
+ if (
936
+ "object" === typeof Component &&
937
+ null !== Component &&
938
+ Component.$$typeof !== CLIENT_REFERENCE_TAG$1
939
+ ) {
936
940
  if ("function" === typeof Component.then) {
937
941
  props = Component;
938
942
  if ("fulfilled" === props.status) return props.value;
@@ -39,6 +39,9 @@ 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
+
42
45
  function error(format) {
43
46
  {
44
47
  {
@@ -46,38 +49,51 @@ function error(format) {
46
49
  args[_key2 - 1] = arguments[_key2];
47
50
  }
48
51
 
49
- printWarning('error', format, args);
52
+ printWarning('error', format, args, new Error('react-stack-top-frame'));
50
53
  }
51
54
  }
52
- }
55
+ } // eslint-disable-next-line react-internal/no-production-logging
53
56
 
54
- function printWarning(level, format, args) {
57
+ function printWarning(level, format, args, currentStack) {
55
58
  // When changing this logic, you might want to also
56
59
  // update consoleWithStackDev.www.js as well.
57
60
  {
58
- var stack = ReactSharedInternalsServer.getStackAddendum();
59
-
60
- if (stack !== '') {
61
- format += '%s';
62
- args = args.concat([stack]);
63
- } // eslint-disable-next-line react-internal/safe-string-coercion
61
+ var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
64
62
 
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);
65
68
 
66
- var argsWithFormat = args.map(function (item) {
67
- return String(item);
68
- }); // Careful: RN currently depends on this prefix
69
+ if (stack !== '') {
70
+ format += '%s';
71
+ args = args.concat([stack]);
72
+ }
73
+ }
69
74
 
70
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
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
71
89
  // breaks IE9: https://github.com/facebook/react/issues/13610
72
90
  // eslint-disable-next-line react-internal/no-production-logging
73
91
 
74
- Function.prototype.apply.call(console[level], console, argsWithFormat);
92
+
93
+ Function.prototype.apply.call(console[level], console, args);
75
94
  }
76
95
  }
77
96
 
78
- // -----------------------------------------------------------------------------
79
- var enablePostpone = false;
80
-
81
97
  function scheduleWork(callback) {
82
98
  setTimeout(callback, 0);
83
99
  }
@@ -1523,6 +1539,37 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1523
1539
 
1524
1540
  var ReactSharedInternals = ReactSharedInternalsServer;
1525
1541
 
1542
+ function prepareStackTrace(error, structuredStackTrace) {
1543
+ var name = error.name || 'Error';
1544
+ var message = error.message || '';
1545
+ var stack = name + ': ' + message;
1546
+
1547
+ for (var i = 0; i < structuredStackTrace.length; i++) {
1548
+ stack += '\n at ' + structuredStackTrace[i].toString();
1549
+ }
1550
+
1551
+ return stack;
1552
+ }
1553
+
1554
+ function getStack(error) {
1555
+ // We override Error.prepareStackTrace with our own version that normalizes
1556
+ // the stack to V8 formatting even if the server uses other formatting.
1557
+ // It also ensures that source maps are NOT applied to this since that can
1558
+ // be slow we're better off doing that lazily from the client instead of
1559
+ // eagerly on the server. If the stack has already been read, then we might
1560
+ // not get a normalized stack and it might still have been source mapped.
1561
+ // So the client still needs to be resilient to this.
1562
+ var previousPrepare = Error.prepareStackTrace;
1563
+ Error.prepareStackTrace = prepareStackTrace;
1564
+
1565
+ try {
1566
+ // eslint-disable-next-line react-internal/safe-string-coercion
1567
+ return String(error.stack);
1568
+ } finally {
1569
+ Error.prepareStackTrace = previousPrepare;
1570
+ }
1571
+ }
1572
+
1526
1573
  var ObjectPrototype = Object.prototype;
1527
1574
  var stringify = JSON.stringify; // Serializable values
1528
1575
  // Thenable<ReactClientValue>
@@ -1585,6 +1632,7 @@ function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpo
1585
1632
 
1586
1633
  {
1587
1634
  request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1635
+ request.didWarnForKey = null;
1588
1636
  }
1589
1637
 
1590
1638
  var rootTask = createTask(request, model, null, false, abortSet);
@@ -1972,7 +2020,8 @@ function callLazyInitInDEV(lazy) {
1972
2020
  }
1973
2021
 
1974
2022
  function renderFunctionComponent(request, task, key, Component, props, owner, // DEV-only
1975
- stack) // DEV-only
2023
+ stack, // DEV-only
2024
+ validated) // DEV-only
1976
2025
  {
1977
2026
  // Reset the task's thenable state before continuing, so that if a later
1978
2027
  // component suspends we can reuse the same task object. If the same
@@ -2014,12 +2063,23 @@ stack) // DEV-only
2014
2063
  result = callComponentInDEV(Component, props, componentDebugInfo);
2015
2064
  }
2016
2065
 
2017
- if (typeof result === 'object' && result !== null) {
2066
+ if (typeof result === 'object' && result !== null && !isClientReference(result)) {
2018
2067
  if (typeof result.then === 'function') {
2019
2068
  // When the return value is in children position we can resolve it immediately,
2020
2069
  // to its value without a wrapper if it's synchronously available.
2021
2070
  var thenable = result;
2022
2071
 
2072
+ {
2073
+ // If the thenable resolves to an element, then it was in a static position,
2074
+ // the return value of a Server Component. That doesn't need further validation
2075
+ // of keys. The Server Component itself would have had a key.
2076
+ thenable.then(function (resolvedValue) {
2077
+ if (typeof resolvedValue === 'object' && resolvedValue !== null && resolvedValue.$$typeof === REACT_ELEMENT_TYPE) {
2078
+ resolvedValue._store.validated = 1;
2079
+ }
2080
+ }, function () {});
2081
+ }
2082
+
2023
2083
  if (thenable.status === 'fulfilled') {
2024
2084
  return thenable.value;
2025
2085
  } // TODO: Once we accept Promises as children on the client, we can just return
@@ -2090,6 +2150,11 @@ stack) // DEV-only
2090
2150
  {
2091
2151
  result._debugInfo = _iterableChild._debugInfo;
2092
2152
  }
2153
+ } else if (result.$$typeof === REACT_ELEMENT_TYPE) {
2154
+ // If the server component renders to an element, then it was in a static position.
2155
+ // That doesn't need further validation of keys. The Server Component itself would
2156
+ // have had a key.
2157
+ result._store.validated = 1;
2093
2158
  }
2094
2159
  } // Track this element's key on the Server Component on the keyPath context..
2095
2160
 
@@ -2116,12 +2181,26 @@ stack) // DEV-only
2116
2181
  }
2117
2182
 
2118
2183
  function renderFragment(request, task, children) {
2184
+ {
2185
+ for (var i = 0; i < children.length; i++) {
2186
+ var child = children[i];
2187
+
2188
+ if (child !== null && typeof child === 'object' && child.$$typeof === REACT_ELEMENT_TYPE) {
2189
+ var element = child;
2190
+
2191
+ if (element.key === null && !element._store.validated) {
2192
+ element._store.validated = 2;
2193
+ }
2194
+ }
2195
+ }
2196
+ }
2197
+
2119
2198
  if (task.keyPath !== null) {
2120
2199
  // We have a Server Component that specifies a key but we're now splitting
2121
2200
  // the tree using a fragment.
2122
2201
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2123
2202
  children: children
2124
- }];
2203
+ }, null] ;
2125
2204
 
2126
2205
  if (!task.implicitSlot) {
2127
2206
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2178,7 +2257,7 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2178
2257
  // the tree using a fragment.
2179
2258
  var fragment = [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {
2180
2259
  children: children
2181
- }];
2260
+ }, null] ;
2182
2261
 
2183
2262
  if (!task.implicitSlot) {
2184
2263
  // If this was keyed inside a set. I.e. the outer Server Component was keyed
@@ -2209,7 +2288,8 @@ function renderAsyncFragment(request, task, children, getAsyncIterator) {
2209
2288
  }
2210
2289
 
2211
2290
  function renderClientElement(task, type, key, props, owner, // DEV-only
2212
- stack) // DEV-only
2291
+ stack, // DEV-only
2292
+ validated) // DEV-only
2213
2293
  {
2214
2294
  // We prepend the terminal client element that actually gets serialized with
2215
2295
  // the keys of any Server Components which are not serialized.
@@ -2260,7 +2340,8 @@ function outlineTask(request, task) {
2260
2340
  }
2261
2341
 
2262
2342
  function renderElement(request, task, type, key, ref, props, owner, // DEV only
2263
- stack) // DEV only
2343
+ stack, // DEV only
2344
+ validated) // DEV only
2264
2345
  {
2265
2346
  if (ref !== null && ref !== undefined) {
2266
2347
  // When the ref moves to the regular props object this will implicitly
@@ -3206,9 +3287,8 @@ function emitPostponeChunk(request, id, postponeInstance) {
3206
3287
 
3207
3288
  try {
3208
3289
  // eslint-disable-next-line react-internal/safe-string-coercion
3209
- reason = String(postponeInstance.message); // eslint-disable-next-line react-internal/safe-string-coercion
3210
-
3211
- stack = String(postponeInstance.stack);
3290
+ reason = String(postponeInstance.message);
3291
+ stack = getStack(postponeInstance);
3212
3292
  } catch (x) {}
3213
3293
 
3214
3294
  row = serializeRowHeader('P', id) + stringify({
@@ -3231,9 +3311,8 @@ function emitErrorChunk(request, id, digest, error) {
3231
3311
  try {
3232
3312
  if (error instanceof Error) {
3233
3313
  // eslint-disable-next-line react-internal/safe-string-coercion
3234
- message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
3235
-
3236
- stack = String(error.stack);
3314
+ message = String(error.message);
3315
+ stack = getStack(error);
3237
3316
  } else if (typeof error === 'object' && error !== null) {
3238
3317
  message = describeObjectForErrorMessage(error);
3239
3318
  } else {
@@ -947,7 +947,11 @@ function renderFunctionComponent(request, task, key, Component, props) {
947
947
  thenableIndexCounter = 0;
948
948
  thenableState = prevThenableState;
949
949
  Component = Component(props, void 0);
950
- if ("object" === typeof Component && null !== Component) {
950
+ if (
951
+ "object" === typeof Component &&
952
+ null !== Component &&
953
+ Component.$$typeof !== CLIENT_REFERENCE_TAG$1
954
+ ) {
951
955
  if ("function" === typeof Component.then) {
952
956
  props = Component;
953
957
  if ("fulfilled" === props.status) return props.value;