Skip to content

Commit 35e1601

Browse files
committed
syntax/jsx_v4: fix forwardRef arity regression; mark internal impl uncurried when forwardRef is used (#7738)
- Fix JSX v4 React.forwardRef arity regression seen in v12. - When forwardRef is used, make the internal implementation uncurried with arity 2. - Add regression test tests/tests/src/forwardRef_regress.res (JSX v4 enabled).
1 parent ed425d8 commit 35e1601

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/syntax/src/jsx_v4.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
733733
| _ -> Pat.record (List.rev patterns_with_label) Open
734734
in
735735
let expression =
736+
(* Shape internal implementation to match wrapper: uncurried when using forwardRef. *)
736737
Exp.fun_ ~arity:(Some 1) ~async:is_async Nolabel None
737738
(Pat.constraint_ record_pattern
738739
(Typ.constr ~loc:empty_loc
@@ -748,6 +749,10 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
748749
| _ -> [Typ.any ()]))))
749750
expression
750751
in
752+
let expression =
753+
if has_forward_ref then expression |> Ast_uncurried.uncurried_fun ~arity:2
754+
else expression
755+
in
751756
let expression =
752757
(* Add new tupes (type a,b,c) to make's definition *)
753758
newtypes
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@@config({flags: ["-bs-jsx", "4"]})
2+
3+
@react.component
4+
let make = React.forwardRef((~className=?, ~children, _ref) => {
5+
// Constrain type variables to avoid value restriction
6+
let _: option<string> = className
7+
children
8+
})

0 commit comments

Comments
 (0)