diff --git a/ppx/reason_react_ppx.ml b/ppx/reason_react_ppx.ml index c3c8bd4e0..1d2941819 100644 --- a/ppx/reason_react_ppx.ml +++ b/ppx/reason_react_ppx.ml @@ -54,6 +54,12 @@ module Binding = struct { txt = Longident.Ldot (Lident "React", "array"); loc }) [ (nolabel, children) ] + let unsafeArray ~loc children = + Builder.pexp_apply ~loc + (Builder.pexp_ident ~loc + { txt = Longident.Ldot (Lident "React", "unsafeArray"); loc }) + [ (nolabel, children) ] + let componentLike ~loc props return = Ptyp_constr ( { loc; txt = Ldot (Lident "React", "componentLike") }, @@ -448,7 +454,7 @@ let jsxExprAndChildren ~ident ~loc ~ctxt mapper ~keyProps children = when list = [] -> ( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxKeyed") }, Some (label, key), - Some (Binding.React.array ~loc children) ) + Some (Binding.React.unsafeArray ~loc children) ) | Some (ListLiteral { pexp_desc = Pexp_array list }), [] when list = [] -> ( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsx") }, None, @@ -458,13 +464,13 @@ let jsxExprAndChildren ~ident ~loc ~ctxt mapper ~keyProps children = children *) ( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxsKeyed") }, Some (label, key), - Some (Binding.React.array ~loc children) ) + Some (Binding.React.unsafeArray ~loc children) ) | Some (ListLiteral children), [] -> (* this is a hack to support react components that introspect into their children *) ( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxs") }, None, - Some (Binding.React.array ~loc children) ) + Some (Binding.React.unsafeArray ~loc children) ) | None, (label, key) :: _ -> ( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxKeyed") }, Some (label, key), diff --git a/src/React.re b/src/React.re index 873d87347..4242995e5 100644 --- a/src/React.re +++ b/src/React.re @@ -301,6 +301,7 @@ module Event = { }; type element; +type elementKeyed; type componentLike('props, 'return) = 'props => 'return; type component('props) = componentLike('props, element); @@ -308,7 +309,8 @@ external null: element = "null"; external float: float => element = "%identity"; external int: int => element = "%identity"; external string: string => element = "%identity"; -external array: array(element) => element = "%identity"; +external array: array(elementKeyed) => element = "%identity"; +external unsafeArray: array(element) => element = "%identity"; /* this function exists to prepare for making `component` abstract */ external component: componentLike('props, element) => component('props) = @@ -328,7 +330,7 @@ external createElementVariadic: [@mel.module "react/jsx-runtime"] external jsxKeyed: - (component('props), 'props, ~key: string=?, unit) => element = + (component('props), 'props, ~key: string=?, unit) => elementKeyed = "jsx"; [@mel.module "react/jsx-runtime"] diff --git a/src/React.rei b/src/React.rei index fcbdb1120..a5d849bae 100644 --- a/src/React.rei +++ b/src/React.rei @@ -1,4 +1,5 @@ type element; +type elementKeyed; type componentLike('props, 'return) = 'props => 'return; type component('props) = componentLike('props, element); @@ -6,7 +7,8 @@ external null: element = "null"; external float: float => element = "%identity"; external int: int => element = "%identity"; external string: string => element = "%identity"; -external array: array(element) => element = "%identity"; +external array: array(elementKeyed) => element = "%identity"; +external unsafeArray: array(element) => element = "%identity"; /* this function exists to prepare for making `component` abstract */ external component: componentLike('props, element) => component('props) = @@ -26,7 +28,7 @@ external createElementVariadic: [@mel.module "react/jsx-runtime"] external jsxKeyed: - (component('props), 'props, ~key: string=?, unit) => element = + (component('props), 'props, ~key: string=?, unit) => elementKeyed = "jsx"; [@mel.module "react/jsx-runtime"] diff --git a/src/ReactDOM.re b/src/ReactDOM.re index 42b3a5777..5a7ee6854 100644 --- a/src/ReactDOM.re +++ b/src/ReactDOM.re @@ -1535,7 +1535,7 @@ external createDOMElementVariadic: "createElement"; [@mel.module "react/jsx-runtime"] -external jsxKeyed: (string, domProps, ~key: string=?, unit) => React.element = +external jsxKeyed: (string, domProps, ~key: string=?, unit) => React.elementKeyed = "jsx"; [@mel.module "react/jsx-runtime"] diff --git a/src/ReactDOM.rei b/src/ReactDOM.rei index d6cbd26d4..c4ca10615 100644 --- a/src/ReactDOM.rei +++ b/src/ReactDOM.rei @@ -1536,7 +1536,7 @@ external createDOMElementVariadic: "createElement"; [@mel.module "react/jsx-runtime"] -external jsxKeyed: (string, domProps, ~key: string=?, unit) => React.element = +external jsxKeyed: (string, domProps, ~key: string=?, unit) => React.elementKeyed = "jsx"; [@mel.module "react/jsx-runtime"] diff --git a/test/Hooks__test.re b/test/Hooks__test.re index 20b942a46..aba4a17a4 100644 --- a/test/Hooks__test.re +++ b/test/Hooks__test.re @@ -55,7 +55,7 @@ module DummyStatefulComponent = { let make = (~initialValue=0, ()) => { let (value, setValue) = React.useState(() => initialValue); - ; }; diff --git a/test/React__test.re b/test/React__test.re index 8b26c8339..e9f44053d 100644 --- a/test/React__test.re +++ b/test/React__test.re @@ -283,9 +283,12 @@ describe("React", () => { act(() => { ReactDOM.Client.render( root, - -
"Child"->React.string
-
, + [| + +
"Child"->React.string
+
, + |] + ->React.array, ) }); @@ -309,9 +312,12 @@ describe("React", () => { }; let render = author => -
-
-
; + [| +
+
+
, + |] + ->React.array; act(() => { ReactDOM.Client.render(