-
Notifications
You must be signed in to change notification settings - Fork 465
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
[RFC] Generic JSX transform #6408
Comments
I also think this could unlock quite a lot of innovation for rescript, I'm all for it. Could you detail in this example what part belongs to the JSX PPX transform? Is it the |
This seems quite feasible. Is there any particular reason to use jsx.customModule instead of using jsx.module="MyCustomModule" in the current compiler config? |
@mununki that would work well too. My thinking was mostly that React is special cased there, but that probably doesn't matter. Putting it directly in |
Maybe we can get even further than just custom prop types in this RFC. There is
Which allows to user overriding not only props, but also elements. So custom renderers like react-three-fiber can provide type definitions for their own host element (e.g. There is a few points to change for this:
|
Out of all the feature requests and proposals for improvement this would have the largest impact on the ability to adopt ReScript. Being able to use it for things other than React would be huge! |
Currently occupied with other things, but maybe me and @mununki could pair on this and get an implementation going that we can test. |
We definitively need a solution for this, it's great feedback. I just wonder if this should perhaps be a "step 2" thing in this proposal. |
@mununki I had a fairly thorough look at the existing JSX code and I think adding a generic one looks pretty straight forward. But, we need to make some assumptions. Here's a list of things I thought about when reading the code.
@mununki what do you think? |
Totally agree with your assumption. I think preserve mode should definitely be implemented. |
Started working on a generic transform here: #6565 Please leave any feedback you might have. |
I have used this one. |
Cool! Perfect example of something that would be very easy to set up with the generic transform. |
I'm proposing a generic JSX transform where you bring your own JSX assets (functions to call, types for JSX nodes, etc), that ReScript can delegate to. This will both enable slicker integration with other FE frameworks than React that also use JSX, and enable innovation since JSX is just syntax sugar for function calls.
JSX is an XML-style syntax that's great for templating hierarchical things like HTML, while preserving the full strength of ReScript in your templating. With a generic JSX transform, one could leverage the fact that JSX is part of the ReScript language to build your own things leveraging ReScript's great JSX support. I believe this could unlock some innovation.
Background
We currently have a great React JSX transform in ReScript, including the
@react.component
transform for component support. This works well for React. It's possible to use the React JSX transform with other frameworks today by carefully overriding theReact
,ReactDOM
andJsx*
modules. However, this is cumbersome, error prone, and is a hack.Prior art
TypeScript let's you configure various things related to JSX: https://www.typescriptlang.org/tsconfig#jsxFactory
Proposal
I propose a simple way of swapping out the React JSX transform to your own custom one, and additionally a dedicated
@jsx.component
transform.Configure a custom JSX module in
bsconfig.json
MyJsxModule
is then what the JSX PPX delegates to for all JSX related functionality.@jsx.component
A generic component transform that gives the same ergonomic experience as
@react.component
, but with none of the React specific quirks. We'll need to figure out which of the quirks belong in the generic PPX.Complete example
Here's a sketch of a complete example of how this could look. Note: Hyperons is a lightweight lib for rendering JSX to a string of HTML.
bsconfig.json
Ending thoughts
It'll be important to ensure that all of this works seamlessly, including things like autocomplete via the editor integration for both user defined components and lowecase "HTML" dom nodes.
Interested in hearing any feedback really.
The text was updated successfully, but these errors were encountered: