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 concurrent render functions / removal of findDOMNode / test updates #2330

Closed
wants to merge 6 commits into from

Conversation

edkimmel
Copy link
Contributor

@edkimmel edkimmel commented Jul 6, 2022

Looking to resolve the issues pointed out by #1529

The breaking changes come from the deprecation / removal of findNodeHandle, which doesn't appear to be a strictly necessary change to support React 18. Let me know if I should revert those changes.

  • Bump React dependency to 18.

  • Remove uses of findNodeHandle. Remove direct uses of findDOMNode. Marked findNodeHandle as deprecated for uses outside of this library

    • TouchableMixin has a new required function on the user - getTouchableNode - which returns the dom node of the touchable element.
    • ScrollResponderMixin no longer has the imperative findNodeHandle fallback, the dom node must be provided by getScrollableNode
  • Support for concurrent mode in AppRegistry

    • This required swapping to a callback ref on AppContainer as the callback parameter to the new render/hydrate calls was removed.
  • Using react testing library's render and act functions in tests

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 6, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bfab947:

Sandbox Source
react-native-web-examples Configuration

Copy link
Owner

@necolas necolas left a comment

Choose a reason for hiding this comment

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

Thanks! This looks pretty good

Comment on lines +76 to +78
* getTouchableNode: function() {
* return this.touchableRef.current
* }
Copy link
Owner

Choose a reason for hiding this comment

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

Where is this used / implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guidance from React is to remove findDOMNode and use React.Ref instead. The Touchable and ScrollResponder mixins don't render themselves, so they become dependent on the concrete component to capture the root to a ref and provide it.

I didn't see any uses of Touchable directly in this repository, so that seems to be only a user-facing breaking change. Nothing in this repository actually implements it.

ScrollResponderMixin was used by ScrollView, which already provided getScrollableNode. It appears that it would only be user components using ScrollResponderMixin that would have to be sure to implement getScrollableNode now.

Copy link
Owner

Choose a reason for hiding this comment

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

I think after this is merged, it will also be a good time to remove those mixins as a legacy feature that will not carry forward with React 18 adoption.

packages/react-native-web/package.json Outdated Show resolved Hide resolved
@necolas
Copy link
Owner

necolas commented Jul 6, 2022

The unmountComponentAtNode export probably also needs rethinking for the new root API.

@edkimmel
Copy link
Contributor Author

edkimmel commented Jul 7, 2022

The unmountComponentAtNode export probably also needs rethinking for the new root API.

ReactDom does warn/error when that is called on a container used by createRoot. Someone using legacy mode is fine to call that method.

We may have to provide some method of communicating to the root created by the new createRoot / hydrateRoot calls though?

@edkimmel
Copy link
Contributor Author

edkimmel commented Jul 7, 2022

Does this mean we can use strict mode now? IIRC, that was one of the existing issues last time we looked into it.

Removing findDOMNode is a step towards react-native-web working under strict mode.

The other two I can think of are:

  1. Remove all use of legacy context API #1506 - legacy context APIs
  2. Uses of UNSAFE_componentWillMount and UNSAFE_componentWillReceiveProps

@necolas necolas added this to the 0.20: React 18 milestone Jul 8, 2022
@edkimmel
Copy link
Contributor Author

edkimmel commented Jul 11, 2022

@necolas I pushed a small change + test to return an object containing an unmount method from runApplication. It hides whether we used react 17 or 18 render/hydrate methods and can be used to expose access to the new root object returned by react 18 methods.

necolas pushed a commit that referenced this pull request Aug 26, 2022
* Support React 18 concurrency and constraints.
* Add new render / hydrate functions.
* Remove uses of findNodeHandle.
* Expose ability to unmount an application once ran.

Fix #1529
Close #2330
@necolas necolas added the has: pr Subject of a pull request label Aug 26, 2022
necolas pushed a commit that referenced this pull request Aug 30, 2022
* Support React 18 concurrency and constraints.
* Add new render / hydrate functions.
* Remove uses of findNodeHandle.
* Expose ability to unmount an application once ran.

Fix #1529
Close #2330
@edkimmel edkimmel force-pushed the react-18-deprecation-fixes branch from bf36608 to bfab947 Compare October 7, 2022 20:05
@edkimmel
Copy link
Contributor Author

@necolas Should I close this PR? I just saw the commit on 0.19-dev referencing this PR.

@JinbeiStudio
Copy link

Do you know on which update this will be fixed ? Thank you !

@edkimmel
Copy link
Contributor Author

Do you know on which update this will be fixed ? Thank you !

@JinbeiStudio This is part of 0.19 #2377

I don't know when that release is expected to go out.

necolas pushed a commit that referenced this pull request Nov 28, 2022
* Support React 18 concurrency and constraints.
* Add new render / hydrate functions.
* Remove uses of findNodeHandle.
* Expose ability to unmount an application once ran.

Fix #1529
Close #2330
@MalgoBlock

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: pr Subject of a pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants