| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and its 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 ReactSharedInternals from 'shared/ReactSharedInternals'; |
| 11 | |
| 12 | let lastResetTime = 0; |
| 13 | |
| 14 | let getCurrentTime: () => number | DOMHighResTimeStamp; |
| 15 | const hasPerformanceNow = |
| 16 | // $FlowFixMe[method-unbinding] |
| 17 | typeof performance === 'object' && typeof performance.now === 'function'; |
| 18 | |
| 19 | if (hasPerformanceNow) { |
| 20 | const localPerformance = performance; |
| 21 | getCurrentTime = () => localPerformance.now(); |
| 22 | } else { |
| 23 | const localDate = Date; |
| 24 | getCurrentTime = () => localDate.now(); |
| 25 | } |
| 26 | |
| 27 | export function resetOwnerStackLimit() { |
| 28 | if (__DEV__) { |
| 29 | const now = getCurrentTime(); |
| 30 | const timeSinceLastReset = now - lastResetTime; |
| 31 | if (timeSinceLastReset > 1000) { |
| 32 | ReactSharedInternals.recentlyCreatedOwnerStacks = 0; |
| 33 | lastResetTime = now; |
| 34 | } |
| 35 | } else { |
| 36 | // These errors should never make it into a build so we don't need to encode them in codes.json |
| 37 | // eslint-disable-next-line react-internal/prod-error-codes |
| 38 | throw new Error( |
| 39 | 'resetOwnerStackLimit should never be called in production mode. This is a bug in React.', |
| 40 | ); |
| 41 | } |
| 42 | } |