Skip to content

Commit 9ea88c8

Browse files
committed
[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 DiffTrain build for [9007fdc](9007fdc)
1 parent d1d30ea commit 9ea88c8

21 files changed

+1273
-1042
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14f50ad1554f0adf20fa1b5bc62859ed32be0bc6
1+
9007fdc8f103a5d9247be384791496db9a3be91d

compiled/facebook-www/ReactDOM-dev.classic.js

Lines changed: 126 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,15 +3034,14 @@ if (__DEV__) {
30343034
preinitModuleScript: noop$3
30353035
};
30363036
var Internals = {
3037-
usingClientEntryPoint: false,
30383037
Events: null,
3039-
ReactDOMCurrentDispatcher: {
3040-
current: DefaultDispatcher
3041-
},
3042-
findDOMNode: null,
3043-
up:
3038+
d:
3039+
/* ReactDOMCurrentDispatcher */
3040+
DefaultDispatcher,
3041+
p:
30443042
/* currentUpdatePriority */
3045-
NoEventPriority
3043+
NoEventPriority,
3044+
findDOMNode: null
30463045
};
30473046

30483047
function setCurrentUpdatePriority(
@@ -3052,13 +3051,17 @@ if (__DEV__) {
30523051
// is much longer. I hope this is consistent enough to rely on across builds
30533052
IntentionallyUnusedArgument
30543053
) {
3055-
Internals.up = newPriority;
3054+
Internals.p =
3055+
/* currentUpdatePriority */
3056+
newPriority;
30563057
}
30573058
function getCurrentUpdatePriority() {
3058-
return Internals.up;
3059+
return Internals.p;
3060+
/* currentUpdatePriority */
30593061
}
30603062
function resolveUpdatePriority() {
3061-
var updatePriority = Internals.up;
3063+
var updatePriority = Internals.p;
3064+
/* currentUpdatePriority */
30623065

30633066
if (updatePriority !== NoEventPriority) {
30643067
return updatePriority;
@@ -36159,7 +36162,7 @@ if (__DEV__) {
3615936162
return root;
3616036163
}
3616136164

36162-
var ReactVersion = "19.0.0-www-classic-a72c7db8";
36165+
var ReactVersion = "19.0.0-www-classic-393dd949";
3616336166

3616436167
function createPortal$1(
3616536168
children,
@@ -44179,8 +44182,6 @@ if (__DEV__) {
4417944182
}
4418044183
}
4418144184

44182-
var ReactDOMCurrentDispatcher$1 = Internals.ReactDOMCurrentDispatcher; // Unused
44183-
4418444185
var SUPPRESS_HYDRATION_WARNING = "suppressHydrationWarning";
4418544186
var SUSPENSE_START_DATA = "$";
4418644187
var SUSPENSE_END_DATA = "/$";
@@ -45599,17 +45600,21 @@ if (__DEV__) {
4559945600
return root.ownerDocument || root;
4560045601
}
4560145602

45602-
var previousDispatcher = ReactDOMCurrentDispatcher$1.current;
45603-
ReactDOMCurrentDispatcher$1.current = {
45604-
flushSyncWork: previousDispatcher.flushSyncWork,
45605-
prefetchDNS: prefetchDNS$1,
45606-
preconnect: preconnect$1,
45607-
preload: preload$1,
45608-
preloadModule: preloadModule$1,
45609-
preinitStyle: preinitStyle,
45610-
preinitScript: preinitScript,
45611-
preinitModuleScript: preinitModuleScript
45612-
};
45603+
var previousDispatcher = Internals.d;
45604+
/* ReactDOMCurrentDispatcher */
45605+
45606+
Internals.d =
45607+
/* ReactDOMCurrentDispatcher */
45608+
{
45609+
flushSyncWork: previousDispatcher.flushSyncWork,
45610+
prefetchDNS: prefetchDNS$1,
45611+
preconnect: preconnect$1,
45612+
preload: preload$1,
45613+
preloadModule: preloadModule$1,
45614+
preinitStyle: preinitStyle,
45615+
preinitScript: preinitScript,
45616+
preinitModuleScript: preinitModuleScript
45617+
};
4561345618
// how we resolve the HoistableRoot for ReactDOM.pre*() methods. Because we support calling
4561445619
// these methods outside of render there is no way to know which Document or ShadowRoot is 'scoped'
4561545620
// and so we have to fall back to something universal. Currently we just refer to the global document.
@@ -48675,7 +48680,6 @@ if (__DEV__) {
4867548680
return undefined;
4867648681
}
4867748682

48678-
var ReactDOMCurrentDispatcher = Internals.ReactDOMCurrentDispatcher;
4867948683
function prefetchDNS(href) {
4868048684
{
4868148685
if (typeof href !== "string" || !href) {
@@ -48704,7 +48708,9 @@ if (__DEV__) {
4870448708
}
4870548709

4870648710
if (typeof href === "string") {
48707-
ReactDOMCurrentDispatcher.current.prefetchDNS(href);
48711+
Internals.d
48712+
/* ReactDOMCurrentDispatcher */
48713+
.prefetchDNS(href);
4870848714
} // We don't error because preconnect needs to be resilient to being called in a variety of scopes
4870948715
// and the runtime may not be capable of responding. The function is optimistic and not critical
4871048716
// so we favor silent bailout over warning or erroring.
@@ -48733,7 +48739,9 @@ if (__DEV__) {
4873348739
var crossOrigin = options
4873448740
? getCrossOriginString(options.crossOrigin)
4873548741
: null;
48736-
ReactDOMCurrentDispatcher.current.preconnect(href, crossOrigin);
48742+
Internals.d
48743+
/* ReactDOMCurrentDispatcher */
48744+
.preconnect(href, crossOrigin);
4873748745
} // We don't error because preconnect needs to be resilient to being called in a variety of scopes
4873848746
// and the runtime may not be capable of responding. The function is optimistic and not critical
4873948747
// so we favor silent bailout over warning or erroring.
@@ -48777,32 +48785,35 @@ if (__DEV__) {
4877748785
) {
4877848786
var as = options.as;
4877948787
var crossOrigin = getCrossOriginStringAs(as, options.crossOrigin);
48780-
ReactDOMCurrentDispatcher.current.preload(href, as, {
48781-
crossOrigin: crossOrigin,
48782-
integrity:
48783-
typeof options.integrity === "string"
48784-
? options.integrity
48785-
: undefined,
48786-
nonce: typeof options.nonce === "string" ? options.nonce : undefined,
48787-
type: typeof options.type === "string" ? options.type : undefined,
48788-
fetchPriority:
48789-
typeof options.fetchPriority === "string"
48790-
? options.fetchPriority
48791-
: undefined,
48792-
referrerPolicy:
48793-
typeof options.referrerPolicy === "string"
48794-
? options.referrerPolicy
48795-
: undefined,
48796-
imageSrcSet:
48797-
typeof options.imageSrcSet === "string"
48798-
? options.imageSrcSet
48799-
: undefined,
48800-
imageSizes:
48801-
typeof options.imageSizes === "string"
48802-
? options.imageSizes
48803-
: undefined,
48804-
media: typeof options.media === "string" ? options.media : undefined
48805-
});
48788+
Internals.d
48789+
/* ReactDOMCurrentDispatcher */
48790+
.preload(href, as, {
48791+
crossOrigin: crossOrigin,
48792+
integrity:
48793+
typeof options.integrity === "string"
48794+
? options.integrity
48795+
: undefined,
48796+
nonce:
48797+
typeof options.nonce === "string" ? options.nonce : undefined,
48798+
type: typeof options.type === "string" ? options.type : undefined,
48799+
fetchPriority:
48800+
typeof options.fetchPriority === "string"
48801+
? options.fetchPriority
48802+
: undefined,
48803+
referrerPolicy:
48804+
typeof options.referrerPolicy === "string"
48805+
? options.referrerPolicy
48806+
: undefined,
48807+
imageSrcSet:
48808+
typeof options.imageSrcSet === "string"
48809+
? options.imageSrcSet
48810+
: undefined,
48811+
imageSizes:
48812+
typeof options.imageSizes === "string"
48813+
? options.imageSizes
48814+
: undefined,
48815+
media: typeof options.media === "string" ? options.media : undefined
48816+
});
4880648817
} // We don't error because preload needs to be resilient to being called in a variety of scopes
4880748818
// and the runtime may not be capable of responding. The function is optimistic and not critical
4880848819
// so we favor silent bailout over warning or erroring.
@@ -48848,19 +48859,23 @@ if (__DEV__) {
4884848859
options.as,
4884948860
options.crossOrigin
4885048861
);
48851-
ReactDOMCurrentDispatcher.current.preloadModule(href, {
48852-
as:
48853-
typeof options.as === "string" && options.as !== "script"
48854-
? options.as
48855-
: undefined,
48856-
crossOrigin: crossOrigin,
48857-
integrity:
48858-
typeof options.integrity === "string"
48859-
? options.integrity
48860-
: undefined
48861-
});
48862+
Internals.d
48863+
/* ReactDOMCurrentDispatcher */
48864+
.preloadModule(href, {
48865+
as:
48866+
typeof options.as === "string" && options.as !== "script"
48867+
? options.as
48868+
: undefined,
48869+
crossOrigin: crossOrigin,
48870+
integrity:
48871+
typeof options.integrity === "string"
48872+
? options.integrity
48873+
: undefined
48874+
});
4886248875
} else {
48863-
ReactDOMCurrentDispatcher.current.preloadModule(href);
48876+
Internals.d
48877+
/* ReactDOMCurrentDispatcher */
48878+
.preloadModule(href);
4886448879
}
4886548880
} // We don't error because preload needs to be resilient to being called in a variety of scopes
4886648881
// and the runtime may not be capable of responding. The function is optimistic and not critical
@@ -48901,24 +48916,29 @@ if (__DEV__) {
4890148916
: undefined;
4890248917

4890348918
if (as === "style") {
48904-
ReactDOMCurrentDispatcher.current.preinitStyle(
48905-
href,
48906-
typeof options.precedence === "string"
48907-
? options.precedence
48908-
: undefined,
48909-
{
48919+
Internals.d
48920+
/* ReactDOMCurrentDispatcher */
48921+
.preinitStyle(
48922+
href,
48923+
typeof options.precedence === "string"
48924+
? options.precedence
48925+
: undefined,
48926+
{
48927+
crossOrigin: crossOrigin,
48928+
integrity: integrity,
48929+
fetchPriority: fetchPriority
48930+
}
48931+
);
48932+
} else if (as === "script") {
48933+
Internals.d
48934+
/* ReactDOMCurrentDispatcher */
48935+
.preinitScript(href, {
4891048936
crossOrigin: crossOrigin,
4891148937
integrity: integrity,
48912-
fetchPriority: fetchPriority
48913-
}
48914-
);
48915-
} else if (as === "script") {
48916-
ReactDOMCurrentDispatcher.current.preinitScript(href, {
48917-
crossOrigin: crossOrigin,
48918-
integrity: integrity,
48919-
fetchPriority: fetchPriority,
48920-
nonce: typeof options.nonce === "string" ? options.nonce : undefined
48921-
});
48938+
fetchPriority: fetchPriority,
48939+
nonce:
48940+
typeof options.nonce === "string" ? options.nonce : undefined
48941+
});
4892248942
}
4892348943
} // We don't error because preinit needs to be resilient to being called in a variety of scopes
4892448944
// and the runtime may not be capable of responding. The function is optimistic and not critical
@@ -48985,18 +49005,22 @@ if (__DEV__) {
4898549005
options.as,
4898649006
options.crossOrigin
4898749007
);
48988-
ReactDOMCurrentDispatcher.current.preinitModuleScript(href, {
48989-
crossOrigin: crossOrigin,
48990-
integrity:
48991-
typeof options.integrity === "string"
48992-
? options.integrity
48993-
: undefined,
48994-
nonce:
48995-
typeof options.nonce === "string" ? options.nonce : undefined
48996-
});
49008+
Internals.d
49009+
/* ReactDOMCurrentDispatcher */
49010+
.preinitModuleScript(href, {
49011+
crossOrigin: crossOrigin,
49012+
integrity:
49013+
typeof options.integrity === "string"
49014+
? options.integrity
49015+
: undefined,
49016+
nonce:
49017+
typeof options.nonce === "string" ? options.nonce : undefined
49018+
});
4899749019
}
4899849020
} else if (options == null) {
48999-
ReactDOMCurrentDispatcher.current.preinitModuleScript(href);
49021+
Internals.d
49022+
/* ReactDOMCurrentDispatcher */
49023+
.preinitModuleScript(href);
4900049024
}
4900149025
} // We don't error because preinit needs to be resilient to being called in a variety of scopes
4900249026
// and the runtime may not be capable of responding. The function is optimistic and not critical
@@ -49056,7 +49080,7 @@ if (__DEV__) {
4905649080
// $FlowFixMe[incompatible-return] The Flow type is opaque but there's no way to actually create it.
4905749081

4905849082
return createPortal$1(children, container, null, key);
49059-
}
49083+
} // Overload the definition to the two valid signatures.
4906049084
// Warning, this opts-out of checking the function body.
4906149085
// eslint-disable-next-line no-redeclare
4906249086
// eslint-disable-next-line no-redeclare
@@ -49091,14 +49115,16 @@ if (__DEV__) {
4909149115
}
4909249116
// This is an array for better minification.
4909349117

49094-
Internals.Events = [
49095-
getInstanceFromNode,
49096-
getNodeFromInstance,
49097-
getFiberCurrentPropsFromNode,
49098-
enqueueStateRestore,
49099-
restoreStateIfNeeded,
49100-
unstable_batchedUpdates
49101-
];
49118+
Internals.Events =
49119+
/* Events */
49120+
[
49121+
getInstanceFromNode,
49122+
getNodeFromInstance,
49123+
getFiberCurrentPropsFromNode,
49124+
enqueueStateRestore,
49125+
restoreStateIfNeeded,
49126+
unstable_batchedUpdates
49127+
];
4910249128
var foundDevTools = injectIntoDevTools({
4910349129
findFiberByHostInstance: getClosestInstanceFromNode,
4910449130
bundleType: 1,

0 commit comments

Comments
 (0)