Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

React 18 Support #2241

Merged
merged 18 commits into from
Jun 8, 2022
Merged

React 18 Support #2241

merged 18 commits into from
Jun 8, 2022

Conversation

ryanwilsonperkin
Copy link
Member

@ryanwilsonperkin ryanwilsonperkin commented Apr 22, 2022

Description

Base branch for React 18 support. Aiming to add support for React 18 to any libraries that web uses while maintaining backwards compatibility for React 17 since these libraries are still being used by other applications.

Child branches will tackle individual packages/features like @shopify/react-testing, @shopify/react-router, etc

See previous effort: #2112

Fixes (issue #)

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • react-testing Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above (Documentation fix and Test update does not need a changelog as we do not publish new version)

Need to account for the changes to the
children-are-no-longer-implicit-in-components typing that's in more
recent versions
New version required to appropriately perform reflection on v18
Needs to match the major version that we're using in our main app or
else the versions of React will clash and the a11y test runner doesn't
work correctly.
Loom typically looks for setupFiles under tests/setup/environment.* but
we have ours under the additional sub-directory of src/ because of the
way that react-testing lays out its own tests.
The previous ReactDOM.render method is deprecated and instead tests
should be making use of createRoot to generate a "Root" element and then
calling render/unmount on that.

This causes some confusion here because we already have a concept of a
"Root" in react-testing, and so we use the name "reactRoot" to
differentiate here.
Ensure that we're awaiting the promise within the scope of the act block
and use the flushSync API to mimic the behaviour of React 17 to
synchronously flush state to the render rather than trying to batch it.
Without the use of flushSync, we were seeing issues in shopify/web tests
where a previously tested component that left a promise in the act queue
could cause subsequent mounts in other tests to fail.
In React < 18 returning a value that isn't a promise to act will result
in a console warning, we need to match the previous behaviour of
react-testing for applications that are still using React 17 to avoid
introducing a warning.
Both versions are already functionally installed because react-server
is still using React 17. This installs them both under namespaced
packages as react17 and react18. We'll use these values to allow testing
under particular react versions using the REACT_VERSION env var.
React 17 doesn't have a react-dom/client directory, nor does it have a
createRoot or Root API. We provide backwards compatibility for this in
the compat module so that our root.tsx code can still use "createRoot"
just in React < 18 it'll be our own version of createRoot which wraps
ReactDOM.render and ReactDOM.unmountComponentAtNode
Makes it clearer what that 14/16/17/18 numbers correspond to
@ryanwilsonperkin ryanwilsonperkin marked this pull request as ready for review June 8, 2022 18:28
@ryanwilsonperkin ryanwilsonperkin requested a review from a team as a code owner June 8, 2022 18:28
@ryanwilsonperkin
Copy link
Member Author

CI blocks because it's got branch requirements on test names that are being change as part of this PR, will force the merge and then update the CI requirements in branch settings

@ryanwilsonperkin ryanwilsonperkin merged commit 405c12f into main Jun 8, 2022
@ryanwilsonperkin ryanwilsonperkin deleted the react-18 branch June 8, 2022 18:44
@shopify-shipit shopify-shipit bot temporarily deployed to production-js June 8, 2022 19:02 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to beta-js-apollo June 9, 2022 19:48 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to production-gem June 21, 2022 14:45 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants