-
Notifications
You must be signed in to change notification settings - Fork 470
JSX Preserve Mode #6197
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
Comments
This would be very nice to have to build server side apps. The Bun JS runtime has built-in JSX support, and using libraries like https://github.com/nicojs/typed-html or https://github.com/kitajs/html you could render static HTML and serve it from the server without the need for more complicated SSR setups like Next.JS. |
@cornedor unrelated to this specific issue, but since you wrote this - I'm working on something like this, but without JSX preserve mode and just using ReScript's built in JSX support. Server side templating but with JSX and components like in React. Soon ready for alpha. |
I would love to see rescript be used with solidjs. If it's possible to get this done, I am willing to work on a PR if the maintainers are for it. |
Theoretically closed by #6565 (from announcement). |
I don't think it is. 😉 There will be cases where the generic transformation is not enough to solve. |
Example would be helpful for others like me following 🙏🏼 |
@texastoland for Solid the issue is that Solid ships their own Babel transform, that turns actual JSX into Hope that helps! |
Preserve mode seems to be required for React Compiler (as of today at least). |
I'm a bit stumped on how this could be implemented. To get started, I’m going to jot down some thoughts and questions: Assuming you want to preserve the JSX, I would expect the ppx transform not to activate. This means that new After type-checking, some additional processes occur (optimizations, lambdas), but I assume nothing significant would happen there. Finally, we would print the typed JSX node back to JSX text in the js_printer. @cristianoc, would that be more or less what needs to happen? |
Is there a way to annotate what's produced by the JSX transform so that we can follow it all the way to what actually emits this code:
And then match on that to produce JSX instead of the function call? |
That feels a bit messy, as you transformed items only to transform them back later. Yes, we could potentially add an additional attribute to mark the JSX transform; however, I'm not sure this is necessary. It might also capture some React semantics that we may want to keep more agnostic. |
Whether the jsx transform can be moved to later phases in the compiler is a good question, I think. |
Latest attempt can be found over at #7387. |
Hello, During the ReScript Retreat, we achieved an initial (rough) version of preserving JSX code in the JavaScript output. This is not the final version we plan to ship in v12, and we welcome your feedback to determine its viability and identify any remaining gaps. InstallationYou will need the latest v12 version from the master branch of the compiler. Install it via the npm i https://pkg.pr.new/rescript-lang/rescript@362a1da In your {
"suffix": ".res.jsx",
"jsx": {
"version": 4
},
"bsc-flags": [
"-bs-jsx-preserve"
]
} The Known Limitations and Open QuestionsWe are aware of several limitations, and depending on your feedback, we will address them:
React CompilerI tried this in my own project and can confirm that the React compiler worked as expected. SolidThis new feature should enable the use of Solid. We haven't tested this yet, so we would welcome a community sample! |
Hi folks, There's still some UX work to be done here. Currently, the Initially, we considered adding a boolean to the
This approach works, but some tooling scenarios will require the Should we address this? What do people think? Perhaps this isn’t a significant issue for most. One possible solution could be to have something like this:
This would allow us to use that extension if we detect a JSX transform we want to preserve. Please let us know your thoughts! |
Could the compiler determine when preserve mode is active and used, on a file, and emit the |
We could set some global-ish flag if we detected something in the jsx ppx transform. |
Uh oh!
There was an error while loading. Please reload this page.
I would like to initiate a discussion on a potential feature: Preserve Mode for JSX expressions. The Preserve Mode is a functionality that, when enabled, maintains the original formatting and structure of JSX expressions in the JavaScript output generated by the compiler.
As the ReScript ecosystem evolves, it is worth exploring whether introducing Preserve Mode for JSX expressions to the compiler would be beneficial for the community. This feature could potentially enhance the readability and maintainability of the compiled output containing JSX, making it easier for developers to work with and understand the generated code. Another significant advantage of Preserve Mode is the possibility of using ReScript with frameworks like Preact and SolidJS, expanding the reach and applicability of the language.
Please share your thoughts and experiences regarding the necessity and potential benefits of implementing Preserve Mode for JSX expressions in the ReScript compiler. Do you think it is a valuable addition, or are there any concerns or technical challenges that might arise from its implementation?
preserved JSX
The text was updated successfully, but these errors were encountered: