Skip to content
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

Re-organise the modules #794

Merged
merged 7 commits into from
Oct 13, 2023
Merged

Re-organise the modules #794

merged 7 commits into from
Oct 13, 2023

Conversation

davesnx
Copy link
Member

@davesnx davesnx commented Oct 11, 2023

As discussed here: #770

This file explains the new organisation of modules: https://github.com/reasonml/reason-react/blob/Unwrap-and-minimize-toplevels/src/README.md

  • wrapped false and inlining most of the modules makes the interface a little cleaner for the users. On the other side, we have huge modules (which isn't so bad, but that it just my opinion)

  • Moved all interface from React.rei into it's own module

  • I didn't took any decision on ErrorBoundary, neither ReasonReactRouter. I got the feeling that we should rename those as SimpleErrorBoundary and SimpleRouter or similar. I would be fine to rename ReasonReactRouter to Router

Welcome to the source of ReasonReact!
### Welcome to the source of ReasonReact

We want to expose as minimum modules to the toplevel as possible, and at the same time want to map closely to the npm packages. So each module maps to a npm package, and each sub-module maps to a sub-module. For example: `react-dom` -> `ReactDOM` and `react-dom/server` -> `ReactDOM.Server`.

Files overview:

## Bindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for writing this up. it's very clear.

you may want to check the rendering before merging, as the nested bullets aren't rendered as you'd expect.

- `ReasonReactRouter`: a simple, yet fully featured router with minimal memory allocations
- `ErrorBoundary`: component to catch errors within your component tree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this one become React.ErrorBoundary, or do you want it to stay out at the toplevel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React.ErrorBoundary sounds nice to keep like it was before, but I dislike the idea of having it unsafe and part of the React module.

I proposed the renaming of SimpleErrorBoundary to make it clearer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then I'm fine taking the time to think about this, and keeping it ReasonReactErrorBoundary for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds perfect

src/React.re Outdated
([@mel.uncurry] (unit => 'any), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'any =
"useMemo";

/* This is used as return values */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for type callback('input, 'output). which is no longer here

Suggested change
/* This is used as return values */
/* This is used as return values */

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this and added into the React.Uncurried callback

@@ -195,7 +195,7 @@ external useSyncExternalStore:
[@mel.module "react"]
external useSyncExternalStoreWithServer:
(
~subscribe: (([@mel.uncurry] (unit => unit)) => ([@mel.uncurry] (unit => unit))),
~subscribe: ([@mel.uncurry] (unit => unit)) => [@mel.uncurry] (unit => unit),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refmt did this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@@ -1,6 +1,10 @@
(library
(name react)
(public_name reason-react)
(wrapped false)
; Explicitly adding modules isn't necessary, but it's a good idea
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea 👍

Copy link
Member

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking very nice

Copy link
Member

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decide what to name errorBoundary.re -- I propose ReasonReactErrorBoundary to give it a long, unique name.

thanks for working on this

@davesnx
Copy link
Member Author

davesnx commented Oct 13, 2023

We would need to make a proper release notes with the module changes, but should be small.

@davesnx davesnx merged commit 3ab8747 into main Oct 13, 2023
3 checks passed
@anmonteiro anmonteiro deleted the Unwrap-and-minimize-toplevels branch October 13, 2023 22:36
@joprice
Copy link

joprice commented Oct 15, 2023

@davesnx I'm seeing react-dom/test-utils and react-dom/server getting pulled in by vite during development with this change. Without some sort of change in melange to only import referenced submodules, maybe new modules like ReactDOMServer and ReactDOMTestUtils are necessary to avoid this?

@davesnx
Copy link
Member Author

davesnx commented Oct 15, 2023

Splitting those into modules might make sense to avoid this issue. Would this problem fade away in production builds, where those modules would be gone with tree-shaking?

I would like to now how other bundlers handle dev/prod optimisations like this one, to decide if it's a good solution

@joprice
Copy link

joprice commented Oct 16, 2023

I didn't get that far, since vite didn't like the require calls in the server-side commonjs modules. Not sure these particular ones will be shaken away, since I think purity of the module affect tree-shaking as well and would have to check that. I think either way, it's unexpected to pull in test utils or, in general, something you didn't intend to import, even in dev.

davesnx added a commit to davesnx/opam-repository that referenced this pull request Feb 10, 2024
CHANGES:

* Wrap the `React` library, exposing just a single top-level module
  (@anmonteiro in [reasonml/reason-react#783](reasonml/reason-react#783))
* Re-organise toplevel modules (@davesnx in [reasonml/reason-react#794](reasonml/reason-react#794))
* Require and adapt to Melange v3 (@anmonteiro in [reasonml/reason-react#821](reasonml/reason-react#821))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants