mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 00:20:04 +01:00
[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.
This commit is contained in:
parent
bb6f0c8d2f
commit
1549bda33f
12
packages/react-client/src/ReactFlightClient.js
vendored
12
packages/react-client/src/ReactFlightClient.js
vendored
|
|
@ -1172,7 +1172,7 @@ function createElement(
|
|||
props: mixed,
|
||||
owner: ?ReactComponentInfo, // DEV-only
|
||||
stack: ?ReactStackTrace, // DEV-only
|
||||
validated: number, // DEV-only
|
||||
validated: 0 | 1 | 2, // DEV-only
|
||||
):
|
||||
| React$Element<any>
|
||||
| LazyComponent<React$Element<any>, SomeChunk<React$Element<any>>> {
|
||||
|
|
@ -1268,7 +1268,7 @@ function createElement(
|
|||
}
|
||||
erroredChunk._debugInfo = [erroredComponent];
|
||||
}
|
||||
return createLazyChunkWrapper(erroredChunk);
|
||||
return createLazyChunkWrapper(erroredChunk, validated);
|
||||
}
|
||||
if (handler.deps > 0) {
|
||||
// We have blocked references inside this Element but we can turn this into
|
||||
|
|
@ -1277,7 +1277,7 @@ function createElement(
|
|||
createBlockedChunk(response);
|
||||
handler.value = element;
|
||||
handler.chunk = blockedChunk;
|
||||
const lazyType = createLazyChunkWrapper(blockedChunk);
|
||||
const lazyType = createLazyChunkWrapper(blockedChunk, validated);
|
||||
if (__DEV__) {
|
||||
// After we have initialized any blocked references, initialize stack etc.
|
||||
const init = initializeElement.bind(null, response, element, lazyType);
|
||||
|
|
@ -1295,11 +1295,11 @@ function createElement(
|
|||
|
||||
function createLazyChunkWrapper<T>(
|
||||
chunk: SomeChunk<T>,
|
||||
validated: 0 | 1 | 2, // DEV-only
|
||||
): LazyComponent<T, SomeChunk<T>> {
|
||||
const lazyType: LazyComponent<T, SomeChunk<T>> = {
|
||||
$$typeof: REACT_LAZY_TYPE,
|
||||
_payload: chunk,
|
||||
_store: {validated: 0},
|
||||
_init: readChunk,
|
||||
};
|
||||
if (__DEV__) {
|
||||
|
|
@ -1307,6 +1307,8 @@ function createLazyChunkWrapper<T>(
|
|||
const chunkDebugInfo: ReactDebugInfo =
|
||||
chunk._debugInfo || (chunk._debugInfo = ([]: ReactDebugInfo));
|
||||
lazyType._debugInfo = chunkDebugInfo;
|
||||
// Initialize a store for key validation by the JSX runtime.
|
||||
lazyType._store = {validated: validated};
|
||||
}
|
||||
return lazyType;
|
||||
}
|
||||
|
|
@ -2111,7 +2113,7 @@ function parseModelString(
|
|||
}
|
||||
// We create a React.lazy wrapper around any lazy values.
|
||||
// When passed into React, we'll know how to suspend on this.
|
||||
return createLazyChunkWrapper(chunk);
|
||||
return createLazyChunkWrapper(chunk, 0);
|
||||
}
|
||||
case '@': {
|
||||
// Promise
|
||||
|
|
|
|||
|
|
@ -59,8 +59,9 @@ export type LazyComponent<T, P> = {
|
|||
$$typeof: symbol | number,
|
||||
_payload: P,
|
||||
_init: (payload: P) => T,
|
||||
_debugInfo?: null | ReactDebugInfo,
|
||||
|
||||
// __DEV__
|
||||
_debugInfo?: null | ReactDebugInfo,
|
||||
_store?: {validated: 0 | 1 | 2, ...}, // 0: not validated, 1: validated, 2: force fail
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user