Split into multiple packages?
cknitt opened this issue · comments
- With JSX4 bringing breaking changes, the JSX3 bindings have been moved into a separate namespace ReactV3. I was wondering if this ReactV3 namespace shouldn't better be provided by some compatibility package.
@rescript/react
currently includes bindings for bothreact
andreact-dom
and also has both as peer and dev dependencies. However, not every React project is also using React DOM. E.g. React Native projects aren't. So IMHOreact-dom
bindings should go into their own package.- #33 mentions the idea to split out ReScriptReactRouter into a separate package.
If we did all that, we'd end up with something like
@rescript/react
@rescript/react-dom
@rescript/react-jsx3-compat
@rescript/rescript-react-router
(or justrescript-react-router
?)
@mattdamon108 @cristianoc What do you think? How would such a split affect the PPX?
The issue is while transitioning to V4 you might want to do that gradually.
That means having both V3 and V4 used in the same project.
So you install latest rescript-react and use open ReactV3
where needed.
I think that it is a better choice that ReactV3
is shipped with the latest rescript-react
because it is could be used in the same project.
Regarding dom and router, IMHO, splitting rescript-react
and rescript-react-dom
could get some benefit for users to install separately as per their project needs. e.g. React Native as @cknitt says. That is what the react team does. The same story for rescript-react-router.
@mattdamon108 Ok, but ReactV3 also includes ReactDOM.
Would it be possible to have
- @rescript/react (including ReactV3 compatibility module - without the DOM stuff)
- @rescript/react-dom (including ReactDOMV3 compatibility module)
- @rescript/rescript-react-router
?
@cknitt Yes, it is possible, but not a simple task as we're expecting. Currently ReactDOM
has not only react-dom
apis, also has dom
related apis, such as Ref
, domProps
, createElement
for dom element. If we make a decision to align to the react, react-dom, and separate bindings accordingly. We have to move all the unrelated modules and types to React.res
and ReactV3.res
. I'm afraid it would make users have to change their existing code much more due to this splitting.
First thing came to mind is that ReactDOM.Ref.*
-> React.DOM.Ref.*
seems inevitable.
V3 -> V4 migration period seems quite a good timing to split the bindings though.
There is a change budget for each transition, the more changes one introduces, the harder the transition becomes.
I have pushed a lot trying to not have to change rescript-react at all during the V3 -> V4 transition, but it was just too difficult.
I'm afraid there's no budget for more changes at the same time.
In any case, this change requires deprecation, following by changes later on. So will have to be split across 2 phases.
Another possible direction, which was explored for a while, but can be explored more if now things are more stable with JSX V4, is to move more of rescript-react into the compiler.
That might open the way to only have the rest (ie what's not in the compiler) in separate packages.