Skip to content

Commit

Permalink
Shortens the names of host dispatcher methods to save bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Apr 5, 2024
1 parent cc3ce99 commit b3c8140
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 85 deletions.
28 changes: 14 additions & 14 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1923,13 +1923,13 @@ function getDocumentFromRoot(root: HoistableRoot): Document {
const previousDispatcher =
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
prefetchDNS,
preconnect,
preload,
preloadModule,
preinitStyle,
preinitScript,
preinitModuleScript,
D /* prefetchDNS */: prefetchDNS,
C /* preconnect */: preconnect,
L /* preload */: preload,
m /* preloadModule */: preloadModule,
X /* preinitScript */: preinitScript,
S /* preinitStyle */: preinitStyle,
M /* preinitModuleScript */: preinitModuleScript,
};

// We expect this to get inlined. It is a function mostly to communicate the special nature of
Expand Down Expand Up @@ -1971,17 +1971,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 @@ -2059,7 +2059,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 @@ -2120,7 +2120,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 @@ -2194,7 +2194,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 @@ -2250,7 +2250,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,13 +27,13 @@ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
const previousDispatcher =
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
prefetchDNS,
preconnect,
preload,
preloadModule,
preinitStyle,
preinitScript,
preinitModuleScript,
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 @@ -49,7 +49,7 @@ function prefetchDNS(href: string) {
hints.add(key);
emitHint(request, 'D', href);
} else {
previousDispatcher.prefetchDNS(href);
previousDispatcher.D(/* prefetchDNS */ href);
}
}
}
Expand All @@ -72,7 +72,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 @@ -105,7 +105,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 @@ -129,7 +129,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 @@ -163,7 +163,7 @@ function preinitStyle(
return emitHint(request, 'S', href);
}
} else {
previousDispatcher.preinitStyle(href, precedence, options);
previousDispatcher.S(/* preinitStyle */ href, precedence, options);
}
}
}
Expand All @@ -187,7 +187,7 @@ function preinitScript(src: string, options?: ?PreinitScriptOptions) {
return emitHint(request, 'X', src);
}
} else {
previousDispatcher.preinitScript(src, options);
previousDispatcher.X(/* preinitScript */ src, options);
}
}
}
Expand All @@ -214,7 +214,7 @@ function preinitModuleScript(
return emitHint(request, 'M', src);
}
} else {
previousDispatcher.preinitModuleScript(src, options);
previousDispatcher.M(/* preinitModuleScript */ src, options);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
const previousDispatcher =
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
prefetchDNS,
preconnect,
preload,
preloadModule,
preinitScript,
preinitStyle,
preinitModuleScript,
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 @@ -5265,7 +5265,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 @@ -5318,7 +5318,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 @@ -5379,7 +5379,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 @@ -5580,7 +5580,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 @@ -5654,7 +5654,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 @@ -5739,7 +5739,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 @@ -5802,7 +5802,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
14 changes: 7 additions & 7 deletions packages/react-dom/src/ReactDOMSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ type InternalsType = {
function noop() {}

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

const Internals: InternalsType = {
Expand Down
Loading

0 comments on commit b3c8140

Please sign in to comment.