import type {LazyComponent} from 'react/src/ReactLazy';
import type {ReactComponentInfo} from 'shared/ReactTypes';
import type {ReactClientValue} from './ReactFlightServer';
import {setCurrentOwner} from './flight/ReactFlightCurrentOwner';
const callComponent = {
react_stack_bottom_frame: function <Props, R>(
Component: (p: Props, arg: void) => R,
props: Props,
componentDebugInfo: ReactComponentInfo,
): R {
const secondArg = undefined;
setCurrentOwner(componentDebugInfo);
try {
return Component(props, secondArg);
} finally {
setCurrentOwner(null);
}
},
};
export const callComponentInDEV: <Props, R>(
Component: (p: Props, arg: void) => R,
props: Props,
componentDebugInfo: ReactComponentInfo,
) => R = __DEV__
? // We use this technique to trick minifiers to preserve the function name.
(callComponent.react_stack_bottom_frame.bind(callComponent): any)
: (null: any);
const callLazyInit = {
react_stack_bottom_frame: function (lazy: LazyComponent<any, any>): any {
const payload = lazy._payload;
const init = lazy._init;
return init(payload);
},
};
export const callLazyInitInDEV: (lazy: LazyComponent<any, any>) => any = __DEV__
? // We use this technique to trick minifiers to preserve the function name.
(callLazyInit.react_stack_bottom_frame.bind(callLazyInit): any)
: (null: any);
const callIterator = {
react_stack_bottom_frame: function (
iterator: $AsyncIterator<ReactClientValue, ReactClientValue, void>,
progress: (
entry:
| {done: false, +value: ReactClientValue, ...}
| {done: true, +value: ReactClientValue, ...},
) => void,
error: (reason: mixed) => void,
): void {
iterator.next().then(progress, error);
},
};
export const callIteratorInDEV: (
iterator: $AsyncIterator<ReactClientValue, ReactClientValue, void>,
progress: (
entry:
| {done: false, +value: ReactClientValue, ...}
| {done: true, +value: ReactClientValue, ...},
) => void,
error: (reason: mixed) => void,
) => void = __DEV__
? // We use this technique to trick minifiers to preserve the function name.
(callIterator.react_stack_bottom_frame.bind(callIterator): any)
: (null: any);