| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import type {LazyComponent} from 'react/src/ReactLazy'; |
| 11 | |
| 12 | // These indirections exists so we can exclude its stack frame in DEV (and anything below it). |
| 13 | // TODO: Consider marking the whole bundle instead of these boundaries. |
| 14 | |
| 15 | const callComponent = { |
| 16 | react_stack_bottom_frame: function <Props, Arg, R>( |
| 17 | Component: (p: Props, arg: Arg) => R, |
| 18 | props: Props, |
| 19 | secondArg: Arg, |
| 20 | ): R { |
| 21 | return Component(props, secondArg); |
| 22 | }, |
| 23 | }; |
| 24 | |
| 25 | export const callComponentInDEV: <Props, Arg, R>( |
| 26 | Component: (p: Props, arg: Arg) => R, |
| 27 | props: Props, |
| 28 | secondArg: Arg, |
| 29 | ) => R = __DEV__ |
| 30 | ? // We use this technique to trick minifiers to preserve the function name. |
| 31 | (callComponent.react_stack_bottom_frame.bind(callComponent) as any) |
| 32 | : (null as any); |
| 33 | |
| 34 | interface ClassInstance<R> { |
| 35 | render(): R; |
| 36 | } |
| 37 | |
| 38 | const callRender = { |
| 39 | react_stack_bottom_frame: function <R>(instance: ClassInstance<R>): R { |
| 40 | return instance.render(); |
| 41 | }, |
| 42 | }; |
| 43 | |
| 44 | export const callRenderInDEV: <R>(instance: ClassInstance<R>) => R => R = |
| 45 | __DEV__ |
| 46 | ? // We use this technique to trick minifiers to preserve the function name. |
| 47 | (callRender.react_stack_bottom_frame.bind(callRender) as any) |
| 48 | : (null as any); |
| 49 | |
| 50 | const callLazyInit = { |
| 51 | react_stack_bottom_frame: function (lazy: LazyComponent<any, any>): any { |
| 52 | const payload = lazy._payload; |
| 53 | const init = lazy._init; |
| 54 | return init(payload); |
| 55 | }, |
| 56 | }; |
| 57 | |
| 58 | export const callLazyInitInDEV: (lazy: LazyComponent<any, any>) => any = __DEV__ |
| 59 | ? // We use this technique to trick minifiers to preserve the function name. |
| 60 | (callLazyInit.react_stack_bottom_frame.bind(callLazyInit) as any) |
| 61 | : (null as any); |