From 8f6f92832f2fe5a6c738533f5b39e06a1f4d0097 Mon Sep 17 00:00:00 2001 From: r17x Date: Fri, 19 Jul 2024 15:18:08 +0700 Subject: [PATCH] feat(react-dom): add experimental module list of experimental bind: * preconnect * prefetchDNS * preinit * preinitModule * preload * preloadModule --- src/ReactDOM.re | 27 +++++++++++++++++++++++++++ src/ReactDOM.rei | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/ReactDOM.re b/src/ReactDOM.re index bedb622f2..e5823c497 100644 --- a/src/ReactDOM.re +++ b/src/ReactDOM.re @@ -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; diff --git a/src/ReactDOM.rei b/src/ReactDOM.rei index 2310ca3e2..aa343c394 100644 --- a/src/ReactDOM.rei +++ b/src/ReactDOM.rei @@ -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;