Skip to content

Commit

Permalink
[DOM] Shrink ReactDOMSharedInternals source representation (#28771)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gnoff committed Apr 8, 2024
1 parent d1d30ea commit 9ea88c8
Show file tree
Hide file tree
Showing 21 changed files with 1,273 additions and 1,042 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14f50ad1554f0adf20fa1b5bc62859ed32be0bc6
9007fdc8f103a5d9247be384791496db9a3be91d
226 changes: 126 additions & 100 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3034,15 +3034,14 @@ if (__DEV__) {
preinitModuleScript: noop$3
};
var Internals = {
usingClientEntryPoint: false,
Events: null,
ReactDOMCurrentDispatcher: {
current: DefaultDispatcher
},
findDOMNode: null,
up:
d:
/* ReactDOMCurrentDispatcher */
DefaultDispatcher,
p:
/* currentUpdatePriority */
NoEventPriority
NoEventPriority,
findDOMNode: null
};

function setCurrentUpdatePriority(
Expand All @@ -3052,13 +3051,17 @@ if (__DEV__) {
// is much longer. I hope this is consistent enough to rely on across builds
IntentionallyUnusedArgument
) {
Internals.up = newPriority;
Internals.p =
/* currentUpdatePriority */
newPriority;
}
function getCurrentUpdatePriority() {
return Internals.up;
return Internals.p;
/* currentUpdatePriority */
}
function resolveUpdatePriority() {
var updatePriority = Internals.up;
var updatePriority = Internals.p;
/* currentUpdatePriority */

if (updatePriority !== NoEventPriority) {
return updatePriority;
Expand Down Expand Up @@ -36159,7 +36162,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "19.0.0-www-classic-a72c7db8";
var ReactVersion = "19.0.0-www-classic-393dd949";

function createPortal$1(
children,
Expand Down Expand Up @@ -44179,8 +44182,6 @@ if (__DEV__) {
}
}

var ReactDOMCurrentDispatcher$1 = Internals.ReactDOMCurrentDispatcher; // Unused

var SUPPRESS_HYDRATION_WARNING = "suppressHydrationWarning";
var SUSPENSE_START_DATA = "$";
var SUSPENSE_END_DATA = "/$";
Expand Down Expand Up @@ -45599,17 +45600,21 @@ if (__DEV__) {
return root.ownerDocument || root;
}

var previousDispatcher = ReactDOMCurrentDispatcher$1.current;
ReactDOMCurrentDispatcher$1.current = {
flushSyncWork: previousDispatcher.flushSyncWork,
prefetchDNS: prefetchDNS$1,
preconnect: preconnect$1,
preload: preload$1,
preloadModule: preloadModule$1,
preinitStyle: preinitStyle,
preinitScript: preinitScript,
preinitModuleScript: preinitModuleScript
};
var previousDispatcher = Internals.d;
/* ReactDOMCurrentDispatcher */

Internals.d =
/* ReactDOMCurrentDispatcher */
{
flushSyncWork: previousDispatcher.flushSyncWork,
prefetchDNS: prefetchDNS$1,
preconnect: preconnect$1,
preload: preload$1,
preloadModule: preloadModule$1,
preinitStyle: preinitStyle,
preinitScript: preinitScript,
preinitModuleScript: preinitModuleScript
};
// how we resolve the HoistableRoot for ReactDOM.pre*() methods. Because we support calling
// these methods outside of render there is no way to know which Document or ShadowRoot is 'scoped'
// and so we have to fall back to something universal. Currently we just refer to the global document.
Expand Down Expand Up @@ -48675,7 +48680,6 @@ if (__DEV__) {
return undefined;
}

var ReactDOMCurrentDispatcher = Internals.ReactDOMCurrentDispatcher;
function prefetchDNS(href) {
{
if (typeof href !== "string" || !href) {
Expand Down Expand Up @@ -48704,7 +48708,9 @@ if (__DEV__) {
}

if (typeof href === "string") {
ReactDOMCurrentDispatcher.current.prefetchDNS(href);
Internals.d
/* ReactDOMCurrentDispatcher */
.prefetchDNS(href);
} // We don't error because preconnect needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
// so we favor silent bailout over warning or erroring.
Expand Down Expand Up @@ -48733,7 +48739,9 @@ if (__DEV__) {
var crossOrigin = options
? getCrossOriginString(options.crossOrigin)
: null;
ReactDOMCurrentDispatcher.current.preconnect(href, crossOrigin);
Internals.d
/* ReactDOMCurrentDispatcher */
.preconnect(href, crossOrigin);
} // We don't error because preconnect needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
// so we favor silent bailout over warning or erroring.
Expand Down Expand Up @@ -48777,32 +48785,35 @@ if (__DEV__) {
) {
var as = options.as;
var crossOrigin = getCrossOriginStringAs(as, options.crossOrigin);
ReactDOMCurrentDispatcher.current.preload(href, as, {
crossOrigin: crossOrigin,
integrity:
typeof options.integrity === "string"
? options.integrity
: undefined,
nonce: typeof options.nonce === "string" ? options.nonce : undefined,
type: typeof options.type === "string" ? options.type : undefined,
fetchPriority:
typeof options.fetchPriority === "string"
? options.fetchPriority
: undefined,
referrerPolicy:
typeof options.referrerPolicy === "string"
? options.referrerPolicy
: undefined,
imageSrcSet:
typeof options.imageSrcSet === "string"
? options.imageSrcSet
: undefined,
imageSizes:
typeof options.imageSizes === "string"
? options.imageSizes
: undefined,
media: typeof options.media === "string" ? options.media : undefined
});
Internals.d
/* ReactDOMCurrentDispatcher */
.preload(href, as, {
crossOrigin: crossOrigin,
integrity:
typeof options.integrity === "string"
? options.integrity
: undefined,
nonce:
typeof options.nonce === "string" ? options.nonce : undefined,
type: typeof options.type === "string" ? options.type : undefined,
fetchPriority:
typeof options.fetchPriority === "string"
? options.fetchPriority
: undefined,
referrerPolicy:
typeof options.referrerPolicy === "string"
? options.referrerPolicy
: undefined,
imageSrcSet:
typeof options.imageSrcSet === "string"
? options.imageSrcSet
: undefined,
imageSizes:
typeof options.imageSizes === "string"
? options.imageSizes
: undefined,
media: typeof options.media === "string" ? options.media : undefined
});
} // We don't error because preload needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
// so we favor silent bailout over warning or erroring.
Expand Down Expand Up @@ -48848,19 +48859,23 @@ if (__DEV__) {
options.as,
options.crossOrigin
);
ReactDOMCurrentDispatcher.current.preloadModule(href, {
as:
typeof options.as === "string" && options.as !== "script"
? options.as
: undefined,
crossOrigin: crossOrigin,
integrity:
typeof options.integrity === "string"
? options.integrity
: undefined
});
Internals.d
/* ReactDOMCurrentDispatcher */
.preloadModule(href, {
as:
typeof options.as === "string" && options.as !== "script"
? options.as
: undefined,
crossOrigin: crossOrigin,
integrity:
typeof options.integrity === "string"
? options.integrity
: undefined
});
} else {
ReactDOMCurrentDispatcher.current.preloadModule(href);
Internals.d
/* ReactDOMCurrentDispatcher */
.preloadModule(href);
}
} // We don't error because preload needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
Expand Down Expand Up @@ -48901,24 +48916,29 @@ if (__DEV__) {
: undefined;

if (as === "style") {
ReactDOMCurrentDispatcher.current.preinitStyle(
href,
typeof options.precedence === "string"
? options.precedence
: undefined,
{
Internals.d
/* ReactDOMCurrentDispatcher */
.preinitStyle(
href,
typeof options.precedence === "string"
? options.precedence
: undefined,
{
crossOrigin: crossOrigin,
integrity: integrity,
fetchPriority: fetchPriority
}
);
} else if (as === "script") {
Internals.d
/* ReactDOMCurrentDispatcher */
.preinitScript(href, {
crossOrigin: crossOrigin,
integrity: integrity,
fetchPriority: fetchPriority
}
);
} else if (as === "script") {
ReactDOMCurrentDispatcher.current.preinitScript(href, {
crossOrigin: crossOrigin,
integrity: integrity,
fetchPriority: fetchPriority,
nonce: typeof options.nonce === "string" ? options.nonce : undefined
});
fetchPriority: fetchPriority,
nonce:
typeof options.nonce === "string" ? options.nonce : undefined
});
}
} // We don't error because preinit needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
Expand Down Expand Up @@ -48985,18 +49005,22 @@ if (__DEV__) {
options.as,
options.crossOrigin
);
ReactDOMCurrentDispatcher.current.preinitModuleScript(href, {
crossOrigin: crossOrigin,
integrity:
typeof options.integrity === "string"
? options.integrity
: undefined,
nonce:
typeof options.nonce === "string" ? options.nonce : undefined
});
Internals.d
/* ReactDOMCurrentDispatcher */
.preinitModuleScript(href, {
crossOrigin: crossOrigin,
integrity:
typeof options.integrity === "string"
? options.integrity
: undefined,
nonce:
typeof options.nonce === "string" ? options.nonce : undefined
});
}
} else if (options == null) {
ReactDOMCurrentDispatcher.current.preinitModuleScript(href);
Internals.d
/* ReactDOMCurrentDispatcher */
.preinitModuleScript(href);
}
} // We don't error because preinit needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
Expand Down Expand Up @@ -49056,7 +49080,7 @@ if (__DEV__) {
// $FlowFixMe[incompatible-return] The Flow type is opaque but there's no way to actually create it.

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

Internals.Events = [
getInstanceFromNode,
getNodeFromInstance,
getFiberCurrentPropsFromNode,
enqueueStateRestore,
restoreStateIfNeeded,
unstable_batchedUpdates
];
Internals.Events =
/* Events */
[
getInstanceFromNode,
getNodeFromInstance,
getFiberCurrentPropsFromNode,
enqueueStateRestore,
restoreStateIfNeeded,
unstable_batchedUpdates
];
var foundDevTools = injectIntoDevTools({
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 1,
Expand Down
Loading

0 comments on commit 9ea88c8

Please sign in to comment.