Skip to content

Commit c7679f6

Browse files
authored
feat(react-dom): add experimental module (#849)
* feat(react-dom): add experimental module list of experimental bind: * preconnect * prefetchDNS * preinit * preinitModule * preload * preloadModule * feat(react-dom): add options to preinit * feat(react-dom): add options to preload * feat(react-dom): make all _as property in options is required * style(react-dom): formatted Experimental module
1 parent 4b57b39 commit c7679f6

File tree

2 files changed

+248
-0
lines changed

2 files changed

+248
-0
lines changed

src/ReactDOM.re

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,91 @@ external unmountComponentAtNode: Dom.element => unit =
477477
[@mel.module "react-dom"]
478478
external flushSync: (unit => unit) => unit = "flushSync";
479479

480+
module Experimental = {
481+
type preloadOptions;
482+
483+
[@mel.obj]
484+
external preloadOptions:
485+
(
486+
~_as: [
487+
| `audio
488+
| `document
489+
| `embed
490+
| `fetch
491+
| `font
492+
| `image
493+
| [@mel.as "object"] `object_
494+
| `script
495+
| `style
496+
| `track
497+
| `video
498+
| `worker
499+
],
500+
~fetchPriority: [ | `auto | `high | `low]=?,
501+
~referrerPolicy: [
502+
| [@mel.as "no-referrer"] `noReferrer
503+
| [@mel.as "no-referrer-when-downgrade"]
504+
`noReferrerWhenDowngrade
505+
| [@mel.as "origin"] `origin
506+
| [@mel.as "origin-when-cross-origin"]
507+
`originWhenCrossOrigin
508+
| [@mel.as "unsafe-url"] `unsafeUrl
509+
]
510+
=?,
511+
~imageSrcSet: string=?,
512+
~imageSizes: string=?,
513+
~crossOrigin: string=?,
514+
~integrity: string=?,
515+
~nonce: string=?,
516+
unit
517+
) =>
518+
preloadOptions;
519+
520+
[@deriving jsProperties]
521+
type preinitOptions = {
522+
[@mel.as "as"]
523+
_as: [ | `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+
536+
[@deriving jsProperties]
537+
type preOptions = {
538+
[@mel.as "as"]
539+
_as: [ | `script],
540+
[@mel.optional]
541+
crossOrigin: option(string),
542+
[@mel.optional]
543+
integrity: option(string),
544+
[@mel.optional]
545+
nonce: option(string),
546+
};
547+
548+
[@mel.module "react-dom"] external preconnect: string => unit = "preconnect";
549+
[@mel.module "react-dom"]
550+
external prefetchDNS: string => unit = "prefetchDNS";
551+
[@mel.module "react-dom"]
552+
external preinit: (string, ~options: preinitOptions=?, unit) => unit =
553+
"preinit";
554+
[@mel.module "react-dom"]
555+
external preinitModule: (string, ~options: preOptions=?, unit) => unit =
556+
"preinitModule";
557+
[@mel.module "react-dom"]
558+
external preload: (string, ~options: preloadOptions=?, unit) => unit =
559+
"preload";
560+
[@mel.module "react-dom"]
561+
external preloadModule: (string, ~options: preOptions=?, unit) => unit =
562+
"preloadModule";
563+
};
564+
480565
external domElementToObj: Dom.element => Js.t({..}) = "%identity";
481566

482567
type style = Style.t;

src/ReactDOM.rei

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,169 @@ external unmountComponentAtNode: Dom.element => unit =
478478
[@mel.module "react-dom"]
479479
external flushSync: (unit => unit) => unit = "flushSync";
480480

481+
module Experimental: {
482+
/* 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+
(
493+
~_as: [
494+
| `audio
495+
| `document
496+
| `embed
497+
| `fetch
498+
| `font
499+
| `image
500+
| [@mel.as "object"] `object_
501+
| `script
502+
| `style
503+
| `track
504+
| `video
505+
| `worker
506+
],
507+
/*
508+
Suggests a relative priority for fetching the resource.
509+
The possible values are auto (the default), high, and low.
510+
*/
511+
~fetchPriority: [ | `auto | `high | `low]=?,
512+
/*
513+
The Referrer header to send when fetching.
514+
Its possible values are no-referrer-when-downgrade (the default), no-referrer, origin, origin-when-cross-origin, and unsafe-url.
515+
*/
516+
~referrerPolicy: [
517+
| [@mel.as "no-referrer"] `noReferrer
518+
| [@mel.as "no-referrer-when-downgrade"]
519+
`noReferrerWhenDowngrade
520+
| [@mel.as "origin"] `origin
521+
| [@mel.as "origin-when-cross-origin"]
522+
`originWhenCrossOrigin
523+
| [@mel.as "unsafe-url"] `unsafeUrl
524+
]
525+
=?,
526+
/*
527+
For use only with as: "image". Specifies the source set of the image.
528+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
529+
*/
530+
~imageSrcSet: string=?,
531+
/*
532+
For use only with as: "image". Specifies the source sizes of the image.
533+
https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
534+
*/
535+
~imageSizes: string=?,
536+
/*
537+
a required string. It must be "anonymous", "use-credentials", and "".
538+
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
539+
*/
540+
~crossOrigin: 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+
~integrity: string=?,
546+
/*
547+
A cryptographic nonce to allow the module when using a strict Content Security Policy.
548+
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
549+
*/
550+
~nonce: string=?,
551+
unit
552+
) =>
553+
preloadOptions;
554+
555+
/*
556+
preinit options.
557+
https://react.dev/reference/react-dom/preinit#parameters
558+
*/
559+
[@deriving jsProperties]
560+
type preinitOptions = {
561+
/* possible values: "script" or "style" */
562+
[@mel.as "as"]
563+
_as: [ | `script | `style],
564+
/*
565+
Suggests a relative priority for fetching the resource.
566+
The possible values are auto (the default), high, and low.
567+
*/
568+
[@mel.optional]
569+
fetchPriority: option([ | `auto | `high | `low]),
570+
/*
571+
Required with Stylesheets (`style). Says where to insert the stylesheet relative to others.
572+
Stylesheets with higher precedence can override those with lower precedence.
573+
The possible values are reset, low, medium, high.
574+
*/
575+
[@mel.optional]
576+
precedence: option([ | `reset | `low | `medium | `high]),
577+
/*
578+
a required string. It must be "anonymous", "use-credentials", and "".
579+
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
580+
*/
581+
[@mel.optional]
582+
crossOrigin: option(string),
583+
/*
584+
A cryptographic hash of the module, to verify its authenticity.
585+
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
586+
*/
587+
[@mel.optional]
588+
integrity: option(string),
589+
/*
590+
A cryptographic nonce to allow the module when using a strict Content Security Policy.
591+
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
592+
*/
593+
[@mel.optional]
594+
nonce: option(string),
595+
};
596+
597+
/*
598+
preinitModule and preloadModule options.
599+
https://react.dev/reference/react-dom/preinitModule#parameters
600+
https://react.dev/reference/react-dom/preloadModule#parameters
601+
*/
602+
[@deriving jsProperties]
603+
type preOptions = {
604+
/* It must be 'script'. */
605+
[@mel.as "as"]
606+
_as: [ | `script],
607+
/*
608+
a required string. It must be "anonymous", "use-credentials", and "".
609+
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
610+
*/
611+
[@mel.optional]
612+
crossOrigin: option(string),
613+
/*
614+
A cryptographic hash of the module, to verify its authenticity.
615+
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
616+
*/
617+
[@mel.optional]
618+
integrity: option(string),
619+
/*
620+
A cryptographic nonce to allow the module when using a strict Content Security Policy.
621+
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
622+
*/
623+
[@mel.optional]
624+
nonce: option(string),
625+
};
626+
627+
[@mel.module "react-dom"] external preconnect: string => unit = "preconnect";
628+
[@mel.module "react-dom"]
629+
external prefetchDNS: string => unit = "prefetchDNS";
630+
[@mel.module "react-dom"]
631+
external preinit: (string, ~options: preinitOptions=?, unit) => unit =
632+
"preinit";
633+
[@mel.module "react-dom"]
634+
external preinitModule: (string, ~options: preOptions=?, unit) => unit =
635+
"preinitModule";
636+
[@mel.module "react-dom"]
637+
external preload: (string, ~options: preloadOptions=?, unit) => unit =
638+
"preload";
639+
[@mel.module "react-dom"]
640+
external preloadModule: (string, ~options: preOptions=?, unit) => unit =
641+
"preloadModule";
642+
};
643+
481644
external domElementToObj: Dom.element => Js.t({..}) = "%identity";
482645

483646
type style = Style.t;

0 commit comments

Comments
 (0)