Skip to content

Commit

Permalink
feat(react-dom): add options to preload
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed Jul 21, 2024
1 parent 57d426b commit 26e7c3c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
36 changes: 35 additions & 1 deletion src/ReactDOM.re
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,40 @@ external unmountComponentAtNode: Dom.element => unit =
external flushSync: (unit => unit) => unit = "flushSync";

module Experimental = {
type preloadOptions;

[@mel.obj]
external preloadOptions: (
~_as: [
| `audio
| `document
| `embed
| `fetch
| `font
| `image
| [@mel.as "object"] `object_
| `script
| `style
| `track
| `video
| `worker
],
~fetchPriority: [ `auto | `high | `low ]=?,
~referrerPolicy: [
| [@mel.as "no-referrer"] `noReferrer
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
| [@mel.as "origin"] `origin
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
| [@mel.as "unsafe-url"] `unsafeUrl
]=?,
~imageSrcSet: string=?,
~imageSizes: string=?,
~crossOrigin: string=?,
~integrity: string=?,
~nonce: string=?,
unit
) => preloadOptions;

[@deriving jsProperties]
type preinitOptions = {
[@mel.as "as"] [@mel.optional]
Expand Down Expand Up @@ -515,7 +549,7 @@ module Experimental = {
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
external preload: string => unit = "preload";
external preload: (string, ~options: preloadOptions=?, unit) => unit = "preload";
[@mel.module "react-dom"]
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
}
Expand Down
68 changes: 67 additions & 1 deletion src/ReactDOM.rei
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,72 @@ external flushSync: (unit => unit) => unit = "flushSync";

module Experimental: {
/* This module is used to bind to APIs for future versions of ReactDOM. There is no guarantee of backwards compatibility or stability. */
/*
preload options.
https://react.dev/reference/react-dom/preload#parameters
*/
type preloadOptions;

[@mel.obj]
external preloadOptions: (
/* Its possible values are audio, document, embed, fetch, font, image, object, script, style, track, video, worker. */
~_as: [
| `audio
| `document
| `embed
| `fetch
| `font
| `image
| [@mel.as "object"] `object_
| `script
| `style
| `track
| `video
| `worker
],
/*
Suggests a relative priority for fetching the resource.
The possible values are auto (the default), high, and low.
*/
~fetchPriority: [ `auto | `high | `low ]=?,
/*
The Referrer header to send when fetching.
Its possible values are no-referrer-when-downgrade (the default), no-referrer, origin, origin-when-cross-origin, and unsafe-url.
*/
~referrerPolicy: [
| [@mel.as "no-referrer"] `noReferrer
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
| [@mel.as "origin"] `origin
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
| [@mel.as "unsafe-url"] `unsafeUrl
]=?,
/*
For use only with as: "image". Specifies the source set of the image.
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
*/
~imageSrcSet: string=?,
/*
For use only with as: "image". Specifies the source sizes of the image.
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
*/
~imageSizes: string=?,
/*
a required string. It must be "anonymous", "use-credentials", and "".
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
*/
~crossOrigin: string=?,
/*
A cryptographic hash of the module, to verify its authenticity.
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
*/
~integrity: string=?,
/*
A cryptographic nonce to allow the module when using a strict Content Security Policy.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
*/
~nonce: string=?,
unit
) => preloadOptions;

/*
preinit options.
Expand Down Expand Up @@ -562,7 +628,7 @@ module Experimental: {
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
external preload: string => unit = "preload";
external preload: (string, ~options: preloadOptions=?, unit) => unit = "preload";
[@mel.module "react-dom"]
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
}
Expand Down

0 comments on commit 26e7c3c

Please sign in to comment.