Skip to content

Re-organise the modules#794

Merged
davesnx merged 7 commits into
mainfrom
Unwrap-and-minimize-toplevels
Oct 13, 2023
Merged

Re-organise the modules#794
davesnx merged 7 commits into
mainfrom
Unwrap-and-minimize-toplevels

Conversation

@davesnx

@davesnx davesnx commented Oct 11, 2023

Copy link
Copy Markdown
Member

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

Comment thread src/README.md

Files overview:

## Bindings

Copy link
Copy Markdown
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.

Comment thread src/README.md
- `ReactTestUtils`: helpers for testing your components
- `ReasonReactErrorBoundary`: component to catch errors within your component tree
- `ReasonReactRouter`: a simple, yet fully featured router with minimal memory allocations
- `ErrorBoundary`: component to catch errors within your component tree

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds perfect

Comment thread 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
Copy Markdown
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
Copy Markdown
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

Comment thread src/React.rei
external useSyncExternalStoreWithServer:
(
~subscribe: (([@mel.uncurry] (unit => unit)) => ([@mel.uncurry] (unit => unit))),
~subscribe: ([@mel.uncurry] (unit => unit)) => [@mel.uncurry] (unit => unit),

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes

Comment thread src/dune
(name react)
(public_name reason-react)
(wrapped false)
; Explicitly adding modules isn't necessary, but it's a good idea

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great idea 👍

@anmonteiro anmonteiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looking very nice

@anmonteiro anmonteiro left a comment

Copy link
Copy Markdown
Member

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

davesnx commented Oct 13, 2023

Copy link
Copy Markdown
Member Author

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
@anmonteiro anmonteiro deleted the Unwrap-and-minimize-toplevels branch October 13, 2023 22:36
@joprice

joprice commented Oct 15, 2023

Copy link
Copy Markdown

@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

davesnx commented Oct 15, 2023

Copy link
Copy Markdown
Member Author

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

joprice commented Oct 16, 2023

Copy link
Copy Markdown

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.

3 participants