main
js 81 lines 2.58 KB
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 {createRoot, hydrateRoot} from './ReactDOMRoot';
11
12 import {
13 injectIntoDevTools,
14 findHostInstance,
15 } from 'react-reconciler/src/ReactFiberReconciler';
16 import {canUseDOM} from 'shared/ExecutionEnvironment';
17 import ReactVersion from 'shared/ReactVersion';
18
19 import Internals from 'shared/ReactDOMSharedInternals';
20
21 import {ensureCorrectIsomorphicReactVersion} from '../shared/ensureCorrectIsomorphicReactVersion';
22 ensureCorrectIsomorphicReactVersion();
23
24 if (__DEV__) {
25 if (
26 typeof Map !== 'function' ||
27 // $FlowFixMe[prop-missing] Flow incorrectly thinks Map has no prototype
28 Map.prototype == null ||
29 typeof Map.prototype.forEach !== 'function' ||
30 typeof Set !== 'function' ||
31 // $FlowFixMe[prop-missing] Flow incorrectly thinks Set has no prototype
32 Set.prototype == null ||
33 typeof Set.prototype.clear !== 'function' ||
34 typeof Set.prototype.forEach !== 'function'
35 ) {
36 console.error(
37 'React depends on Map and Set built-in types. Make sure that you load a ' +
38 'polyfill in older browsers. https://react.dev/link/react-polyfills',
39 );
40 }
41 }
42
43 function findDOMNode(
44 componentOrElement: component(...props: any),
45 ): null | Element | Text {
46 return findHostInstance(componentOrElement);
47 }
48
49 // Expose findDOMNode on internals
50 Internals.findDOMNode = findDOMNode;
51
52 export {ReactVersion as version, createRoot, hydrateRoot};
53
54 const foundDevTools = injectIntoDevTools();
55
56 if (__DEV__) {
57 if (!foundDevTools && canUseDOM && window.top === window.self) {
58 // If we're in Chrome or Firefox, provide a download link if not installed.
59 if (
60 (navigator.userAgent.indexOf('Chrome') > -1 &&
61 navigator.userAgent.indexOf('Edge') === -1) ||
62 navigator.userAgent.indexOf('Firefox') > -1
63 ) {
64 const protocol = window.location.protocol;
65 // Don't warn in exotic cases like chrome-extension://.
66 if (/^(https?|file):$/.test(protocol)) {
67 // eslint-disable-next-line react-internal/no-production-logging
68 console.info(
69 '%cDownload the React DevTools ' +
70 'for a better development experience: ' +
71 'https://react.dev/link/react-devtools' +
72 (protocol === 'file:'
73 ? '\nYou might need to use a local HTTP server (instead of file://): ' +
74 'https://react.dev/link/react-devtools-faq'
75 : ''),
76 'font-weight:bold',
77 );
78 }
79 }
80 }
81 }