Skip to content

Commit 81e2051

Browse files
committed
[Float][Fizz][Fiber] implement preconnect and prefetchDNS float methods (#26237)
Adds two new ReactDOM methods ### `ReactDOM.prefetchDNS(href: string)` In SSR this method will cause a `<link rel="dns-prefetch" href="..." />` to flush before most other content both on intial flush (Shell) and late flushes. It will only emit one link per href. On the client, this method will case the same kind of link to be inserted into the document immediately (when called during render, not during commit) if there is not already a matching element in the document. ### `ReactDOM.preconnect(href: string, options?: { crossOrigin?: string })` In SSR this method will cause a `<link rel="dns-prefetch" href="..." [corssorigin="..."] />` to flush before most other content both on intial flush (Shell) and late flushes. It will only emit one link per href + crossorigin combo. On the client, this method will case the same kind of link to be inserted into the document immediately (when called during render, not during commit) if there is not already a matching element in the document. DiffTrain build for [1173a17](1173a17)
1 parent 3b9bf76 commit 81e2051

31 files changed

+1427
-90
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e7d7d4cb4b61624c5762521370a58d941c1c46e3
1+
1173a17e6eea08599005e9f8e7d7a4245783edba
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e7d7d4cb4b61624c5762521370a58d941c1c46e3
1+
1173a17e6eea08599005e9f8e7d7a4245783edba

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-classic-e7d7d4cb4-20230225";
30+
var ReactVersion = "18.3.0-www-classic-1173a17e6-20230225";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-e7d7d4cb4-20230225";
30+
var ReactVersion = "18.3.0-www-modern-1173a17e6-20230225";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,4 +646,4 @@ exports.useSyncExternalStore = function (
646646
);
647647
};
648648
exports.useTransition = useTransition;
649-
exports.version = "18.3.0-www-classic-e7d7d4cb4-20230225";
649+
exports.version = "18.3.0-www-classic-1173a17e6-20230225";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,4 @@ exports.useSyncExternalStore = function (
638638
);
639639
};
640640
exports.useTransition = useTransition;
641-
exports.version = "18.3.0-www-modern-e7d7d4cb4-20230225";
641+
exports.version = "18.3.0-www-modern-1173a17e6-20230225";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ exports.useSyncExternalStore = function (
657657
);
658658
};
659659
exports.useTransition = useTransition;
660-
exports.version = "18.3.0-www-classic-e7d7d4cb4-20230225";
660+
exports.version = "18.3.0-www-classic-1173a17e6-20230225";
661661

662662
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
663663
if (

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ exports.useSyncExternalStore = function (
649649
);
650650
};
651651
exports.useTransition = useTransition;
652-
exports.version = "18.3.0-www-modern-e7d7d4cb4-20230225";
652+
exports.version = "18.3.0-www-modern-1173a17e6-20230225";
653653

654654
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
655655
if (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-classic-e7d7d4cb4-20230225";
72+
var ReactVersion = "18.3.0-www-classic-1173a17e6-20230225";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-modern-e7d7d4cb4-20230225";
72+
var ReactVersion = "18.3.0-www-modern-1173a17e6-20230225";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;

compiled/facebook-www/ReactART-prod.classic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9780,7 +9780,7 @@ var slice = Array.prototype.slice,
97809780
return null;
97819781
},
97829782
bundleType: 0,
9783-
version: "18.3.0-www-classic-e7d7d4cb4-20230225",
9783+
version: "18.3.0-www-classic-1173a17e6-20230225",
97849784
rendererPackageName: "react-art"
97859785
};
97869786
var internals$jscomp$inline_1300 = {
@@ -9811,7 +9811,7 @@ var internals$jscomp$inline_1300 = {
98119811
scheduleRoot: null,
98129812
setRefreshHandler: null,
98139813
getCurrentFiber: null,
9814-
reconcilerVersion: "18.3.0-next-e7d7d4cb4-20230225"
9814+
reconcilerVersion: "18.3.0-next-1173a17e6-20230225"
98159815
};
98169816
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
98179817
var hook$jscomp$inline_1301 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled/facebook-www/ReactART-prod.modern.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9445,7 +9445,7 @@ var slice = Array.prototype.slice,
94459445
return null;
94469446
},
94479447
bundleType: 0,
9448-
version: "18.3.0-www-modern-e7d7d4cb4-20230225",
9448+
version: "18.3.0-www-modern-1173a17e6-20230225",
94499449
rendererPackageName: "react-art"
94509450
};
94519451
var internals$jscomp$inline_1280 = {
@@ -9476,7 +9476,7 @@ var internals$jscomp$inline_1280 = {
94769476
scheduleRoot: null,
94779477
setRefreshHandler: null,
94789478
getCurrentFiber: null,
9479-
reconcilerVersion: "18.3.0-next-e7d7d4cb4-20230225"
9479+
reconcilerVersion: "18.3.0-next-1173a17e6-20230225"
94809480
};
94819481
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
94829482
var hook$jscomp$inline_1281 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9403,11 +9403,14 @@ function cleanupAfterRenderResources() {
94039403
// from Internals -> ReactDOM -> FloatClient -> Internals so this doesn't introduce a new one.
94049404

94059405
var ReactDOMClientDispatcher = {
9406+
prefetchDNS: prefetchDNS$1,
9407+
preconnect: preconnect$1,
94069408
preload: preload$1,
94079409
preinit: preinit$1
9408-
}; // global maps of Resources
9410+
}; // global collections of Resources
94099411

9410-
var preloadPropsMap = new Map(); // getRootNode is missing from IE and old jsdom versions
9412+
var preloadPropsMap = new Map();
9413+
var preconnectsSet = new Set(); // getRootNode is missing from IE and old jsdom versions
94119414

94129415
function getHoistableRoot(container) {
94139416
// $FlowFixMe[method-unbinding]
@@ -9444,8 +9447,104 @@ function getDocumentForPreloads() {
94449447

94459448
function getDocumentFromRoot(root) {
94469449
return root.ownerDocument || root;
9450+
}
9451+
9452+
function preconnectAs(rel, crossOrigin, href) {
9453+
var ownerDocument = getDocumentForPreloads();
9454+
9455+
if (typeof href === "string" && href && ownerDocument) {
9456+
var limitedEscapedHref =
9457+
escapeSelectorAttributeValueInsideDoubleQuotes(href);
9458+
var key = 'link[rel="' + rel + '"][href="' + limitedEscapedHref + '"]';
9459+
9460+
if (typeof crossOrigin === "string") {
9461+
key += '[crossorigin="' + crossOrigin + '"]';
9462+
}
9463+
9464+
if (!preconnectsSet.has(key)) {
9465+
preconnectsSet.add(key);
9466+
var preconnectProps = {
9467+
rel: rel,
9468+
crossOrigin: crossOrigin,
9469+
href: href
9470+
};
9471+
9472+
if (null === ownerDocument.querySelector(key)) {
9473+
var preloadInstance = createElement(
9474+
"link",
9475+
preconnectProps,
9476+
ownerDocument,
9477+
HTML_NAMESPACE
9478+
);
9479+
setInitialProperties(preloadInstance, "link", preconnectProps);
9480+
markNodeAsResource(preloadInstance);
9481+
ownerDocument.head.appendChild(preloadInstance);
9482+
}
9483+
}
9484+
}
9485+
} // --------------------------------------
9486+
// ReactDOM.prefetchDNS
9487+
// --------------------------------------
9488+
9489+
function prefetchDNS$1(href, options) {
9490+
{
9491+
if (typeof href !== "string" || !href) {
9492+
error(
9493+
"ReactDOM.prefetchDNS(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
9494+
getValueDescriptorExpectingObjectForWarning(href)
9495+
);
9496+
} else if (options != null) {
9497+
if (
9498+
typeof options === "object" &&
9499+
options.hasOwnProperty("crossOrigin")
9500+
) {
9501+
error(
9502+
"ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. It looks like the you are attempting to set a crossOrigin property for this DNS lookup hint. Browsers do not perform DNS queries using CORS and setting this attribute on the resource hint has no effect. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.",
9503+
getValueDescriptorExpectingEnumForWarning(options)
9504+
);
9505+
} else {
9506+
error(
9507+
"ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.",
9508+
getValueDescriptorExpectingEnumForWarning(options)
9509+
);
9510+
}
9511+
}
9512+
}
9513+
9514+
preconnectAs("dns-prefetch", null, href);
9515+
} // --------------------------------------
9516+
// ReactDOM.preconnect
9517+
// --------------------------------------
9518+
9519+
function preconnect$1(href, options) {
9520+
{
9521+
if (typeof href !== "string" || !href) {
9522+
error(
9523+
"ReactDOM.preconnect(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
9524+
getValueDescriptorExpectingObjectForWarning(href)
9525+
);
9526+
} else if (options != null && typeof options !== "object") {
9527+
error(
9528+
"ReactDOM.preconnect(): Expected the `options` argument (second) to be an object but encountered %s instead. The only supported option at this time is `crossOrigin` which accepts a string.",
9529+
getValueDescriptorExpectingEnumForWarning(options)
9530+
);
9531+
} else if (options != null && typeof options.crossOrigin !== "string") {
9532+
error(
9533+
"ReactDOM.preconnect(): Expected the `crossOrigin` option (second argument) to be a string but encountered %s instead. Try removing this option or passing a string value instead.",
9534+
getValueDescriptorExpectingObjectForWarning(options.crossOrigin)
9535+
);
9536+
}
9537+
}
9538+
9539+
var crossOrigin =
9540+
options == null || typeof options.crossOrigin !== "string"
9541+
? null
9542+
: options.crossOrigin === "use-credentials"
9543+
? "use-credentials"
9544+
: "";
9545+
preconnectAs("preconnect", crossOrigin, href);
94479546
} // --------------------------------------
9448-
// ReactDOM.Preload
9547+
// ReactDOM.preload
94499548
// --------------------------------------
94509549

94519550
function preload$1(href, options) {
@@ -42002,7 +42101,7 @@ function createFiberRoot(
4200242101
return root;
4200342102
}
4200442103

42005-
var ReactVersion = "18.3.0-www-classic-e7d7d4cb4-20230225";
42104+
var ReactVersion = "18.3.0-www-classic-1173a17e6-20230225";
4200642105

4200742106
function createPortal$1(
4200842107
children,
@@ -43486,12 +43585,21 @@ function createEventHandle(type, options) {
4348643585
}
4348743586
}
4348843587

43489-
function preinit() {
43588+
function prefetchDNS() {
4349043589
var dispatcher = Internals.Dispatcher.current;
4349143590

4349243591
if (dispatcher) {
43493-
dispatcher.preinit.apply(this, arguments);
43494-
} // We don't error because preinit needs to be resilient to being called in a variety of scopes
43592+
dispatcher.prefetchDNS.apply(this, arguments);
43593+
} // We don't error because preconnect needs to be resilient to being called in a variety of scopes
43594+
// and the runtime may not be capable of responding. The function is optimistic and not critical
43595+
// so we favor silent bailout over warning or erroring.
43596+
}
43597+
function preconnect() {
43598+
var dispatcher = Internals.Dispatcher.current;
43599+
43600+
if (dispatcher) {
43601+
dispatcher.preconnect.apply(this, arguments);
43602+
} // We don't error because preconnect needs to be resilient to being called in a variety of scopes
4349543603
// and the runtime may not be capable of responding. The function is optimistic and not critical
4349643604
// so we favor silent bailout over warning or erroring.
4349743605
}
@@ -43504,6 +43612,15 @@ function preload() {
4350443612
// and the runtime may not be capable of responding. The function is optimistic and not critical
4350543613
// so we favor silent bailout over warning or erroring.
4350643614
}
43615+
function preinit() {
43616+
var dispatcher = Internals.Dispatcher.current;
43617+
43618+
if (dispatcher) {
43619+
dispatcher.preinit.apply(this, arguments);
43620+
} // We don't error because preinit needs to be resilient to being called in a variety of scopes
43621+
// and the runtime may not be capable of responding. The function is optimistic and not critical
43622+
// so we favor silent bailout over warning or erroring.
43623+
}
4350743624

4350843625
setAttemptSynchronousHydration(attemptSynchronousHydration);
4350943626
setAttemptDiscreteHydration(attemptDiscreteHydration);
@@ -43657,6 +43774,8 @@ exports.findDOMNode = findDOMNode;
4365743774
exports.flushSync = flushSync;
4365843775
exports.hydrate = hydrate;
4365943776
exports.hydrateRoot = hydrateRoot;
43777+
exports.preconnect = preconnect;
43778+
exports.prefetchDNS = prefetchDNS;
4366043779
exports.preinit = preinit;
4366143780
exports.preload = preload;
4366243781
exports.render = render;

0 commit comments

Comments
 (0)