Skip to content

Commit

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

module Experimental = {
[@deriving jsProperties]
type preinitOptions = {
[@mel.as "as"] [@mel.optional]
_as: option([ | `script | `style ]),
[@mel.optional]
fetchPriority: option([ `auto | `high | `low ]),
[@mel.optional]
precedence: option([ `reset | `low | `medium | `high ]),
[@mel.optional]
crossOrigin: option(string),
[@mel.optional]
integrity: option(string),
[@mel.optional]
nonce: option(string),
};

[@deriving jsProperties]
type preOptions = {
[@mel.as "as"] [@mel.optional]
Expand All @@ -495,7 +511,7 @@ module Experimental = {
[@mel.module "react-dom"]
external prefetchDNS: string => unit = "prefetchDNS";
[@mel.module "react-dom"]
external preinit: string => unit = "preinit";
external preinit: (string, ~options: preinitOptions=?, unit) => unit = "preinit";
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
Expand Down
44 changes: 43 additions & 1 deletion src/ReactDOM.rei
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,48 @@ 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. */

/*
preinit options.
https://react.dev/reference/react-dom/preinit#parameters
*/
[@deriving jsProperties]
type preinitOptions = {
/* possible values: "script" or "style" */
[@mel.as "as"] [@mel.optional]
_as: option([ | `script | `style ]),
/*
Suggests a relative priority for fetching the resource.
The possible values are auto (the default), high, and low.
*/
[@mel.optional]
fetchPriority: option([ `auto | `high | `low ]),
/*
Required with Stylesheets (`style). Says where to insert the stylesheet relative to others.
Stylesheets with higher precedence can override those with lower precedence.
The possible values are reset, low, medium, high.
*/
[@mel.optional]
precedence: option([ `reset | `low | `medium | `high ]),
/*
a required string. It must be "anonymous", "use-credentials", and "".
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
*/
[@mel.optional]
crossOrigin: option(string),
/*
A cryptographic hash of the module, to verify its authenticity.
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
*/
[@mel.optional]
integrity: option(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
*/
[@mel.optional]
nonce: option(string),
};

/*
preinitModule and preloadModule options.
https://react.dev/reference/react-dom/preinitModule#parameters
Expand Down Expand Up @@ -516,7 +558,7 @@ module Experimental: {
[@mel.module "react-dom"]
external prefetchDNS: string => unit = "prefetchDNS";
[@mel.module "react-dom"]
external preinit: string => unit = "preinit";
external preinit: (string, ~options: preinitOptions=?, unit) => unit = "preinit";
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
Expand Down

0 comments on commit 57d426b

Please sign in to comment.