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

React 18 conditional support #1449

Closed
wants to merge 4 commits into from

Conversation

tomdracz
Copy link
Contributor

@tomdracz tomdracz commented Apr 25, 2022

Another stab at #1441


This change is Reviewable

@@ -213,6 +211,7 @@ function unmount(el: Element): void {
const domNode = document.getElementById(domNodeId);
if(domNode === null){return;}
try {
// Might need updating? https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unmountComponentAtNode is considered legacy https://reactjs.org/docs/react-dom.html#unmountcomponentatnode but would need to store references to root instead if we were to update

Copy link
Contributor

Choose a reason for hiding this comment

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

Please see #1466.

toExport = legacyRootHandler;
} else {
toExport = modernRootHandler;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Struggling to find a nicer way to get this going, can't think of a way to do a dynamic import and then reexport

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be fairly trivial with top-level await though 🤔


let toExport;

if (supportsReactCreateRoot) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be good based not only on React version but also some configuration option so it's an opt-in

@tomdracz
Copy link
Contributor Author

Also worth noting reactwg/react-18#125 (reply in thread) and multiple roots (which is what we're doing) being discouraged, although not a great info on "why"

@summera
Copy link

summera commented Apr 26, 2022

Also worth noting reactwg/react-18#125 (reply in thread) and multiple roots (which is what we're doing) being discouraged, although not a great info on "why"

I also noticed this while working on #1448. @justin808 would switching to portals be an option for react_on_rails?

@tomdracz
Copy link
Contributor Author

Also worth noting reactwg/react-18#125 (reply in thread) and multiple roots (which is what we're doing) being discouraged, although not a great info on "why"

I also noticed this while working on #1448. @justin808 would switching to portals be an option for react_on_rails?

Don't think portals are suitable here, would normally use them for some modals and overlays rather than full component trees. It doesn't seem like the docs discourage it anywhere, so apart from that one comment, there's no clear rationale and options from React team. Probably good to leave as is for now

@tomdracz
Copy link
Contributor Author

@Judahmeek @justin808 any of you able to trigger the tests to see the output?

Copy link
Member

@justin808 justin808 left a comment

Choose a reason for hiding this comment

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

Looks fantastic with a quick code review!

@tomdracz I like your coding style a lot!

Reviewed 8 of 9 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @tomdracz)


node_package/src/clientStartup.ts line 214 at r1 (raw file):

Previously, tomdracz (Tom Dracz) wrote…

unmountComponentAtNode is considered legacy https://reactjs.org/docs/react-dom.html#unmountcomponentatnode but would need to store references to root instead if we were to update

Agree. It looks like there is more to do: reactwg/react-18#5.

Consequently, I'm not sure we should use the new createRoot API until we're confident that ReactOnRails is ready, as that is why the old behavior is available.


node_package/src/helpers/renderHelper.ts line 12 at r1 (raw file):

Previously, tomdracz (Tom Dracz) wrote…

Would be fairly trivial with top-level await though 🤔

Looks great so far!


node_package/src/helpers/renderHelper.ts line 8 at r2 (raw file):

Previously, tomdracz (Tom Dracz) wrote…

This could be good based not only on React version but also some configuration option so it's an opt-in

100% agree! Given what I wrote in the previous comment of us not being 100% sure that we're fully ready!

@justin808
Copy link
Member

@tomdracz we've got CI fixed. Is this one ready to go?

@alexeyr-ci1 alexeyr-ci1 mentioned this pull request Jun 27, 2022
4 tasks
@alexeyr-ci1
Copy link
Contributor

#1460 has been merged instead.

@alexeyr-ci1 alexeyr-ci1 closed this Jul 1, 2022
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.

4 participants