| 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 {ReactIOInfo, ReactAsyncInfo} from 'shared/ReactTypes'; |
| 11 | import type {SuspenseNode} from './DevToolsFiberTypes'; |
| 12 | |
| 13 | export function ioExistsInSuspenseAncestor( |
| 14 | suspenseNode: SuspenseNode, |
| 15 | ioInfo: ReactIOInfo, |
| 16 | ): boolean { |
| 17 | let ancestor = suspenseNode.parent; |
| 18 | while (ancestor !== null) { |
| 19 | if (ancestor.suspendedBy.has(ioInfo)) { |
| 20 | return true; |
| 21 | } |
| 22 | ancestor = ancestor.parent; |
| 23 | } |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | export function getAwaitInSuspendedByFromIO( |
| 28 | suspensedBy: Array<ReactAsyncInfo>, |
| 29 | ioInfo: ReactIOInfo, |
| 30 | ): null | ReactAsyncInfo { |
| 31 | for (let i = 0; i < suspensedBy.length; i++) { |
| 32 | const asyncInfo = suspensedBy[i]; |
| 33 | if (asyncInfo.awaited === ioInfo) { |
| 34 | return asyncInfo; |
| 35 | } |
| 36 | } |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | export function getVirtualEndTime(ioInfo: ReactIOInfo): number { |
| 41 | if (ioInfo.env != null) { |
| 42 | // Sort client side content first so that scripts and streams don't |
| 43 | // cover up the effect of server time. |
| 44 | return ioInfo.end + 1000000; |
| 45 | } |
| 46 | return ioInfo.end; |
| 47 | } |