-
Notifications
You must be signed in to change notification settings - Fork 47.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Float][Flight][Fizz][Fiber] Implement
preloadModule
and `preinitMo…
…dule` (#27220) Stacked on #27224 ### Implements `ReactDOM.preloadModule()` `preloadModule` is a function to preload modules of various types. Similar to `preload` this is useful when you expect to use a Resource soon but can't render that resource directly. At the moment the only sensible module to preload is script modules along with some other `as` variants such as `as="serviceworker"`. In the future when there is some notion of how to preload style module script or json module scripts this API will be extended to support those as well. ##### Arguments 1. `href: string` -> the href or src value you want to preload. 2. `options?: {...}` -> 2.1. `options.as?: string` -> the `as` property the modulepreload link should render with. If not provided it will be omitted which will cause the modulepreload to be treated like a script module 2.2. `options.crossOrigin?: string` -> modules always load with CORS but you can provide `use-credentials` if you want to change the default behavior 2.3. `options.integrity?: string` -> an integrity hash for subresource integrity APIs ##### Rendering each preloaded module will emit a `<link rel="modulepreload" href="..." />` if `as` is specified and is something other than `"script"` the as attribute will also be included if crossOrigin or integrity as specified their attributes will also be included During SSR these script tags will be emitted before content. If we have not yet flushed the document head they will be emitted there after things that block paint such as font preloads, img preloads, and stylesheets. On the client these link tags will be appended to the document.head. ### Implements `ReactDOM.preinitModule()` `preinitModule` is a function to loading module scripts before they are required. It has the same use cases as `preinit`. During SSR you would use this to tell the browsers to start fetching code that will be used without having to wait for bootstrapping to initiate module fetches. ON the client you would use this to start fetching a module script early for an anticipated navigation or other event that is likely to depend on this module script. the `as` property for Float methods drew inspiration from the `as` attribute of the `<link rel="preload" ... >` tag but it is used as a sort of tag for the kind of thing being targetted by Float methods. For `preinitModule` we currently only support `as: "script"` and this is also the assumed default type so you current never need to specify this `as` value. In the future `preinitModule` will support additional module script types such as `style` or `json`. The support of these types will correspond to [Module Import Attributes](https://github.com/tc39/proposal-import-attributes). ##### Arguments 1. `href: string` -> the href or src value you want to preinitialize 2. `options?: {...}` -> 2.1 `options.as?: string` -> only supports `script` and this is the default behavior. Until we support import attributes such as `json` and `style` there will not be much reason to provide an `as` option. 2.2. `options.crossOrigin?: string`: modules always load with CORS but you can provide `use-credentials` if you want to change the default behavior 2.3 `options.integrity?: string` -> an integrity hash for subresource integrity APIs ##### Rendering each preinitialized `script` module will emit a `<script type="module" async="" src"...">` During SSR these will appear behind display blocking resources such as font preloads, img preloads, and stylesheets. In the browser these will be appende to the head. Note that for other `as` types the rendered output will be slightly different. `<script type="module">import "..." with {type: "json" }</script>`. Since this tag is an inline script variants of React that do not use inline scripts will simply omit these preinitialization tags from the SSR output. This is not implemented in this PR but will appear in a future update. DiffTrain build for [e505316](e505316)
- Loading branch information
Showing
22 changed files
with
2,337 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ac1a16c67e268fcb2c52e91717cbc918c7c24446 | ||
e50531692010bbda2a4627b07c7c810c3770a52a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.