| 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 { |
| 11 | enableDefaultTransitionIndicator, |
| 12 | enableViewTransition, |
| 13 | } from 'shared/ReactFeatureFlags'; |
| 14 | |
| 15 | export let rootMutationContext: boolean = false; |
| 16 | export let viewTransitionMutationContext: boolean = false; |
| 17 | |
| 18 | export function pushRootMutationContext(): void { |
| 19 | if (enableDefaultTransitionIndicator) { |
| 20 | rootMutationContext = false; |
| 21 | } |
| 22 | if (enableViewTransition) { |
| 23 | viewTransitionMutationContext = false; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | export function pushMutationContext(): boolean { |
| 28 | if (!enableViewTransition) { |
| 29 | return false; |
| 30 | } |
| 31 | const prev = viewTransitionMutationContext; |
| 32 | viewTransitionMutationContext = false; |
| 33 | return prev; |
| 34 | } |
| 35 | |
| 36 | export function popMutationContext(prev: boolean): void { |
| 37 | if (enableViewTransition) { |
| 38 | if (viewTransitionMutationContext) { |
| 39 | rootMutationContext = true; |
| 40 | } |
| 41 | viewTransitionMutationContext = prev; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | export function trackHostMutation(): void { |
| 46 | // This is extremely hot function that must be inlined. Don't add more stuff. |
| 47 | if (enableViewTransition) { |
| 48 | viewTransitionMutationContext = true; |
| 49 | } else if (enableDefaultTransitionIndicator) { |
| 50 | // We only set this if enableViewTransition is not on. Otherwise we track |
| 51 | // it on the viewTransitionMutationContext and collect it when we pop |
| 52 | // to avoid more than a single operation in this hot path. |
| 53 | rootMutationContext = true; |
| 54 | } |
| 55 | } |