Skip to content

Commit cc3ce99

Browse files
committed
Reduces the size of ReactDOMSharedIntenrals object representation to save on bundle size
1 parent b1c3da8 commit cc3ce99

File tree

11 files changed

+115
-108
lines changed

11 files changed

+115
-108
lines changed

packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ export function setCurrentUpdatePriority(
2525
// is much longer. I hope this is consistent enough to rely on across builds
2626
IntentionallyUnusedArgument?: empty,
2727
): void {
28-
ReactDOMSharedInternals.up = newPriority;
28+
ReactDOMSharedInternals.p /* currentUpdatePriority */ = newPriority;
2929
}
3030

3131
export function getCurrentUpdatePriority(): EventPriority {
32-
return ReactDOMSharedInternals.up;
32+
return ReactDOMSharedInternals.p; /* currentUpdatePriority */
3333
}
3434

3535
export function resolveUpdatePriority(): EventPriority {
36-
const updatePriority = ReactDOMSharedInternals.up;
36+
const updatePriority = ReactDOMSharedInternals.p; /* currentUpdatePriority */
3737
if (updatePriority !== NoEventPriority) {
3838
return updatePriority;
3939
}

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ import {validateLinkPropsForStyleResource} from '../shared/ReactDOMResourceValid
102102
import escapeSelectorAttributeValueInsideDoubleQuotes from './escapeSelectorAttributeValueInsideDoubleQuotes';
103103

104104
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
105-
const ReactDOMCurrentDispatcher =
106-
ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
107105

108106
export type Type = string;
109107
export type Props = {
@@ -1922,8 +1920,9 @@ function getDocumentFromRoot(root: HoistableRoot): Document {
19221920
return root.ownerDocument || root;
19231921
}
19241922

1925-
const previousDispatcher = ReactDOMCurrentDispatcher.current;
1926-
ReactDOMCurrentDispatcher.current = {
1923+
const previousDispatcher =
1924+
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
1925+
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
19271926
prefetchDNS,
19281927
preconnect,
19291928
preload,

packages/react-dom-bindings/src/server/ReactDOMFlightServerHostDispatcher.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import {
2323
} from 'react-server/src/ReactFlightServer';
2424

2525
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
26-
const ReactDOMCurrentDispatcher =
27-
ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
2826

29-
const previousDispatcher = ReactDOMCurrentDispatcher.current;
30-
ReactDOMCurrentDispatcher.current = {
27+
const previousDispatcher =
28+
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
29+
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
3130
prefetchDNS,
3231
preconnect,
3332
preload,

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ import {getValueDescriptorExpectingObjectForWarning} from '../shared/ReactDOMRes
8383
import {NotPending} from '../shared/ReactDOMFormActions';
8484

8585
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
86-
const ReactDOMCurrentDispatcher =
87-
ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
8886

89-
const previousDispatcher = ReactDOMCurrentDispatcher.current;
90-
ReactDOMCurrentDispatcher.current = {
87+
const previousDispatcher =
88+
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
89+
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
9190
prefetchDNS,
9291
preconnect,
9392
preload,

packages/react-dom-bindings/src/shared/ReactFlightClientConfigDOM.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
import type {HintCode, HintModel} from '../server/ReactFlightServerConfigDOM';
1414

1515
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
16-
const ReactDOMCurrentDispatcher =
17-
ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
1816

1917
import {getCrossOriginString} from './crossOriginStrings';
2018

2119
export function dispatchHint<Code: HintCode>(
2220
code: Code,
2321
model: HintModel<Code>,
2422
): void {
25-
const dispatcher = ReactDOMCurrentDispatcher.current;
23+
const dispatcher = ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
2624
switch (code) {
2725
case 'D': {
2826
const refined = refineModel(code, model);
@@ -117,19 +115,21 @@ export function preinitModuleForSSR(
117115
nonce: ?string,
118116
crossOrigin: ?string,
119117
) {
120-
ReactDOMCurrentDispatcher.current.preinitModuleScript(href, {
121-
crossOrigin: getCrossOriginString(crossOrigin),
122-
nonce,
123-
});
118+
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
119+
.preinitModuleScript(href, {
120+
crossOrigin: getCrossOriginString(crossOrigin),
121+
nonce,
122+
});
124123
}
125124

126125
export function preinitScriptForSSR(
127126
href: string,
128127
nonce: ?string,
129128
crossOrigin: ?string,
130129
) {
131-
ReactDOMCurrentDispatcher.current.preinitScript(href, {
132-
crossOrigin: getCrossOriginString(crossOrigin),
133-
nonce,
134-
});
130+
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
131+
.preinitScript(href, {
132+
crossOrigin: getCrossOriginString(crossOrigin),
133+
nonce,
134+
});
135135
}

packages/react-dom/client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export function createRoot(
2727
options?: CreateRootOptions,
2828
): RootType {
2929
if (__DEV__) {
30-
Internals.usingClientEntryPoint = true;
30+
Internals.c /* usingClientEntryPoint */ = true;
3131
}
3232
try {
3333
return createRootImpl(container, options);
3434
} finally {
3535
if (__DEV__) {
36-
Internals.usingClientEntryPoint = false;
36+
Internals.c /* usingClientEntryPoint */ = false;
3737
}
3838
}
3939
}
@@ -44,13 +44,13 @@ export function hydrateRoot(
4444
options?: HydrateRootOptions,
4545
): RootType {
4646
if (__DEV__) {
47-
Internals.usingClientEntryPoint = true;
47+
Internals.c /* usingClientEntryPoint */ = true;
4848
}
4949
try {
5050
return hydrateRootImpl(container, children, options);
5151
} finally {
5252
if (__DEV__) {
53-
Internals.usingClientEntryPoint = false;
53+
Internals.c /* usingClientEntryPoint */ = false;
5454
}
5555
}
5656
}

packages/react-dom/npm/client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ if (process.env.NODE_ENV === 'production') {
77
} else {
88
var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
99
exports.createRoot = function (c, o) {
10-
i.usingClientEntryPoint = true;
10+
i.c /* usingClientEntryPoint */ = true;
1111
try {
1212
return m.createRoot(c, o);
1313
} finally {
14-
i.usingClientEntryPoint = false;
14+
i.c /* usingClientEntryPoint */ = false;
1515
}
1616
};
1717
exports.hydrateRoot = function (c, h, o) {
18-
i.usingClientEntryPoint = true;
18+
i.c /* usingClientEntryPoint */ = true;
1919
try {
2020
return m.hydrateRoot(c, h, o);
2121
} finally {
22-
i.usingClientEntryPoint = false;
22+
i.c /* usingClientEntryPoint */ = false;
2323
}
2424
};
2525
}

packages/react-dom/src/ReactDOMSharedInternals.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ import type {HostDispatcher} from './shared/ReactDOMTypes';
1313
import {NoEventPriority} from 'react-reconciler/src/ReactEventPriorities';
1414

1515
type InternalsType = {
16-
usingClientEntryPoint: boolean,
17-
Events: [any, any, any, any, any, any],
18-
ReactDOMCurrentDispatcher: {
19-
current: HostDispatcher,
20-
},
16+
c /* usingClientEntryPoint */: boolean,
17+
E /* Events */: [any, any, any, any, any, any],
18+
d /* ReactDOMCurrentDispatcher */: HostDispatcher,
2119
findDOMNode:
2220
| null
2321
| ((
2422
componentOrElement: React$Component<any, any>,
2523
) => null | Element | Text),
26-
up /* currentUpdatePriority */: EventPriority,
24+
p /* currentUpdatePriority */: EventPriority,
2725
};
2826

2927
function noop() {}
@@ -39,13 +37,11 @@ const DefaultDispatcher: HostDispatcher = {
3937
};
4038

4139
const Internals: InternalsType = {
42-
usingClientEntryPoint: false,
43-
Events: (null: any),
44-
ReactDOMCurrentDispatcher: {
45-
current: DefaultDispatcher,
46-
},
40+
c /* usingClientEntryPoint */: false,
41+
E /* Events */: (null: any),
42+
d /* ReactDOMCurrentDispatcher */: DefaultDispatcher,
4743
findDOMNode: null,
48-
up /* currentUpdatePriority */: NoEventPriority,
44+
p /* currentUpdatePriority */: NoEventPriority,
4945
};
5046

5147
export default Internals;

packages/react-dom/src/client/ReactDOM.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function createRoot(
9595
options?: CreateRootOptions,
9696
): RootType {
9797
if (__DEV__) {
98-
if (!Internals.usingClientEntryPoint && !__UMD__) {
98+
if (!Internals.c /* usingClientEntryPoint */ && !__UMD__) {
9999
console.error(
100100
'You are importing createRoot from "react-dom" which is not supported. ' +
101101
'You should instead import it from "react-dom/client".',
@@ -111,7 +111,7 @@ function hydrateRoot(
111111
options?: HydrateRootOptions,
112112
): RootType {
113113
if (__DEV__) {
114-
if (!Internals.usingClientEntryPoint && !__UMD__) {
114+
if (!Internals.c /* usingClientEntryPoint */ && !__UMD__) {
115115
console.error(
116116
'You are importing hydrateRoot from "react-dom" which is not supported. ' +
117117
'You should instead import it from "react-dom/client".',
@@ -173,7 +173,7 @@ export {
173173

174174
// Keep in sync with ReactTestUtils.js.
175175
// This is an array for better minification.
176-
Internals.Events = [
176+
Internals.E /* Events */ = [
177177
getInstanceFromNode,
178178
getNodeFromInstance,
179179
getFiberCurrentPropsFromNode,

0 commit comments

Comments
 (0)