Repository navigation
JSX preserve mode: fix "make is not a valid component name" - #7831
Conversation
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
nojaf
left a comment
There was a problem hiding this comment.
Thanks for your continued efforts to resolve this.
Could you add a new test case using the example from #7432?
I also think this code no longer makes sense because of that change:
rescript/compiler/syntax/src/jsx_v4.ml
Lines 96 to 108 in a09a3d7
Transforming make to FileName$ModuleName appears irrelevant now since that won't be called anymore.
Given this, should this behavior become the default regardless of preserve JSX? If so, the work in #7203 could be undone.
The uppercase function name is relevant for the React devtools. Otherwise all your components will have the name "make" there. Also, React Compiler does not recognize lowercase component functions. |
|
I assumed wrongly that the React compiler would follow function make(props) {
return null;
}
let C = {
make: make
};
let c = <C.make />;The |
0d4cc14 to
941b636
Compare
nojaf
left a comment
There was a problem hiding this comment.
I'll leave this to @cristianoc. I can't quite tell whether it's harmless, so I suggested a few changes to tighten it up. Think of them as ideal-world tips since I'm not sure they're all feasible.
| *) | ||
| match Ext_list.nth_opt ls (Int32.to_int i) with | ||
| (* 7432: prevent optimization in JSX preserve mode *) | ||
| | Some {expression_desc = J.Var (Id {name = "make"})} |
There was a problem hiding this comment.
This check could in theory affect each make function right?
Could we add some sort of check if that make returns a Jsx.element type? Just to further limit the scope when this kicks in.
There was a problem hiding this comment.
there's no type this down the compiler stack
| (* 7432: prevent optimization in JSX preserve mode *) | ||
| | Lprim | ||
| { | ||
| primitive = Pjs_call {prim_name = "jsx" | "jsxs"} as primitive; |
There was a problem hiding this comment.
Same remark, very unlikely that jsx is not going to come from ReactRuntime call, if we can further tighten it that be great.
There was a problem hiding this comment.
I think it's plenty guarded against risk already
There was a problem hiding this comment.
why not the same check that preserve mode is on?
I guess it's kind of implicit, and only a super corner case would have the same name, but since it's so easy to add why not
There was a problem hiding this comment.
The check for preserve mode is already there (below).
| referrerPolicy={"strict-origin-when-cross-origin"} | ||
| />; | ||
|
|
||
| function make(_props) { |
There was a problem hiding this comment.
Thanks for adding the tests!
cristianoc
left a comment
There was a problem hiding this comment.
looks plenty safe -- good to go for me
nice fix!
| (* 7432: prevent optimization in JSX preserve mode *) | ||
| | Lprim | ||
| { | ||
| primitive = Pjs_call {prim_name = "jsx" | "jsxs"} as primitive; |
There was a problem hiding this comment.
I think it's plenty guarded against risk already
| (* 7432: prevent optimization in JSX preserve mode *) | ||
| | Lprim | ||
| { | ||
| primitive = Pjs_call {prim_name = "jsx" | "jsxs"} as primitive; |
There was a problem hiding this comment.
why not the same check that preserve mode is on?
I guess it's kind of implicit, and only a super corner case would have the same name, but since it's so easy to add why not
|
I tested against a large project, and the changes looked fine to me. BTW, if I remove the checks for the JSX preserve mode and do |
…-lang#7831) * JSX preserve mode: fix "make is not a valid component name" * More selective fix for lam_pass_remove_alias * Selective fix for js_pass_flatten_and_mark_dead * Add tests * CHANGELOG Signed-off-by: Pedro Castro <aspeddro@gmail.com>
Closes #7432 by disabling two optimization when in JSX preserve mode.
Ideally, the optimization should only be disabled for actual JSX expressions, but I have not found how to do that yet.