Skip to content

Commit 26e7c3c

Browse files
committed
feat(react-dom): add options to preload
1 parent 57d426b commit 26e7c3c

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

src/ReactDOM.re

+35-1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,40 @@ external unmountComponentAtNode: Dom.element => unit =
478478
external flushSync: (unit => unit) => unit = "flushSync";
479479

480480
module Experimental = {
481+
type preloadOptions;
482+
483+
[@mel.obj]
484+
external preloadOptions: (
485+
~_as: [
486+
| `audio
487+
| `document
488+
| `embed
489+
| `fetch
490+
| `font
491+
| `image
492+
| [@mel.as "object"] `object_
493+
| `script
494+
| `style
495+
| `track
496+
| `video
497+
| `worker
498+
],
499+
~fetchPriority: [ `auto | `high | `low ]=?,
500+
~referrerPolicy: [
501+
| [@mel.as "no-referrer"] `noReferrer
502+
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
503+
| [@mel.as "origin"] `origin
504+
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
505+
| [@mel.as "unsafe-url"] `unsafeUrl
506+
]=?,
507+
~imageSrcSet: string=?,
508+
~imageSizes: string=?,
509+
~crossOrigin: string=?,
510+
~integrity: string=?,
511+
~nonce: string=?,
512+
unit
513+
) => preloadOptions;
514+
481515
[@deriving jsProperties]
482516
type preinitOptions = {
483517
[@mel.as "as"] [@mel.optional]
@@ -515,7 +549,7 @@ module Experimental = {
515549
[@mel.module "react-dom"]
516550
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
517551
[@mel.module "react-dom"]
518-
external preload: string => unit = "preload";
552+
external preload: (string, ~options: preloadOptions=?, unit) => unit = "preload";
519553
[@mel.module "react-dom"]
520554
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
521555
}

src/ReactDOM.rei

+67-1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,72 @@ external flushSync: (unit => unit) => unit = "flushSync";
480480

481481
module Experimental: {
482482
/* This module is used to bind to APIs for future versions of ReactDOM. There is no guarantee of backwards compatibility or stability. */
483+
/*
484+
preload options.
485+
https://react.dev/reference/react-dom/preload#parameters
486+
*/
487+
type preloadOptions;
488+
489+
[@mel.obj]
490+
external preloadOptions: (
491+
/* Its possible values are audio, document, embed, fetch, font, image, object, script, style, track, video, worker. */
492+
~_as: [
493+
| `audio
494+
| `document
495+
| `embed
496+
| `fetch
497+
| `font
498+
| `image
499+
| [@mel.as "object"] `object_
500+
| `script
501+
| `style
502+
| `track
503+
| `video
504+
| `worker
505+
],
506+
/*
507+
Suggests a relative priority for fetching the resource.
508+
The possible values are auto (the default), high, and low.
509+
*/
510+
~fetchPriority: [ `auto | `high | `low ]=?,
511+
/*
512+
The Referrer header to send when fetching.
513+
Its possible values are no-referrer-when-downgrade (the default), no-referrer, origin, origin-when-cross-origin, and unsafe-url.
514+
*/
515+
~referrerPolicy: [
516+
| [@mel.as "no-referrer"] `noReferrer
517+
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
518+
| [@mel.as "origin"] `origin
519+
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
520+
| [@mel.as "unsafe-url"] `unsafeUrl
521+
]=?,
522+
/*
523+
For use only with as: "image". Specifies the source set of the image.
524+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
525+
*/
526+
~imageSrcSet: string=?,
527+
/*
528+
For use only with as: "image". Specifies the source sizes of the image.
529+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
530+
*/
531+
~imageSizes: string=?,
532+
/*
533+
a required string. It must be "anonymous", "use-credentials", and "".
534+
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
535+
*/
536+
~crossOrigin: string=?,
537+
/*
538+
A cryptographic hash of the module, to verify its authenticity.
539+
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
540+
*/
541+
~integrity: string=?,
542+
/*
543+
A cryptographic nonce to allow the module when using a strict Content Security Policy.
544+
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
545+
*/
546+
~nonce: string=?,
547+
unit
548+
) => preloadOptions;
483549

484550
/*
485551
preinit options.
@@ -562,7 +628,7 @@ module Experimental: {
562628
[@mel.module "react-dom"]
563629
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
564630
[@mel.module "react-dom"]
565-
external preload: string => unit = "preload";
631+
external preload: (string, ~options: preloadOptions=?, unit) => unit = "preload";
566632
[@mel.module "react-dom"]
567633
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
568634
}

0 commit comments

Comments
 (0)