Skip to content

Commit 8645888

Browse files
committed
[Fizz] implement onHeaders and headersLengthHint options (#27641)
Adds a new option to `react-dom/server` entrypoints. `onHeaders: (headers: Headers) => void` (non node envs) `onHeaders: (headers: { Link?: string }) => void` (node envs) When any `renderTo...` or `prerender...` function is called and this option is provided the supplied function will be called sometime on or before completion of the render with some preload link headers. When provided during a `renderTo...` the callback will usually be called after the first pass at work. The idea here is we want to get a set of headers to start the browser loading well before the shell is ready. We don't wait for the shell because if we did we may as well send the preloads as tags in the HTML. When provided during a `prerender...` the callback will be called after the entire prerender is complete. The idea here is we are not responding to a live request and it is preferable to capture as much as possible for preloading as Headers in case the prerender was unable to finish the shell. Currently the following resources are always preloaded as headers when the option is provided 1. prefetchDNS and preconnects 2. font preloads 3. high priority image preloads Additionally if we are providing headers when the shell is incomplete (regardless of whether it is render or prerender) we will also include any stylesheet Resources (ones with a precedence prop) There is a second option `maxHeadersLength?: number` which allows you to specify the maximum length of the header content in unicode code units. This is what you get when you read the length property of a string in javascript. It's improtant to note that this is not the same as the utf-8 byte length when these headers are serialized in a Response. The utf8 representation may be the same size, or larger but it will never be smaller. If you do not supply a `maxHeadersLength` we defaul to `2000`. This was chosen as half the value of the max headers length supported by commonly known web servers and CDNs. many browser and web server can support significantly more headers than this so you can use this option to increase the headers limit. You can also of course use it to be even more conservative. Again it is important to keep in mind there is no direct translation between the max length and the bytelength and so if you want to stay under a certain byte length you need to be potentially more aggressive in the maxHeadersLength you choose. Conceptually `onHeaders` could be called more than once as new headers are discovered however if we haven't started flushing yet but since most APIs for the server including the web standard Response only allow you to set headers once the current implementation will only call it one time DiffTrain build for [2983249](2983249)
1 parent c7102d3 commit 8645888

10 files changed

+2949
-677
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ce2bc58a9f6f3b0bfc8c738a0d8e2a5f3a332ff5
1+
2983249dd2bb1a295f27939e36ab0de9e4bfab76

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-044f7cdc";
72+
var ReactVersion = "18.3.0-www-modern-073e3c23";
7373

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9850,7 +9850,7 @@ var slice = Array.prototype.slice,
98509850
return null;
98519851
},
98529852
bundleType: 0,
9853-
version: "18.3.0-www-modern-b1c48f3b",
9853+
version: "18.3.0-www-modern-deff22e3",
98549854
rendererPackageName: "react-art"
98559855
};
98569856
var internals$jscomp$inline_1302 = {
@@ -9881,7 +9881,7 @@ var internals$jscomp$inline_1302 = {
98819881
scheduleRoot: null,
98829882
setRefreshHandler: null,
98839883
getCurrentFiber: null,
9884-
reconcilerVersion: "18.3.0-www-modern-b1c48f3b"
9884+
reconcilerVersion: "18.3.0-www-modern-deff22e3"
98859885
};
98869886
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
98879887
var hook$jscomp$inline_1303 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

0 commit comments

Comments
 (0)