| 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 {ReactComponentInfo} from 'shared/ReactTypes'; |
| 11 | |
| 12 | import { |
| 13 | supportsComponentStorage, |
| 14 | componentStorage, |
| 15 | } from '../ReactFlightServerConfig'; |
| 16 | |
| 17 | let currentOwner: ReactComponentInfo | null = null; |
| 18 | |
| 19 | export function setCurrentOwner(componentInfo: null | ReactComponentInfo) { |
| 20 | currentOwner = componentInfo; |
| 21 | } |
| 22 | |
| 23 | export function resolveOwner(): null | ReactComponentInfo { |
| 24 | if (currentOwner) return currentOwner; |
| 25 | // $FlowFixMe[constant-condition] |
| 26 | if (supportsComponentStorage) { |
| 27 | const owner = componentStorage.getStore(); |
| 28 | if (owner) return owner; |
| 29 | } |
| 30 | return null; |
| 31 | } |