main
js 28 lines 879 Bytes
Raw
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 {ReactRecoverable, ReactRecoverableReason} from 'shared/ReactTypes';
11
12 import {enableBrowserAPI} from 'shared/ReactFeatureFlags';
13 import {REACT_RECOVERABLE_TYPE} from 'shared/ReactSymbols';
14
15 const browserImpl = function browser(
16 reason?: ReactRecoverableReason,
17 ): ReactRecoverable {
18 // This also runs in the browser, where the reason is never observed. Keep the
19 // value cheap and let an SSR renderer initialize the error if it defers work.
20 return {
21 $$typeof: REACT_RECOVERABLE_TYPE,
22 _reason: reason,
23 };
24 };
25
26 export const browser:
27 | ((reason?: ReactRecoverableReason) => ReactRecoverable)
28 | void = enableBrowserAPI ? browserImpl : undefined;