Skip to content

Commit 1549bda

Browse files
authored
[Flight] Only assign _store in dev mode when creating lazy types (#34354)
Small follow-up to #34350. The `_store` property is now only assigned in development mode when creating lazy types. It also uses the `validated` value that was passed to `createElement`, if applicable.
1 parent bb6f0c8 commit 1549bda

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ function createElement(
11721172
props: mixed,
11731173
owner: ?ReactComponentInfo, // DEV-only
11741174
stack: ?ReactStackTrace, // DEV-only
1175-
validated: number, // DEV-only
1175+
validated: 0 | 1 | 2, // DEV-only
11761176
):
11771177
| React$Element<any>
11781178
| LazyComponent<React$Element<any>, SomeChunk<React$Element<any>>> {
@@ -1268,7 +1268,7 @@ function createElement(
12681268
}
12691269
erroredChunk._debugInfo = [erroredComponent];
12701270
}
1271-
return createLazyChunkWrapper(erroredChunk);
1271+
return createLazyChunkWrapper(erroredChunk, validated);
12721272
}
12731273
if (handler.deps > 0) {
12741274
// We have blocked references inside this Element but we can turn this into
@@ -1277,7 +1277,7 @@ function createElement(
12771277
createBlockedChunk(response);
12781278
handler.value = element;
12791279
handler.chunk = blockedChunk;
1280-
const lazyType = createLazyChunkWrapper(blockedChunk);
1280+
const lazyType = createLazyChunkWrapper(blockedChunk, validated);
12811281
if (__DEV__) {
12821282
// After we have initialized any blocked references, initialize stack etc.
12831283
const init = initializeElement.bind(null, response, element, lazyType);
@@ -1295,18 +1295,20 @@ function createElement(
12951295

12961296
function createLazyChunkWrapper<T>(
12971297
chunk: SomeChunk<T>,
1298+
validated: 0 | 1 | 2, // DEV-only
12981299
): LazyComponent<T, SomeChunk<T>> {
12991300
const lazyType: LazyComponent<T, SomeChunk<T>> = {
13001301
$$typeof: REACT_LAZY_TYPE,
13011302
_payload: chunk,
1302-
_store: {validated: 0},
13031303
_init: readChunk,
13041304
};
13051305
if (__DEV__) {
13061306
// Ensure we have a live array to track future debug info.
13071307
const chunkDebugInfo: ReactDebugInfo =
13081308
chunk._debugInfo || (chunk._debugInfo = ([]: ReactDebugInfo));
13091309
lazyType._debugInfo = chunkDebugInfo;
1310+
// Initialize a store for key validation by the JSX runtime.
1311+
lazyType._store = {validated: validated};
13101312
}
13111313
return lazyType;
13121314
}
@@ -2111,7 +2113,7 @@ function parseModelString(
21112113
}
21122114
// We create a React.lazy wrapper around any lazy values.
21132115
// When passed into React, we'll know how to suspend on this.
2114-
return createLazyChunkWrapper(chunk);
2116+
return createLazyChunkWrapper(chunk, 0);
21152117
}
21162118
case '@': {
21172119
// Promise

packages/react/src/ReactLazy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ export type LazyComponent<T, P> = {
5959
$$typeof: symbol | number,
6060
_payload: P,
6161
_init: (payload: P) => T,
62-
_debugInfo?: null | ReactDebugInfo,
62+
6363
// __DEV__
64+
_debugInfo?: null | ReactDebugInfo,
6465
_store?: {validated: 0 | 1 | 2, ...}, // 0: not validated, 1: validated, 2: force fail
6566
};
6667

0 commit comments

Comments
 (0)