Skip to content

Commit 24f04c7

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

File tree

2 files changed

+128
-2
lines changed

2 files changed

+128
-2
lines changed

src/ReactDOM.re

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

480480
module Experimental = {
481+
[@deriving jsProperties]
482+
type preloadOptions = {
483+
[@mel.as "as"] [@mel.optional]
484+
_as: option([
485+
| `audio
486+
| `document
487+
| `embed
488+
| `fetch
489+
| `font
490+
| `image
491+
| [@mel.as "object"] `object_
492+
| `script
493+
| `style
494+
| `track
495+
| `video
496+
| `worker
497+
]),
498+
[@mel.optional]
499+
fetchPriority: option([ `auto | `high | `low ]),
500+
[@mel.optional]
501+
referrerPolicy: option([
502+
| [@mel.as "no-referrer"] `noReferrer
503+
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
504+
| [@mel.as "origin"] `origin
505+
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
506+
| [@mel.as "unsafe-url"] `unsafeUrl
507+
]),
508+
[@mel.optional]
509+
imageSrcSet: option(string),
510+
[@mel.optional]
511+
imageSizes: option(string),
512+
[@mel.optional]
513+
crossOrigin: option(string),
514+
[@mel.optional]
515+
integrity: option(string),
516+
[@mel.optional]
517+
nonce: option(string),
518+
};
519+
520+
[@deriving jsProperties]
521+
type preinitOptions = {
522+
[@mel.as "as"] [@mel.optional]
523+
_as: option([ | `script | `style ]),
524+
[@mel.optional]
525+
fetchPriority: option([ `auto | `high | `low ]),
526+
[@mel.optional]
527+
precedence: option([ `reset | `low | `medium | `high ]),
528+
[@mel.optional]
529+
crossOrigin: option(string),
530+
[@mel.optional]
531+
integrity: option(string),
532+
[@mel.optional]
533+
nonce: option(string),
534+
};
535+
481536
[@deriving jsProperties]
482537
type preinitOptions = {
483538
[@mel.as "as"] [@mel.optional]
@@ -515,7 +570,7 @@ module Experimental = {
515570
[@mel.module "react-dom"]
516571
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
517572
[@mel.module "react-dom"]
518-
external preload: string => unit = "preload";
573+
external preload: (string, ~options: preloadOptions=?, unit) => unit = "preload";
519574
[@mel.module "react-dom"]
520575
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
521576
}

src/ReactDOM.rei

+72-1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,77 @@ 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+
[@deriving jsProperties]
488+
type preloadOptions = {
489+
/* Its possible values are audio, document, embed, fetch, font, image, object, script, style, track, video, worker. */
490+
[@mel.as "as"] [@mel.optional]
491+
_as: option([
492+
| `audio
493+
| `document
494+
| `embed
495+
| `fetch
496+
| `font
497+
| `image
498+
| [@mel.as "object"] `object_
499+
| `script
500+
| `style
501+
| `track
502+
| `video
503+
| `worker
504+
]),
505+
/*
506+
Suggests a relative priority for fetching the resource.
507+
The possible values are auto (the default), high, and low.
508+
*/
509+
[@mel.optional]
510+
fetchPriority: option([ `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+
[@mel.optional]
516+
referrerPolicy: option([
517+
| [@mel.as "no-referrer"] `noReferrer
518+
| [@mel.as "no-referrer-when-downgrade"] `noReferrerWhenDowngrade
519+
| [@mel.as "origin"] `origin
520+
| [@mel.as "origin-when-cross-origin"] `originWhenCrossOrigin
521+
| [@mel.as "unsafe-url"] `unsafeUrl
522+
]),
523+
/*
524+
For use only with as: "image". Specifies the source set of the image.
525+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
526+
*/
527+
[@mel.optional]
528+
imageSrcSet: option(string),
529+
/*
530+
For use only with as: "image". Specifies the source sizes of the image.
531+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
532+
*/
533+
[@mel.optional]
534+
imageSizes: option(string),
535+
/*
536+
a required string. It must be "anonymous", "use-credentials", and "".
537+
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
538+
*/
539+
[@mel.optional]
540+
crossOrigin: option(string),
541+
/*
542+
A cryptographic hash of the module, to verify its authenticity.
543+
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
544+
*/
545+
[@mel.optional]
546+
integrity: option(string),
547+
/*
548+
A cryptographic nonce to allow the module when using a strict Content Security Policy.
549+
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
550+
*/
551+
[@mel.optional]
552+
nonce: option(string),
553+
};
483554

484555
/*
485556
preinit options.
@@ -562,7 +633,7 @@ module Experimental: {
562633
[@mel.module "react-dom"]
563634
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
564635
[@mel.module "react-dom"]
565-
external preload: string => unit = "preload";
636+
external preload: (string, ~options: preloadOptions=?, unit) => unit = "preload";
566637
[@mel.module "react-dom"]
567638
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
568639
}

0 commit comments

Comments
 (0)