@samitouri / QOS-React-2 / commits / 9007fdc8f1

[DOM] Shrink ReactDOMSharedInternals source representation (#28771)

Stacked on #28751 ReactDOMSharedInternals uses properties of considerable length to model mutuable state. These properties are not mangled during minification and contribute a not insigificant amount to the uncompressed bundle size and to a lesser degree compressed bundle size. This change rewrites the DOMInternals in a way that shortens property names so we can have smaller builds. It also treats the entire object as a mutable container rather than having different mutable sub objects. The same treatment should be given to ReactSharedInternals

Josh Story committed Apr 8, 2024 at 13:39 UTC 9007fdc8f103a5d9247be384791496db9a3be91d
15 files changed +357 -136
packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.js
+3 -3
@@ -25,15 +25,15 @@ export function setCurrentUpdatePriority(
25 // is much longer. I hope this is consistent enough to rely on across builds
26 IntentionallyUnusedArgument?: empty,
27 ): void {
28 - ReactDOMSharedInternals.up = newPriority;
28 + ReactDOMSharedInternals.p /* currentUpdatePriority */ = newPriority;
29 }
30
31 export function getCurrentUpdatePriority(): EventPriority {
32 - return ReactDOMSharedInternals.up;
32 + return ReactDOMSharedInternals.p; /* currentUpdatePriority */
33 }
34
35 export function resolveUpdatePriority(): EventPriority {
36 - const updatePriority = ReactDOMSharedInternals.up;
36 + const updatePriority = ReactDOMSharedInternals.p; /* currentUpdatePriority */
37 if (updatePriority !== NoEventPriority) {
38 return updatePriority;
39 }
packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
+3 -4
@@ -104,8 +104,6 @@ import escapeSelectorAttributeValueInsideDoubleQuotes from './escapeSelectorAttr
104 import {flushSyncWork as flushSyncWorkOnAllRoots} from 'react-reconciler/src/ReactFiberWorkLoop';
105
106 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
107 -const ReactDOMCurrentDispatcher =
108 - ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
107
108 export type Type = string;
109 export type Props = {
@@ -1924,8 +1922,9 @@ function getDocumentFromRoot(root: HoistableRoot): Document {
1922 return root.ownerDocument || root;
1923 }
1924
1927 -const previousDispatcher = ReactDOMCurrentDispatcher.current;
1928 -ReactDOMCurrentDispatcher.current = {
1925 +const previousDispatcher =
1926 + ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
1927 +ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
1928 flushSyncWork: disableLegacyMode
1929 ? flushSyncWork
1930 : previousDispatcher.flushSyncWork,
packages/react-dom-bindings/src/server/ReactDOMFlightServerHostDispatcher.js
+3 -4
@@ -23,11 +23,10 @@ import {
23 } from 'react-server/src/ReactFlightServer';
24
25 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
26 -const ReactDOMCurrentDispatcher =
27 - ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
26
29 -const previousDispatcher = ReactDOMCurrentDispatcher.current;
30 -ReactDOMCurrentDispatcher.current = {
27 +const previousDispatcher =
28 + ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
29 +ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
30 flushSyncWork: previousDispatcher.flushSyncWork,
31 prefetchDNS,
32 preconnect,
packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
+3 -4
@@ -83,11 +83,10 @@ import {getValueDescriptorExpectingObjectForWarning} from '../shared/ReactDOMRes
83 import {NotPending} from '../shared/ReactDOMFormActions';
84
85 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
86 -const ReactDOMCurrentDispatcher =
87 - ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
86
89 -const previousDispatcher = ReactDOMCurrentDispatcher.current;
90 -ReactDOMCurrentDispatcher.current = {
87 +const previousDispatcher =
88 + ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
89 +ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
90 flushSyncWork: previousDispatcher.flushSyncWork,
91 prefetchDNS,
92 preconnect,
packages/react-dom-bindings/src/shared/ReactFlightClientConfigDOM.js
+5 -11
@@ -13,8 +13,6 @@
13 import type {HintCode, HintModel} from '../server/ReactFlightServerConfigDOM';
14
15 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
16 -const ReactDOMCurrentDispatcher =
17 - ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
16
17 import {getCrossOriginString} from './crossOriginStrings';
18
@@ -22,7 +20,7 @@ export function dispatchHint<Code: HintCode>(
20 code: Code,
21 model: HintModel<Code>,
22 ): void {
25 - const dispatcher = ReactDOMCurrentDispatcher.current;
23 + const dispatcher = ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
24 switch (code) {
25 case 'D': {
26 const refined = refineModel(code, model);
@@ -117,13 +115,11 @@ export function preinitModuleForSSR(
115 nonce: ?string,
116 crossOrigin: ?string,
117 ) {
120 - const dispatcher = ReactDOMCurrentDispatcher.current;
121 - if (dispatcher) {
122 - dispatcher.preinitModuleScript(href, {
118 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
119 + .preinitModuleScript(href, {
120 crossOrigin: getCrossOriginString(crossOrigin),
121 nonce,
122 });
126 - }
123 }
124
125 export function preinitScriptForSSR(
@@ -131,11 +127,9 @@ export function preinitScriptForSSR(
127 nonce: ?string,
128 crossOrigin: ?string,
129 ) {
134 - const dispatcher = ReactDOMCurrentDispatcher.current;
135 - if (dispatcher) {
136 - dispatcher.preinitScript(href, {
130 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
131 + .preinitScript(href, {
132 crossOrigin: getCrossOriginString(crossOrigin),
133 nonce,
134 });
140 - }
135 }
packages/react-dom/client.js
+4 -4
@@ -27,13 +27,13 @@ export function createRoot(
27 options?: CreateRootOptions,
28 ): RootType {
29 if (__DEV__) {
30 - Internals.usingClientEntryPoint = true;
30 + (Internals: any).usingClientEntryPoint = true;
31 }
32 try {
33 return createRootImpl(container, options);
34 } finally {
35 if (__DEV__) {
36 - Internals.usingClientEntryPoint = false;
36 + (Internals: any).usingClientEntryPoint = false;
37 }
38 }
39 }
@@ -44,13 +44,13 @@ export function hydrateRoot(
44 options?: HydrateRootOptions,
45 ): RootType {
46 if (__DEV__) {
47 - Internals.usingClientEntryPoint = true;
47 + (Internals: any).usingClientEntryPoint = true;
48 }
49 try {
50 return hydrateRootImpl(container, children, options);
51 } finally {
52 if (__DEV__) {
53 - Internals.usingClientEntryPoint = false;
53 + (Internals: any).usingClientEntryPoint = false;
54 }
55 }
56 }
packages/react-dom/index.classic.fb.js
+2 -2
@@ -9,7 +9,7 @@
9
10 import {isEnabled} from 'react-dom-bindings/src/events/ReactDOMEventListener';
11
12 -import Internals from './src/ReactDOMSharedInternals';
12 +import Internals from './src/ReactDOMSharedInternalsFB';
13
14 // For classic WWW builds, include a few internals that are already in use.
15 Object.assign((Internals: any), {
@@ -32,7 +32,7 @@ export {
32 preinit,
33 preinitModule,
34 version,
35 -} from './src/client/ReactDOM';
35 +} from './src/client/ReactDOMFB';
36
37 export {
38 createRoot,
packages/react-dom/index.modern.fb.js
+2 -2
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './src/ReactDOMSharedInternals';
10 +export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './src/ReactDOMSharedInternalsFB';
11 export {
12 createPortal,
13 flushSync,
@@ -23,6 +23,6 @@ export {
23 preinit,
24 preinitModule,
25 version,
26 -} from './src/client/ReactDOM';
26 +} from './src/client/ReactDOMFB';
27
28 export {createRoot, hydrateRoot} from './src/client/ReactDOMRootFB';
packages/react-dom/src/ReactDOMSharedInternals.js
+16 -14
@@ -12,18 +12,19 @@ import type {HostDispatcher} from './shared/ReactDOMTypes';
12
13 import {NoEventPriority} from 'react-reconciler/src/ReactEventPriorities';
14
15 -type InternalsType = {
16 - usingClientEntryPoint: boolean,
17 - Events: [any, any, any, any, any, any],
18 - ReactDOMCurrentDispatcher: {
19 - current: HostDispatcher,
20 - },
15 +type ReactDOMInternals = {
16 + d /* ReactDOMCurrentDispatcher */: HostDispatcher,
17 + p /* currentUpdatePriority */: EventPriority,
18 findDOMNode:
19 | null
20 | ((
21 componentOrElement: React$Component<any, any>,
22 ) => null | Element | Text),
26 - up /* currentUpdatePriority */: EventPriority,
23 + usingClientEntryPoint: boolean,
24 +};
25 +
26 +export type ReactDOMInternalsDev = ReactDOMInternals & {
27 + usingClientEntryPoint: boolean,
28 };
29
30 function noop() {}
@@ -39,14 +40,15 @@ const DefaultDispatcher: HostDispatcher = {
40 preinitModuleScript: noop,
41 };
42
42 -const Internals: InternalsType = {
43 - usingClientEntryPoint: false,
44 - Events: (null: any),
45 - ReactDOMCurrentDispatcher: {
46 - current: DefaultDispatcher,
47 - },
43 +const Internals: ReactDOMInternals = {
44 + d /* ReactDOMCurrentDispatcher */: DefaultDispatcher,
45 + p /* currentUpdatePriority */: NoEventPriority,
46 findDOMNode: null,
49 - up /* currentUpdatePriority */: NoEventPriority,
47 + usingClientEntryPoint: false,
48 };
49
50 +// if (__DEV__) {
51 +// (Internals: any).usingClientEntryPoint = false;
52 +// }
53 +
54 export default Internals;
packages/react-dom/src/ReactDOMSharedInternalsFB.js new
+46
@@ -0,0 +1,46 @@
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 {EventPriority} from 'react-reconciler/src/ReactEventPriorities';
11 +import type {HostDispatcher} from './shared/ReactDOMTypes';
12 +
13 +import {NoEventPriority} from 'react-reconciler/src/ReactEventPriorities';
14 +
15 +type ReactDOMInternals = {
16 + Events: [any, any, any, any, any, any],
17 + d /* ReactDOMCurrentDispatcher */: HostDispatcher,
18 + p /* currentUpdatePriority */: EventPriority,
19 + findDOMNode:
20 + | null
21 + | ((
22 + componentOrElement: React$Component<any, any>,
23 + ) => null | Element | Text),
24 +};
25 +
26 +function noop() {}
27 +
28 +const DefaultDispatcher: HostDispatcher = {
29 + flushSyncWork: noop,
30 + prefetchDNS: noop,
31 + preconnect: noop,
32 + preload: noop,
33 + preloadModule: noop,
34 + preinitScript: noop,
35 + preinitStyle: noop,
36 + preinitModuleScript: noop,
37 +};
38 +
39 +const Internals: ReactDOMInternals = {
40 + Events: (null: any),
41 + d /* ReactDOMCurrentDispatcher */: DefaultDispatcher,
42 + p /* currentUpdatePriority */: NoEventPriority,
43 + findDOMNode: null,
44 +};
45 +
46 +export default Internals;
packages/react-dom/src/client/ReactDOM.js
+3 -23
@@ -34,16 +34,7 @@ import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal
34 import {canUseDOM} from 'shared/ExecutionEnvironment';
35 import ReactVersion from 'shared/ReactVersion';
36
37 -import {
38 - getClosestInstanceFromNode,
39 - getInstanceFromNode,
40 - getNodeFromInstance,
41 - getFiberCurrentPropsFromNode,
42 -} from 'react-dom-bindings/src/client/ReactDOMComponentTree';
43 -import {
44 - enqueueStateRestore,
45 - restoreStateIfNeeded,
46 -} from 'react-dom-bindings/src/events/ReactDOMControlledComponent';
37 +import {getClosestInstanceFromNode} from 'react-dom-bindings/src/client/ReactDOMComponentTree';
38 import Internals from '../ReactDOMSharedInternals';
39
40 export {
@@ -97,7 +88,7 @@ function createRoot(
88 options?: CreateRootOptions,
89 ): RootType {
90 if (__DEV__) {
100 - if (!Internals.usingClientEntryPoint && !__UMD__) {
91 + if (!(Internals: any).usingClientEntryPoint && !__UMD__) {
92 console.error(
93 'You are importing createRoot from "react-dom" which is not supported. ' +
94 'You should instead import it from "react-dom/client".',
@@ -113,7 +104,7 @@ function hydrateRoot(
104 options?: HydrateRootOptions,
105 ): RootType {
106 if (__DEV__) {
116 - if (!Internals.usingClientEntryPoint && !__UMD__) {
107 + if (!(Internals: any).usingClientEntryPoint && !__UMD__) {
108 console.error(
109 'You are importing hydrateRoot from "react-dom" which is not supported. ' +
110 'You should instead import it from "react-dom/client".',
@@ -177,17 +168,6 @@ export {
168 runWithPriority as unstable_runWithPriority,
169 };
170
180 -// Keep in sync with ReactTestUtils.js.
181 -// This is an array for better minification.
182 -Internals.Events = [
183 - getInstanceFromNode,
184 - getNodeFromInstance,
185 - getFiberCurrentPropsFromNode,
186 - enqueueStateRestore,
187 - restoreStateIfNeeded,
188 - unstable_batchedUpdates,
189 -];
190 -
171 const foundDevTools = injectIntoDevTools({
172 findFiberByHostInstance: getClosestInstanceFromNode,
173 bundleType: __DEV__ ? 1 : 0,
packages/react-dom/src/client/ReactDOMFB.js new
+180
@@ -0,0 +1,180 @@
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 {disableLegacyMode} from 'shared/ReactFeatureFlags';
13 +import {isValidContainer} from './ReactDOMRoot';
14 +import {createEventHandle} from 'react-dom-bindings/src/client/ReactDOMEventHandle';
15 +import {runWithPriority} from 'react-dom-bindings/src/client/ReactDOMUpdatePriority';
16 +import {flushSync as flushSyncIsomorphic} from '../shared/ReactDOMFlushSync';
17 +
18 +import {
19 + flushSyncFromReconciler as flushSyncWithoutWarningIfAlreadyRendering,
20 + isAlreadyRendering,
21 + injectIntoDevTools,
22 + findHostInstance,
23 +} from 'react-reconciler/src/ReactFiberReconciler';
24 +import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
25 +import {canUseDOM} from 'shared/ExecutionEnvironment';
26 +import ReactVersion from 'shared/ReactVersion';
27 +
28 +import {
29 + getClosestInstanceFromNode,
30 + getInstanceFromNode,
31 + getNodeFromInstance,
32 + getFiberCurrentPropsFromNode,
33 +} from 'react-dom-bindings/src/client/ReactDOMComponentTree';
34 +import {
35 + enqueueStateRestore,
36 + restoreStateIfNeeded,
37 +} from 'react-dom-bindings/src/events/ReactDOMControlledComponent';
38 +import Internals from '../ReactDOMSharedInternalsFB';
39 +
40 +export {
41 + prefetchDNS,
42 + preconnect,
43 + preload,
44 + preloadModule,
45 + preinit,
46 + preinitModule,
47 +} from '../shared/ReactDOMFloat';
48 +export {
49 + useFormStatus,
50 + useFormState,
51 +} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
52 +
53 +if (__DEV__) {
54 + if (
55 + typeof Map !== 'function' ||
56 + // $FlowFixMe[prop-missing] Flow incorrectly thinks Map has no prototype
57 + Map.prototype == null ||
58 + typeof Map.prototype.forEach !== 'function' ||
59 + typeof Set !== 'function' ||
60 + // $FlowFixMe[prop-missing] Flow incorrectly thinks Set has no prototype
61 + Set.prototype == null ||
62 + typeof Set.prototype.clear !== 'function' ||
63 + typeof Set.prototype.forEach !== 'function'
64 + ) {
65 + console.error(
66 + 'React depends on Map and Set built-in types. Make sure that you load a ' +
67 + 'polyfill in older browsers. https://react.dev/link/react-polyfills',
68 + );
69 + }
70 +}
71 +
72 +function createPortal(
73 + children: ReactNodeList,
74 + container: Element | DocumentFragment,
75 + key: ?string = null,
76 +): React$Portal {
77 + if (!isValidContainer(container)) {
78 + throw new Error('Target container is not a DOM element.');
79 + }
80 +
81 + // TODO: pass ReactDOM portal implementation as third argument
82 + // $FlowFixMe[incompatible-return] The Flow type is opaque but there's no way to actually create it.
83 + return createPortalImpl(children, container, null, key);
84 +}
85 +
86 +// Overload the definition to the two valid signatures.
87 +// Warning, this opts-out of checking the function body.
88 +declare function flushSyncFromReconciler<R>(fn: () => R): R;
89 +// eslint-disable-next-line no-redeclare
90 +declare function flushSyncFromReconciler(): void;
91 +// eslint-disable-next-line no-redeclare
92 +function flushSyncFromReconciler<R>(fn: (() => R) | void): R | void {
93 + if (__DEV__) {
94 + if (isAlreadyRendering()) {
95 + console.error(
96 + 'flushSync was called from inside a lifecycle method. React cannot ' +
97 + 'flush when React is already rendering. Consider moving this call to ' +
98 + 'a scheduler task or micro task.',
99 + );
100 + }
101 + }
102 + return flushSyncWithoutWarningIfAlreadyRendering(fn);
103 +}
104 +
105 +const flushSync: typeof flushSyncIsomorphic = disableLegacyMode
106 + ? flushSyncIsomorphic
107 + : flushSyncFromReconciler;
108 +
109 +function findDOMNode(
110 + componentOrElement: React$Component<any, any>,
111 +): null | Element | Text {
112 + return findHostInstance(componentOrElement);
113 +}
114 +
115 +// Expose findDOMNode on internals
116 +Internals.findDOMNode = findDOMNode;
117 +
118 +function unstable_batchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
119 + // batchedUpdates was a legacy mode feature that is a no-op outside of
120 + // legacy mode. In 19, we made it an actual no-op, but we're keeping it
121 + // for now since there may be libraries that still include it.
122 + return fn(a);
123 +}
124 +
125 +export {
126 + createPortal,
127 + unstable_batchedUpdates,
128 + flushSync,
129 + ReactVersion as version,
130 + // enableCreateEventHandleAPI
131 + createEventHandle as unstable_createEventHandle,
132 + // TODO: Remove this once callers migrate to alternatives.
133 + // This should only be used by React internals.
134 + runWithPriority as unstable_runWithPriority,
135 +};
136 +
137 +// Keep in sync with ReactTestUtils.js.
138 +// This is an array for better minification.
139 +Internals.Events /* Events */ = [
140 + getInstanceFromNode,
141 + getNodeFromInstance,
142 + getFiberCurrentPropsFromNode,
143 + enqueueStateRestore,
144 + restoreStateIfNeeded,
145 + unstable_batchedUpdates,
146 +];
147 +
148 +const foundDevTools = injectIntoDevTools({
149 + findFiberByHostInstance: getClosestInstanceFromNode,
150 + bundleType: __DEV__ ? 1 : 0,
151 + version: ReactVersion,
152 + rendererPackageName: 'react-dom',
153 +});
154 +
155 +if (__DEV__) {
156 + if (!foundDevTools && canUseDOM && window.top === window.self) {
157 + // If we're in Chrome or Firefox, provide a download link if not installed.
158 + if (
159 + (navigator.userAgent.indexOf('Chrome') > -1 &&
160 + navigator.userAgent.indexOf('Edge') === -1) ||
161 + navigator.userAgent.indexOf('Firefox') > -1
162 + ) {
163 + const protocol = window.location.protocol;
164 + // Don't warn in exotic cases like chrome-extension://.
165 + if (/^(https?|file):$/.test(protocol)) {
166 + // eslint-disable-next-line react-internal/no-production-logging
167 + console.info(
168 + '%cDownload the React DevTools ' +
169 + 'for a better development experience: ' +
170 + 'https://react.dev/link/react-devtools' +
171 + (protocol === 'file:'
172 + ? '\nYou might need to use a local HTTP server (instead of file://): ' +
173 + 'https://react.dev/link/react-devtools-faq'
174 + : ''),
175 + 'font-weight:bold',
176 + );
177 + }
178 + }
179 + }
180 +}
packages/react-dom/src/shared/ReactDOMFloat.js
+72 -58
@@ -15,8 +15,6 @@ import type {
15 } from './ReactDOMTypes';
16
17 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
18 -const ReactDOMCurrentDispatcher =
19 - ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
18
19 import {
20 getCrossOriginString,
@@ -49,7 +47,8 @@ export function prefetchDNS(href: string) {
47 }
48 }
49 if (typeof href === 'string') {
52 - ReactDOMCurrentDispatcher.current.prefetchDNS(href);
50 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
51 + .prefetchDNS(href);
52 }
53 // We don't error because preconnect needs to be resilient to being called in a variety of scopes
54 // and the runtime may not be capable of responding. The function is optimistic and not critical
@@ -79,7 +78,8 @@ export function preconnect(href: string, options?: ?PreconnectOptions) {
78 const crossOrigin = options
79 ? getCrossOriginString(options.crossOrigin)
80 : null;
82 - ReactDOMCurrentDispatcher.current.preconnect(href, crossOrigin);
81 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
82 + .preconnect(href, crossOrigin);
83 }
84 // We don't error because preconnect needs to be resilient to being called in a variety of scopes
85 // and the runtime may not be capable of responding. The function is optimistic and not critical
@@ -119,28 +119,31 @@ export function preload(href: string, options: PreloadOptions) {
119 ) {
120 const as = options.as;
121 const crossOrigin = getCrossOriginStringAs(as, options.crossOrigin);
122 - ReactDOMCurrentDispatcher.current.preload(href, as, {
123 - crossOrigin,
124 - integrity:
125 - typeof options.integrity === 'string' ? options.integrity : undefined,
126 - nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
127 - type: typeof options.type === 'string' ? options.type : undefined,
128 - fetchPriority:
129 - typeof options.fetchPriority === 'string'
130 - ? options.fetchPriority
131 - : undefined,
132 - referrerPolicy:
133 - typeof options.referrerPolicy === 'string'
134 - ? options.referrerPolicy
135 - : undefined,
136 - imageSrcSet:
137 - typeof options.imageSrcSet === 'string'
138 - ? options.imageSrcSet
139 - : undefined,
140 - imageSizes:
141 - typeof options.imageSizes === 'string' ? options.imageSizes : undefined,
142 - media: typeof options.media === 'string' ? options.media : undefined,
143 - });
122 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
123 + .preload(href, as, {
124 + crossOrigin,
125 + integrity:
126 + typeof options.integrity === 'string' ? options.integrity : undefined,
127 + nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
128 + type: typeof options.type === 'string' ? options.type : undefined,
129 + fetchPriority:
130 + typeof options.fetchPriority === 'string'
131 + ? options.fetchPriority
132 + : undefined,
133 + referrerPolicy:
134 + typeof options.referrerPolicy === 'string'
135 + ? options.referrerPolicy
136 + : undefined,
137 + imageSrcSet:
138 + typeof options.imageSrcSet === 'string'
139 + ? options.imageSrcSet
140 + : undefined,
141 + imageSizes:
142 + typeof options.imageSizes === 'string'
143 + ? options.imageSizes
144 + : undefined,
145 + media: typeof options.media === 'string' ? options.media : undefined,
146 + });
147 }
148 // We don't error because preload needs to be resilient to being called in a variety of scopes
149 // and the runtime may not be capable of responding. The function is optimistic and not critical
@@ -177,17 +180,21 @@ export function preloadModule(href: string, options?: ?PreloadModuleOptions) {
180 options.as,
181 options.crossOrigin,
182 );
180 - ReactDOMCurrentDispatcher.current.preloadModule(href, {
181 - as:
182 - typeof options.as === 'string' && options.as !== 'script'
183 - ? options.as
184 - : undefined,
185 - crossOrigin,
186 - integrity:
187 - typeof options.integrity === 'string' ? options.integrity : undefined,
188 - });
183 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
184 + .preloadModule(href, {
185 + as:
186 + typeof options.as === 'string' && options.as !== 'script'
187 + ? options.as
188 + : undefined,
189 + crossOrigin,
190 + integrity:
191 + typeof options.integrity === 'string'
192 + ? options.integrity
193 + : undefined,
194 + });
195 } else {
190 - ReactDOMCurrentDispatcher.current.preloadModule(href);
196 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
197 + .preloadModule(href);
198 }
199 }
200 // We don't error because preload needs to be resilient to being called in a variety of scopes
@@ -224,22 +231,26 @@ export function preinit(href: string, options: PreinitOptions) {
231 ? options.fetchPriority
232 : undefined;
233 if (as === 'style') {
227 - ReactDOMCurrentDispatcher.current.preinitStyle(
228 - href,
229 - typeof options.precedence === 'string' ? options.precedence : undefined,
230 - {
234 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
235 + .preinitStyle(
236 + href,
237 + typeof options.precedence === 'string'
238 + ? options.precedence
239 + : undefined,
240 + {
241 + crossOrigin,
242 + integrity,
243 + fetchPriority,
244 + },
245 + );
246 + } else if (as === 'script') {
247 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
248 + .preinitScript(href, {
249 crossOrigin,
250 integrity,
251 fetchPriority,
234 - },
235 - );
236 - } else if (as === 'script') {
237 - ReactDOMCurrentDispatcher.current.preinitScript(href, {
238 - crossOrigin,
239 - integrity,
240 - fetchPriority,
241 - nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
242 - });
252 + nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
253 + });
254 }
255 }
256 // We don't error because preinit needs to be resilient to being called in a variety of scopes
@@ -299,17 +310,20 @@ export function preinitModule(href: string, options?: ?PreinitModuleOptions) {
310 options.as,
311 options.crossOrigin,
312 );
302 - ReactDOMCurrentDispatcher.current.preinitModuleScript(href, {
303 - crossOrigin,
304 - integrity:
305 - typeof options.integrity === 'string'
306 - ? options.integrity
307 - : undefined,
308 - nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
309 - });
313 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
314 + .preinitModuleScript(href, {
315 + crossOrigin,
316 + integrity:
317 + typeof options.integrity === 'string'
318 + ? options.integrity
319 + : undefined,
320 + nonce:
321 + typeof options.nonce === 'string' ? options.nonce : undefined,
322 + });
323 }
324 } else if (options == null) {
312 - ReactDOMCurrentDispatcher.current.preinitModuleScript(href);
325 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
326 + .preinitModuleScript(href);
327 }
328 }
329 // We don't error because preinit needs to be resilient to being called in a variety of scopes
packages/react-dom/src/shared/ReactDOMFlushSync.js
+6 -6
@@ -17,19 +17,17 @@ const ReactCurrentBatchConfig: BatchConfig =
17 ReactSharedInternals.ReactCurrentBatchConfig;
18
19 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
20 -const ReactDOMCurrentDispatcher =
21 - ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
20
21 declare function flushSyncImpl<R>(fn: () => R): R;
22 declare function flushSyncImpl(void): void;
23 function flushSyncImpl<R>(fn: (() => R) | void): R | void {
24 const previousTransition = ReactCurrentBatchConfig.transition;
25 const previousUpdatePriority =
28 - ReactDOMSharedInternals.up; /* ReactDOMCurrentUpdatePriority */
26 + ReactDOMSharedInternals.p; /* ReactDOMCurrentUpdatePriority */
27
28 try {
29 ReactCurrentBatchConfig.transition = null;
32 - ReactDOMSharedInternals.up /* ReactDOMCurrentUpdatePriority */ =
30 + ReactDOMSharedInternals.p /* ReactDOMCurrentUpdatePriority */ =
31 DiscreteEventPriority;
32 if (fn) {
33 return fn();
@@ -38,9 +36,11 @@ function flushSyncImpl<R>(fn: (() => R) | void): R | void {
36 }
37 } finally {
38 ReactCurrentBatchConfig.transition = previousTransition;
41 - ReactDOMSharedInternals.up /* ReactDOMCurrentUpdatePriority */ =
39 + ReactDOMSharedInternals.p /* ReactDOMCurrentUpdatePriority */ =
40 previousUpdatePriority;
43 - const wasInRender = ReactDOMCurrentDispatcher.current.flushSyncWork();
41 + const wasInRender =
42 + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
43 + .flushSyncWork();
44 if (__DEV__) {
45 if (wasInRender) {
46 console.error(
scripts/rollup/forks.js
+9 -1
@@ -96,7 +96,15 @@ const forks = Object.freeze({
96 entry === 'react-dom/src/ReactDOMServer.js' ||
97 entry === 'react-dom/unstable_testing'
98 ) {
99 - return './packages/react-dom/src/ReactDOMSharedInternals.js';
99 + if (
100 + bundleType === FB_WWW_DEV ||
101 + bundleType === FB_WWW_PROD ||
102 + bundleType === FB_WWW_PROFILING
103 + ) {
104 + return './packages/react-dom/src/ReactDOMSharedInternalsFB.js';
105 + } else {
106 + return './packages/react-dom/src/ReactDOMSharedInternals.js';
107 + }
108 }
109 if (
110 !entry.startsWith('react-dom/') &&