Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOM] Shrink ReactDOMCurrentDispatcher method names #28770

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1925,21 +1925,21 @@ function getDocumentFromRoot(root: HoistableRoot): Document {
const previousDispatcher =
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
flushSyncWork: disableLegacyMode
f /* flushSyncWork */: disableLegacyMode
? flushSyncWork
: previousDispatcher.flushSyncWork,
prefetchDNS,
preconnect,
preload,
preloadModule,
preinitStyle,
preinitScript,
preinitModuleScript,
: previousDispatcher.f /* flushSyncWork */,
D /* prefetchDNS */: prefetchDNS,
C /* preconnect */: preconnect,
L /* preload */: preload,
m /* preloadModule */: preloadModule,
X /* preinitScript */: preinitScript,
S /* preinitStyle */: preinitStyle,
M /* preinitModuleScript */: preinitModuleScript,
};

function flushSyncWork() {
if (disableLegacyMode) {
const previousWasRendering = previousDispatcher.flushSyncWork();
const previousWasRendering = previousDispatcher.f(); /* flushSyncWork */
const wasRendering = flushSyncWorkOnAllRoots();
// Since multiple dispatchers can flush sync work during a single flushSync call
// we need to return true if any of them were rendering.
Expand Down Expand Up @@ -1990,17 +1990,17 @@ function preconnectAs(
}

function prefetchDNS(href: string) {
previousDispatcher.prefetchDNS(href);
previousDispatcher.D(/* prefetchDNS */ href);
preconnectAs('dns-prefetch', href, null);
}

function preconnect(href: string, crossOrigin?: ?CrossOriginEnum) {
previousDispatcher.preconnect(href, crossOrigin);
previousDispatcher.C(/* preconnect */ href, crossOrigin);
preconnectAs('preconnect', href, crossOrigin);
}

function preload(href: string, as: string, options?: ?PreloadImplOptions) {
previousDispatcher.preload(href, as, options);
previousDispatcher.L(/* preload */ href, as, options);
const ownerDocument = getGlobalDocument();
if (ownerDocument && href && as) {
let preloadSelector = `link[rel="preload"][as="${escapeSelectorAttributeValueInsideDoubleQuotes(
Expand Down Expand Up @@ -2078,7 +2078,7 @@ function preload(href: string, as: string, options?: ?PreloadImplOptions) {
}

function preloadModule(href: string, options?: ?PreloadModuleImplOptions) {
previousDispatcher.preloadModule(href, options);
previousDispatcher.m(/* preloadModule */ href, options);
const ownerDocument = getGlobalDocument();
if (ownerDocument && href) {
const as =
Expand Down Expand Up @@ -2139,7 +2139,7 @@ function preinitStyle(
precedence: ?string,
options?: ?PreinitStyleOptions,
) {
previousDispatcher.preinitStyle(href, precedence, options);
previousDispatcher.S(/* preinitStyle */ href, precedence, options);

const ownerDocument = getGlobalDocument();
if (ownerDocument && href) {
Expand Down Expand Up @@ -2213,7 +2213,7 @@ function preinitStyle(
}

function preinitScript(src: string, options?: ?PreinitScriptOptions) {
previousDispatcher.preinitScript(src, options);
previousDispatcher.X(/* preinitScript */ src, options);

const ownerDocument = getGlobalDocument();
if (ownerDocument && src) {
Expand Down Expand Up @@ -2269,7 +2269,7 @@ function preinitModuleScript(
src: string,
options?: ?PreinitModuleScriptOptions,
) {
previousDispatcher.preinitModuleScript(src, options);
previousDispatcher.M(/* preinitModuleScript */ src, options);

const ownerDocument = getGlobalDocument();
if (ownerDocument && src) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
const previousDispatcher =
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
flushSyncWork: previousDispatcher.flushSyncWork,
prefetchDNS,
preconnect,
preload,
preloadModule,
preinitStyle,
preinitScript,
preinitModuleScript,
f /* flushSyncWork */: previousDispatcher.f /* flushSyncWork */,
D /* prefetchDNS */: prefetchDNS,
C /* preconnect */: preconnect,
L /* preload */: preload,
m /* preloadModule */: preloadModule,
X /* preinitScript */: preinitScript,
S /* preinitStyle */: preinitStyle,
M /* preinitModuleScript */: preinitModuleScript,
};

function prefetchDNS(href: string) {
Expand All @@ -50,7 +50,7 @@ function prefetchDNS(href: string) {
hints.add(key);
emitHint(request, 'D', href);
} else {
previousDispatcher.prefetchDNS(href);
previousDispatcher.D(/* prefetchDNS */ href);
}
}
}
Expand All @@ -73,7 +73,7 @@ function preconnect(href: string, crossOrigin?: ?CrossOriginEnum) {
emitHint(request, 'C', href);
}
} else {
previousDispatcher.preconnect(href, crossOrigin);
previousDispatcher.C(/* preconnect */ href, crossOrigin);
}
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ function preload(href: string, as: string, options?: ?PreloadImplOptions) {
emitHint(request, 'L', [href, as]);
}
} else {
previousDispatcher.preload(href, as, options);
previousDispatcher.L(/* preload */ href, as, options);
}
}
}
Expand All @@ -130,7 +130,7 @@ function preloadModule(href: string, options?: ?PreloadModuleImplOptions) {
return emitHint(request, 'm', href);
}
} else {
previousDispatcher.preloadModule(href, options);
previousDispatcher.m(/* preloadModule */ href, options);
}
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ function preinitStyle(
return emitHint(request, 'S', href);
}
} else {
previousDispatcher.preinitStyle(href, precedence, options);
previousDispatcher.S(/* preinitStyle */ href, precedence, options);
}
}
}
Expand All @@ -188,7 +188,7 @@ function preinitScript(src: string, options?: ?PreinitScriptOptions) {
return emitHint(request, 'X', src);
}
} else {
previousDispatcher.preinitScript(src, options);
previousDispatcher.X(/* preinitScript */ src, options);
}
}
}
Expand All @@ -215,7 +215,7 @@ function preinitModuleScript(
return emitHint(request, 'M', src);
}
} else {
previousDispatcher.preinitModuleScript(src, options);
previousDispatcher.M(/* preinitModuleScript */ src, options);
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
const previousDispatcher =
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
flushSyncWork: previousDispatcher.flushSyncWork,
prefetchDNS,
preconnect,
preload,
preloadModule,
preinitScript,
preinitStyle,
preinitModuleScript,
f /* flushSyncWork */: previousDispatcher.f /* flushSyncWork */,
D /* prefetchDNS */: prefetchDNS,
C /* preconnect */: preconnect,
L /* preload */: preload,
m /* preloadModule */: preloadModule,
X /* preinitScript */: preinitScript,
S /* preinitStyle */: preinitStyle,
M /* preinitModuleScript */: preinitModuleScript,
};

// We make every property of the descriptor optional because it is not a contract that
Expand Down Expand Up @@ -5266,7 +5266,7 @@ function prefetchDNS(href: string) {
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.prefetchDNS(href);
previousDispatcher.D(/* prefetchDNS */ href);
return;
}
const resumableState = getResumableState(request);
Expand Down Expand Up @@ -5319,7 +5319,7 @@ function preconnect(href: string, crossOrigin: ?CrossOriginEnum) {
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.preconnect(href, crossOrigin);
previousDispatcher.C(/* preconnect */ href, crossOrigin);
return;
}
const resumableState = getResumableState(request);
Expand Down Expand Up @@ -5380,7 +5380,7 @@ function preload(href: string, as: string, options?: ?PreloadImplOptions) {
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.preload(href, as, options);
previousDispatcher.L(/* preload */ href, as, options);
return;
}
const resumableState = getResumableState(request);
Expand Down Expand Up @@ -5581,7 +5581,7 @@ function preloadModule(
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.preloadModule(href, options);
previousDispatcher.m(/* preloadModule */ href, options);
return;
}
const resumableState = getResumableState(request);
Expand Down Expand Up @@ -5655,7 +5655,7 @@ function preinitStyle(
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.preinitStyle(href, precedence, options);
previousDispatcher.S(/* preinitStyle */ href, precedence, options);
return;
}
const resumableState = getResumableState(request);
Expand Down Expand Up @@ -5740,7 +5740,7 @@ function preinitScript(src: string, options?: ?PreinitScriptOptions): void {
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.preinitScript(src, options);
previousDispatcher.X(/* preinitScript */ src, options);
return;
}
const resumableState = getResumableState(request);
Expand Down Expand Up @@ -5803,7 +5803,7 @@ function preinitModuleScript(
// the resources for this call in either case we opt to do nothing. We can consider making this a warning
// but there may be times where calling a function outside of render is intentional (i.e. to warm up data
// fetching) and we don't want to warn in those cases.
previousDispatcher.preinitModuleScript(src, options);
previousDispatcher.M(/* preinitModuleScript */ src, options);
return;
}
const resumableState = getResumableState(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export function dispatchHint<Code: HintCode>(
case 'D': {
const refined = refineModel(code, model);
const href = refined;
dispatcher.prefetchDNS(href);
dispatcher.D(/* prefetchDNS */ href);
return;
}
case 'C': {
const refined = refineModel(code, model);
if (typeof refined === 'string') {
const href = refined;
dispatcher.preconnect(href);
dispatcher.C(/* preconnect */ href);
} else {
const href = refined[0];
const crossOrigin = refined[1];
dispatcher.preconnect(href, crossOrigin);
dispatcher.C(/* preconnect */ href, crossOrigin);
}
return;
}
Expand All @@ -46,58 +46,58 @@ export function dispatchHint<Code: HintCode>(
const as = refined[1];
if (refined.length === 3) {
const options = refined[2];
dispatcher.preload(href, as, options);
dispatcher.L(/* preload */ href, as, options);
} else {
dispatcher.preload(href, as);
dispatcher.L(/* preload */ href, as);
}
return;
}
case 'm': {
const refined = refineModel(code, model);
if (typeof refined === 'string') {
const href = refined;
dispatcher.preloadModule(href);
dispatcher.m(/* preloadModule */ href);
} else {
const href = refined[0];
const options = refined[1];
dispatcher.preloadModule(href, options);
dispatcher.m(/* preloadModule */ href, options);
}
return;
}
case 'S': {
case 'X': {
const refined = refineModel(code, model);
if (typeof refined === 'string') {
const href = refined;
dispatcher.preinitStyle(href);
dispatcher.X(/* preinitScript */ href);
} else {
const href = refined[0];
const precedence = refined[1] === 0 ? undefined : refined[1];
const options = refined.length === 3 ? refined[2] : undefined;
dispatcher.preinitStyle(href, precedence, options);
const options = refined[1];
dispatcher.X(/* preinitScript */ href, options);
}
return;
}
case 'X': {
case 'S': {
const refined = refineModel(code, model);
if (typeof refined === 'string') {
const href = refined;
dispatcher.preinitScript(href);
dispatcher.S(/* preinitStyle */ href);
} else {
const href = refined[0];
const options = refined[1];
dispatcher.preinitScript(href, options);
const precedence = refined[1] === 0 ? undefined : refined[1];
const options = refined.length === 3 ? refined[2] : undefined;
dispatcher.S(/* preinitStyle */ href, precedence, options);
}
return;
}
case 'M': {
const refined = refineModel(code, model);
if (typeof refined === 'string') {
const href = refined;
dispatcher.preinitModuleScript(href);
dispatcher.M(/* preinitModuleScript */ href);
} else {
const href = refined[0];
const options = refined[1];
dispatcher.preinitModuleScript(href, options);
dispatcher.M(/* preinitModuleScript */ href, options);
}
return;
}
Expand All @@ -116,7 +116,7 @@ export function preinitModuleForSSR(
crossOrigin: ?string,
) {
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
.preinitModuleScript(href, {
.M(/* preinitModuleScript */ href, {
crossOrigin: getCrossOriginString(crossOrigin),
nonce,
});
Expand All @@ -128,7 +128,7 @@ export function preinitScriptForSSR(
crossOrigin: ?string,
) {
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
.preinitScript(href, {
.X(/* preinitScript */ href, {
crossOrigin: getCrossOriginString(crossOrigin),
nonce,
});
Expand Down
16 changes: 8 additions & 8 deletions packages/react-dom/src/ReactDOMSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export type ReactDOMInternalsDev = ReactDOMInternals & {
function noop() {}

const DefaultDispatcher: HostDispatcher = {
flushSyncWork: noop,
prefetchDNS: noop,
preconnect: noop,
preload: noop,
preloadModule: noop,
preinitScript: noop,
preinitStyle: noop,
preinitModuleScript: noop,
f /* flushSyncWork */: noop,
D /* prefetchDNS */: noop,
C /* preconnect */: noop,
L /* preload */: noop,
m /* preloadModule */: noop,
X /* preinitScript */: noop,
S /* preinitStyle */: noop,
M /* preinitModuleScript */: noop,
};

const Internals: ReactDOMInternals = {
Expand Down
Loading