Skip to content

Commit

Permalink
feat(react-dom): add experimental module
Browse files Browse the repository at this point in the history
list of experimental bind:
* preconnect
* prefetchDNS
* preinit
* preinitModule
* preload
* preloadModule
  • Loading branch information
r17x committed Jul 19, 2024
1 parent 15affd0 commit 8f6f928
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/ReactDOM.re
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,33 @@ external unmountComponentAtNode: Dom.element => unit =
[@mel.module "react-dom"]
external flushSync: (unit => unit) => unit = "flushSync";

module Experimental = {
[@deriving jsProperties]
type preOptions = {
[@mel.as "as"] [@mel.optional]
_as: option([ | `script]),
[@mel.optional]
crossOrigin: option(string),
[@mel.optional]
integrity: option(string),
[@mel.optional]
nonce: option(string),
};

[@mel.module "react-dom"]
external preconnect: string => unit = "preconnect";
[@mel.module "react-dom"]
external prefetchDNS: string => unit = "prefetchDNS";
[@mel.module "react-dom"]
external preinit: string => unit = "preinit";
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
external preload: string => unit = "preload";
[@mel.module "react-dom"]
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
}

external domElementToObj: Dom.element => Js.t({..}) = "%identity";

type style = Style.t;
Expand Down
45 changes: 45 additions & 0 deletions src/ReactDOM.rei
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,51 @@ external unmountComponentAtNode: Dom.element => unit =
[@mel.module "react-dom"]
external flushSync: (unit => unit) => unit = "flushSync";

module Experimental: {
/*
preinitModule and preloadModule options.
https://react.dev/reference/react-dom/preinitModule#parameters
*/
[@deriving jsProperties]
type preOptions = {
/* a required string. It must be 'script'. */
[@mel.as "as"] [@mel.optional]
_as: option([ | `script]),
/*
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 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 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),
};

/* This module is used to bind to APIs for future versions of ReactDOM. There is no guarantee of backwards compatibility or stability. */
[@mel.module "react-dom"]
external preconnect: string => unit = "preconnect";
[@mel.module "react-dom"]
external prefetchDNS: string => unit = "prefetchDNS";
[@mel.module "react-dom"]
external preinit: string => unit = "preinit";
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
external preload: string => unit = "preload";
[@mel.module "react-dom"]
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
}

external domElementToObj: Dom.element => Js.t({..}) = "%identity";

type style = Style.t;
Expand Down

0 comments on commit 8f6f928

Please sign in to comment.