In several Blog Posts it was announced that React 19 will include it’s own optimizing compiler.
I was wondering how this will fit into the bigger picture in projects that use rescript and didn’t manage to find any existing discussions about this.
Are they mutually exclusive? Are they sequential?
If I adopt rescript for a react project - will I be able to benefit from React 19 once it comes out or will I be locked down to React 18 forever?
The core of the compiler is almost completely decoupled from Babel, and the core compiler API is (roughly) old AST in, new AST out (while retaining source location data). Under the hood we use a custom code representation and transformation pipeline in order to do low-level semantic analysis. However, the primary public interface to the compiler will be via Babel and other build system plugins.
I wonder if that core is binary or JS. I mean, whatever is done via a Babel plugin can be redone as a PPX, but reusing the logic vendored by React team is likely much better.
I was curious to see how the latest version of Rescript works with the new React compiler, so I’ve managed to setup a minimal project with Next (raw js, typescript added some build complexities). So far it seems that compiled rescript components won’t be memo’d by the new compiler, unfortunately. I assume it happens due to them being compiled to jsx-runtime, which React can’t apply performance updates to. Maybe if we could preserve JSX output from Rescript it might’ve worked.
npm install --force because Rescript dependencies point to React 18.
npx rescript build to generate .jsx component
npm run dev to start the next project.
if you are forking the sandbox - open the page in the new window, otherwise CodeSandbox won’t show new compiler messages. If you are running it locally - just open the project url.
Using react component tab in chrome you can see that all components except Rescript were successfully memo’d by the compiler.
This has nothing to do with JSX or plain function calls. It’s because ReScript 11 still compiles to var assignments. If you change the vars in the compiled output JSX file to let, it should work.
- var match = React.useState(function () {
+ let match = React.useState(function () {
return 0;
});
- var setState = match[1];
+ let setState = match[1];