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 #77046

Merged
merged 35 commits into from
Jun 27, 2023
Merged

React 18 #77046

merged 35 commits into from
Jun 27, 2023

Conversation

noahtallen
Copy link
Member

@noahtallen noahtallen commented May 18, 2023

This PR updates Calypso to React 18, and updates WordPress packages to the first version which supported React 18 (which is 4-5 months old at this point.)

Note: this does not yet enable the new rendering mode -- that will likely be a follow-up due to the size of this PR!

Prerequisite or split-out work:

Notable breaking changes which impact us (excluding concurrent mode)

  • Various React types have been deprecated and changed
    • ReactChild, ReactFragment, and ReactText have been deprecated
    • useCallback now requires types for the callback arguments, which means most of those need to be updated
    • children isn't automatically a prop, so we need to add it, which means everywhere we use children needs to be updated

To do:

  • Smoke test everything!

Done: (🤞 )

  • SSR does not appear to be working in prod (calypso.live) due to useSyncExternalStore being called without a 3rd argument in use-subscription. (This breaks SSR.)
  • Fix an issue where TextEncoder wasn't defined in ReactDOMServer, causing notifications panel to not open.
  • Importing parseWithAttributeSchema from @wordpress/blocks crashes the application -- something related to the unlock/lock private APIs. This unfortunately prevents the editor routes from loading. (Will potentially need to fix this in a future WP package update)
  • Import react dom server from browser bundles
  • Fix issue with SSR and layout effects
  • Fix babel issue related to declare context use (breaking docker build)
  • Fix unit tests
  • Fix all type issues!
  • Fix this type issue related to createElement: Argument of type 'ForwardRefExoticComponent<ButtonProps & RefAttributes<any>>' is not assignable to parameter of type 'string | FunctionComponent<BaseButtonProps & _ButtonProps & Omit<Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "disabled" | ... 1 more ... | keyof BaseButtonProps> & RefAttributes<...>> | ComponentClass<...>'. (example) -- doesn't seem to happen any more
  • Fix type issue related to ExternalLink and useInterpolateElement (punted)
  • Add stream browserify to calypso-build and client
  • Fix peer dependency violation warnings (doesn't block working on other issues)
  • Updated types related to children/ReactNode -- @types/react has changed to be more strict about this.
  • Updated some types related to event handlers and useCallback.
  • For some components, use ComponentProps< typeof Component > now that prop types aren't directly available for wp components.
  • Add the stream package -- apparently this was needed for react-dom? Webpack wouldn't compile without it.
  • Updated WordPress components usage to use variant rather than isX. (E.g. variant="tertiary" rather than isTertiary)
  • Updated package versions across the repo (React, WordPress, and testing library)
  • Tried to stub out global styles so that we can work on other things, until we find a solution for this.
  • Added some @types/ packages required by @wordpress/components (See Add some @types packages as proper dependencies WordPress/gutenberg#50231 for more info, but we'll need to do this in Calypso until we get a fix in core.)
  • Fix type issue with internal translations related to deprecated ReactChild
  • Fix type issue with certain store selectors and actions
  • Fix type issues with search results in the help center
  • Update stripe packages for compatibility with React 18
  • Fix @automattic/global-styles -- it relies extensively on private file imports (e.g. @wordpress/edit-site/build-module/some/deep/path), which have been drastically changed internally.

@noahtallen noahtallen self-assigned this May 18, 2023
@noahtallen noahtallen requested review from a team and worldomonation as code owners May 18, 2023 00:38
@noahtallen noahtallen requested review from jessie-ross and removed request for a team May 18, 2023 00:38
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 18, 2023
@noahtallen noahtallen marked this pull request as draft May 18, 2023 00:39
@github-actions
Copy link

github-actions bot commented May 18, 2023

@matticbot
Copy link
Contributor

This PR modifies the release build for wpcom-block-editor

To test your changes on WordPress.com, run install-plugin.sh wpcom-block-editor try-react-18 on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-l4k-p2

@tyxla
Copy link
Member

tyxla commented May 19, 2023

Great work @noahtallen! 🚀 Thank you!

I think we should first address the peer dep situation in #77121 which is quite complex on its own 😅 I'll devote some time to helping there as well with whatever I can.

@noahtallen
Copy link
Member Author

noahtallen commented Jun 1, 2023

@tyxla I made a bunch of changes to the yarnrc file, including reworking how we ignore certain warnings. It should both be much more clear what our discard statements are doing, and should also dynamically cover more scenarios that are the same issue. I also documented the packages we're waiting for @wordpress/ to update. I also moved a few of the discard statements into the packageExtensions area, because I think that's a more ideal way to solve errors where that works.

I also ignored the warnings related to the date picker package we decided not to update just yet.

Finally, I also synced our react-virtualized fork (Automattic/react-virtualized#3) and published the update to npm, ultimately incorporating it here.

This means all the violations/warnings happening on yarn install are resolved now!

@noahtallen
Copy link
Member Author

noahtallen commented Jun 2, 2023

I added a bunch of little commits trying to get some insight into why yarn install is failing in CI and not locally. Here's what's happening. (TeamCity link)

RUN  cat packages/data-stores/package.json && yarn explain peer-requirements p031cd && yarn install && yarn explain peer-requirements p031cd && cat packages/data-stores/package.json

### packages/data-stores/package.json
{
  "name": "@automattic/data-stores",
  ...
   "peerDependencies": {
    ...
     "react": "^17.0.2", ### WTF???
   }
}

### First explain peer requirements (it's fine for some reason?)
YN0000: @automattic/domain-picker@workspace:packages/domain-picker [abd57] provides react-dom@npm:18.2.0 [35689] with version 18.2.0, which satisfies the following requirements:
YN0000: @automattic/data-stores@workspace:packages/data-stores [abd57] → ^18.2.0 ✓

### Yarn install output:
┌ Resolution step
│ @automattic/domain-picker@workspace:packages/domain-picker [abd57] provides react-dom (p031cd) with version 18.2.0, which doesnt satisfy what @automattic/data-stores requests
...

### Second explainer for same ID, now broken!!
@automattic/domain-picker@workspace:packages/domain-picker [abd57] provides react-dom@npm:18.2.0 [441bf] with version 18.2.0, which doesnt satisfy the following requirements:
@automattic/data-stores@workspace:packages/data-stores [abd57] → ^17.0.2 ✘

### packages/data-stores/package.json
{
  "name": "@automattic/data-stores",
  ...
   "peerDependencies": {
    ...
     "react": "^17.0.2", ### incorrect!!!
   }
}

Some of these symptoms are very similar to p9oQ9f-1I5-p2. This is so bizarre

@tyxla
Copy link
Member

tyxla commented Jun 2, 2023

This means all the violations/warnings happening on yarn install are resolved now!

Glad to hear - nice work!

I added a bunch of little commits trying to get some insight into why yarn install is failing in CI and not locally. Here's what's happening.

For what it's worth I've tried on both my machines to repro it and could not. I wonder if we have some sort of a cache on the TeamCity level that we need to bust 🤔

@noahtallen
Copy link
Member Author

noahtallen commented Jun 2, 2023

Yeah, if I check the contents of a package.json file outside of the docker build, it is correct and matches the branch. But inside the build, after running COPY . /calypso/, the contents of the file are different. Suggesting that Docker is copying files from something other than the current branch. (The layer cache is not used, and both docker build and my "outside the build file check" run from the same directory. The --no-cache=true flag also makes no difference, which makes sense as the layer cache is not being used here for the COPY step anyways.)

@noahtallen
Copy link
Member Author

noahtallen commented Jun 3, 2023

Ok, the issue is not happening any more. I rebased the PR and squashed a ton of commits, and the weird CI issue with peer dependency warnings is resolved.

@matticbot
Copy link
Contributor

This PR modifies the release build for notifications

To test your changes on WordPress.com, run install-plugin.sh notifications try-react-18 on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-elI-p2

@noahtallen noahtallen merged commit 8a2800d into trunk Jun 27, 2023
4 checks passed
@noahtallen noahtallen deleted the try-react-18 branch June 27, 2023 19:15
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jun 27, 2023
@noahtallen
Copy link
Member Author

I did further testing of the Calypso apps like ETK, notifications, and wpcom-block-editor, and these are also working well.

@noahtallen
Copy link
Member Author

noahtallen commented Jun 27, 2023

Next up, updating WordPress packages to latest: #78711

TimBroddin pushed a commit that referenced this pull request Jun 28, 2023
* Update packages to be compatible with React 18

* Update internal peer dependencies

* Resolve peer dependency issues

* Update several internal tsconfig references

* Add stream fallback in webpack

* Attempt removing jsx import alias

* Update snapshots to remove whitespace

* Remove custom @types/react patch and pin react 18 types

* Fix issues with children type in React props

* Fix type issues related to useCallback function arguments

* Fix issues with the store selector types

* Remove some uneeded React types

* remove an unused ts-expect-error call

* Add ReactNode types to an inline function component

* Change a use of a component to call it directly

* Fix a type related to interpolate element (ReactNode->ReactElement)

* Cast known render values to string

* Fix context types in legacy class component

* Fix incorrect prop type (Node->ReactNode)

* Fix a type issue with an action creator

* Remove fallback translation which was causing a type error

* Fix an odd issue where children were passed as a function

* Improve generics for use track callback useCallback

* Cast render type to ReactNode and add comment

* Cast const array to readonlyarray so we can use .includes on it

* Another yarn.lock update

* Enable allowDeclareFields for typescript classes in babel preset

* Fix babel config preset syntax

* Try with casting for now

* Fix a bunch of package unit tests

* Fix a bunch of client unit tests

* Conditionally run layout effects in SSR

* Import react dom server from browser bundle explicitly

* Attempt defining TextEncoder globally for tests

* Attempt downgrading use-subscription to fix SSR bug

---------

Co-authored-by: Marin Atanasov <tyxla@abv.bg>
@a8ci18n
Copy link

a8ci18n commented Jul 6, 2023

Translation for this Pull Request has now been finished.

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.

Tooling: Add Storybook for client/*
7 participants