| 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 {ReactNodeList} from 'shared/ReactTypes'; |
| 11 | |
| 12 | import ReactVersion from 'shared/ReactVersion'; |
| 13 | |
| 14 | import {isValidContainer} from 'react-dom-bindings/src/client/ReactDOMContainer'; |
| 15 | import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal'; |
| 16 | import {flushSync} from './ReactDOMFlushSync'; |
| 17 | |
| 18 | import { |
| 19 | prefetchDNS, |
| 20 | preconnect, |
| 21 | preload, |
| 22 | preloadModule, |
| 23 | preinit, |
| 24 | preinitModule, |
| 25 | } from './ReactDOMFloat'; |
| 26 | import { |
| 27 | requestFormReset, |
| 28 | useFormStatus, |
| 29 | useFormState, |
| 30 | } from 'react-dom-bindings/src/shared/ReactDOMFormActions'; |
| 31 | import {browser} from './ReactDOMBrowser'; |
| 32 | |
| 33 | if (__DEV__) { |
| 34 | if ( |
| 35 | typeof Map !== 'function' || |
| 36 | // $FlowFixMe[prop-missing] Flow incorrectly thinks Map has no prototype |
| 37 | Map.prototype == null || |
| 38 | typeof Map.prototype.forEach !== 'function' || |
| 39 | typeof Set !== 'function' || |
| 40 | // $FlowFixMe[prop-missing] Flow incorrectly thinks Set has no prototype |
| 41 | Set.prototype == null || |
| 42 | typeof Set.prototype.clear !== 'function' || |
| 43 | typeof Set.prototype.forEach !== 'function' |
| 44 | ) { |
| 45 | console.error( |
| 46 | 'React depends on Map and Set built-in types. Make sure that you load a ' + |
| 47 | 'polyfill in older browsers. https://reactjs.org/link/react-polyfills', |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | function batchedUpdates<A, R>(fn: (a: A) => R, a: A): R { |
| 53 | // batchedUpdates is now just a passthrough noop |
| 54 | return fn(a); |
| 55 | } |
| 56 | |
| 57 | function createPortal( |
| 58 | children: ReactNodeList, |
| 59 | container: Element | DocumentFragment, |
| 60 | key: ?string = null, |
| 61 | ): React$Portal { |
| 62 | if (!isValidContainer(container)) { |
| 63 | throw new Error('Target container is not a DOM element.'); |
| 64 | } |
| 65 | |
| 66 | // TODO: pass ReactDOM portal implementation as third argument |
| 67 | // $FlowFixMe[incompatible-type] The Flow type is opaque but there's no way to actually create it. |
| 68 | return createPortalImpl(children, container, null, key); |
| 69 | } |
| 70 | |
| 71 | export { |
| 72 | ReactVersion as version, |
| 73 | browser, |
| 74 | createPortal, |
| 75 | flushSync, |
| 76 | batchedUpdates as unstable_batchedUpdates, |
| 77 | prefetchDNS, |
| 78 | preconnect, |
| 79 | preload, |
| 80 | preloadModule, |
| 81 | preinit, |
| 82 | preinitModule, |
| 83 | requestFormReset, |
| 84 | useFormStatus, |
| 85 | useFormState, |
| 86 | }; |