rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Proposal for JSX Upgrades

Open rickyvetter opened this issue 3 years ago • 3 comments

I'm looking to make two changes to the ppx that would be breaking and want to use this as a place to discuss strategy.

Changes

  1. instead of compiling to React.createElement, compile to React.jsx/s In React 17 there is a new compile target for jsx which provides a better api (no overloading, special treatment for keys, eventual normal treatment of refs) for us to work with in Reason. Chnaging the JSX to target React.jsx/s is a breaking change in that it requires users to use React 17 (which itself is labelled as not breaking, but it doesn't force people over to JSX which could have bugs/issues).

  2. Instead of compiling <div to ReactDOMRe.createElement("div", compile to custom elements with the correct props. The pros here are that we can have type safety with regards to valid elements and props. This is breaking change but only for folks that are using elements/props that aren't in the HTML spec or supported by React.

Plan

I have the work for 1 complete and I think since they are both breaking it would be better to batch them together. Today I see two options for release: we could wait for breaking ReScript version change, or we could add a new jsx version to the config. Waiting for ReScript version change makes things a bit more seamless but means we tie JSX changes to the ReScript lifecycle quite closely. Adding a config to switch is a bit more overhead for folks but means that we can ship the features as they are available.

Thoughts on best way to proceed?

rickyvetter avatar Aug 14 '20 17:08 rickyvetter

Combining changes 1 and 2 make sense to me, and I am looking forward to them. 👍

However, I think a config switch would be better than tying this to a specific ReScript version because

  1. As you said, even if React 17 itself is not breaking, using React.jsx instead of React.createElement could cause issues. So IMHO this should be a transition that people need to make explicitly and independently of a ReScript version update.
  2. There is no React Native release supporting React 17 yet, so people using reason-react-native will not be able to use the new jsx version in their projects yet, but will probably want to use the latest ReScript version.

cknitt avatar Aug 15 '20 06:08 cknitt

A config switch looks good to me

bobzhang avatar Aug 18 '20 04:08 bobzhang

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 10 '22 02:08 stale[bot]