Skip to content

@react.componentWithProps with use memo #7300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Exploring problem space
  • Loading branch information
nojaf committed Feb 17, 2025
commit 7c0af6e57f641a296cf786e9771475135d8f0f08
6 changes: 4 additions & 2 deletions compiler/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
in
(Some props_record_type, binding, new_binding))
else if Jsx_common.has_attr_on_binding Jsx_common.has_attr_with_props binding
then
then (
let modified_binding =
{
binding with
Expand All @@ -1198,6 +1198,8 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
make_module_name file_name config.nested_modules fn_name
in

Format.printf "Yow %s\n" full_module_name;

let is_async =
Ast_async.dig_async_payload_from_function modified_binding.pvb_expr
in
Expand Down Expand Up @@ -1283,7 +1285,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
binding with
pvb_attributes = binding.pvb_attributes |> List.filter other_attrs_pure;
},
new_binding )
new_binding ))
else (None, binding, None)

let transform_structure_item ~config item =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,17 @@ module V4A6 = {
\"SharedPropsWithProps$V4A6"
}
}

module V4A7 = {
type props = {count: int}

let make =
@directive("'use memo'")
props => {
React.int(props.count)
}
let make = {
let \"SharedPropsWithProps$V4A7" = props => make(props)
\"SharedPropsWithProps$V4A7"
}
}
10 changes: 10 additions & 0 deletions tests/syntax_tests/data/ppx/react/sharedPropsWithProps.res
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ module V4A6 = {
}
}
}

module V4A7 = {
type props = {count: int}

@react.componentWithProps
let make = @directive("'use memo'")
props => {
React.int(props.count)
}
}
12 changes: 12 additions & 0 deletions tests/tests/src/alias_default_value_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ let C7 = {
make: Alias_default_value_test$C7
};

function make(props) {
'use memo';
return props.count;
}

let Alias_default_value_test$C8 = make;

let C8 = {
make: Alias_default_value_test$C8
};

export {
C0,
C1,
Expand All @@ -90,5 +101,6 @@ export {
C4,
C6,
C7,
C8,
}
/* No side effect */
11 changes: 11 additions & 0 deletions tests/tests/src/alias_default_value_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ module C7 = {
React.string(`Hello ${name}, you clicked me ` ++ times)
}
}

module C8 = {
type props = {count: int}

@react.componentWithProps
let make =
@directive("'use memo'")
props => {
React.int(props.count)
}
}
Loading