Skip to content

Commit bbfef70

Browse files
committed
Extract common logic into moveDebugInfoFromChunkToInnerValue
1 parent 020d65e commit bbfef70

File tree

1 file changed

+38
-60
lines changed

1 file changed

+38
-60
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 38 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,37 @@ function createErrorChunk<T>(
499499
return new ReactPromise(ERRORED, null, error);
500500
}
501501

502+
function moveDebugInfoFromChunkToInnerValue<T>(
503+
chunk: InitializedChunk<T>,
504+
value: T,
505+
): void {
506+
// Remove the debug info from the initialized chunk, and add it to the inner
507+
// value instead. This can be a React element, an array, or an uninitialized
508+
// Lazy.
509+
const resolvedValue = resolveLazy(value);
510+
if (
511+
typeof resolvedValue === 'object' &&
512+
resolvedValue !== null &&
513+
(isArray(resolvedValue) ||
514+
typeof resolvedValue[ASYNC_ITERATOR] === 'function' ||
515+
resolvedValue.$$typeof === REACT_ELEMENT_TYPE ||
516+
resolvedValue.$$typeof === REACT_LAZY_TYPE)
517+
) {
518+
const debugInfo = chunk._debugInfo.splice(0);
519+
if (isArray(resolvedValue._debugInfo)) {
520+
// $FlowFixMe[method-unbinding]
521+
resolvedValue._debugInfo.push.apply(resolvedValue._debugInfo, debugInfo);
522+
} else {
523+
Object.defineProperty((resolvedValue: any), '_debugInfo', {
524+
configurable: false,
525+
enumerable: false,
526+
writable: true,
527+
value: debugInfo,
528+
});
529+
}
530+
}
531+
}
532+
502533
function wakeChunk<T>(
503534
listeners: Array<InitializationReference | (T => mixed)>,
504535
value: T,
@@ -514,34 +545,7 @@ function wakeChunk<T>(
514545
}
515546

516547
if (__DEV__) {
517-
// Remove the debug info from the initialized chunk, and add it to the inner
518-
// value instead. This can be a React element, an array, or an uninitialized
519-
// Lazy.
520-
const resolvedValue = resolveLazy(value);
521-
if (
522-
typeof resolvedValue === 'object' &&
523-
resolvedValue !== null &&
524-
(isArray(resolvedValue) ||
525-
typeof resolvedValue[ASYNC_ITERATOR] === 'function' ||
526-
resolvedValue.$$typeof === REACT_ELEMENT_TYPE ||
527-
resolvedValue.$$typeof === REACT_LAZY_TYPE)
528-
) {
529-
const debugInfo = chunk._debugInfo.splice(0);
530-
if (isArray(resolvedValue._debugInfo)) {
531-
// $FlowFixMe[method-unbinding]
532-
resolvedValue._debugInfo.push.apply(
533-
resolvedValue._debugInfo,
534-
debugInfo,
535-
);
536-
} else {
537-
Object.defineProperty((resolvedValue: any), '_debugInfo', {
538-
configurable: false,
539-
enumerable: false,
540-
writable: true,
541-
value: debugInfo,
542-
});
543-
}
544-
}
548+
moveDebugInfoFromChunkToInnerValue(chunk, value);
545549
}
546550
}
547551

@@ -997,41 +1001,13 @@ function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
9971001
return;
9981002
}
9991003
}
1000-
1001-
if (__DEV__) {
1002-
// Remove the debug info from the initialized chunk, and add it to the
1003-
// inner value instead. This can be a React element, an array, or an
1004-
// uninitialized Lazy.
1005-
const resolvedValue = resolveLazy(value);
1006-
if (
1007-
typeof resolvedValue === 'object' &&
1008-
resolvedValue !== null &&
1009-
(isArray(resolvedValue) ||
1010-
typeof resolvedValue[ASYNC_ITERATOR] === 'function' ||
1011-
resolvedValue.$$typeof === REACT_ELEMENT_TYPE ||
1012-
resolvedValue.$$typeof === REACT_LAZY_TYPE)
1013-
) {
1014-
const debugInfo = chunk._debugInfo.splice(0);
1015-
if (isArray(resolvedValue._debugInfo)) {
1016-
// $FlowFixMe[method-unbinding]
1017-
resolvedValue._debugInfo.push.apply(
1018-
resolvedValue._debugInfo,
1019-
debugInfo,
1020-
);
1021-
} else {
1022-
Object.defineProperty((resolvedValue: any), '_debugInfo', {
1023-
configurable: false,
1024-
enumerable: false,
1025-
writable: true,
1026-
value: debugInfo,
1027-
});
1028-
}
1029-
}
1030-
}
1031-
10321004
const initializedChunk: InitializedChunk<T> = (chunk: any);
10331005
initializedChunk.status = INITIALIZED;
10341006
initializedChunk.value = value;
1007+
1008+
if (__DEV__) {
1009+
moveDebugInfoFromChunkToInnerValue(initializedChunk, value);
1010+
}
10351011
} catch (error) {
10361012
const erroredChunk: ErroredChunk<T> = (chunk: any);
10371013
erroredChunk.status = ERRORED;
@@ -1231,6 +1207,8 @@ function initializeElement(
12311207
element._store.validated = lazyNode._store.validated;
12321208
}
12331209

1210+
// If the lazy node is initialized, we move its debug info to the inner
1211+
// value.
12341212
if (lazyNode._payload.status === INITIALIZED && lazyNode._debugInfo) {
12351213
const debugInfo = lazyNode._debugInfo.splice(0);
12361214
if (element._debugInfo) {

0 commit comments

Comments
 (0)