WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.37k stars 4.15k forks source link

Test and Upgrade to React 17 #24485

Closed youknowriad closed 3 years ago

youknowriad commented 4 years ago

The React team announced React 17 RC1. It’s a major release with some breaking changes. You can read the full post here https://reactjs.org/blog/2020/08/10/react-v17-rc.html We will be able to start upgrading React when it's stabilized and supported by react-native.

In the meantime, we can start testing and analyzing how impactful the breaking changes will be and how to roll out the release on Core.

My first impression after reading the release post is that it's not impactful and while some breakage is always possible, we might be able to upgrade to 17 easily.

Of course, a dev note will be required to announce that change on the WordPress release but I don't expect the need for extra-communication. This might be needed for future upgrades but our use of StrictMode is putting us in a good position since deprecated APIs are already receiving warnings.

Thoughts.

swissspidy commented 3 years ago

Is thee also an issue for using the new JSX transforms?

youknowriad commented 3 years ago

Not that I know of but it was definitely on my mind :)

gziolo commented 3 years ago

This one was accomplished with https://github.com/WordPress/gutenberg/pull/29118 🎉

Is thee also an issue for using the new JSX transforms?

This part wasn't covered. I'm wondering how much work it is to replace our custom approach with the official one. They seem to be compatible though.

ocean90 commented 3 years ago

@gziolo It looks like the React update wasn't documented in any changelog which means the change in @wordpress/element was released as a minor release while it should have been a major release I think. Now packages like @wordpress/data also require React 17 which doesn't mention that new requirement in the changelog. This is mostly an issue where the packages are used outside of the regular WordPress/Gutenberg context and an upgrade to React 17 isn't possible yet.

I guess it's too late to handle that now but wanted to mention anyway as a reminder for future updates.

Edit: Not sure how feasible that is, but one option might be to support v16 and v17 in @wordpress/element?

gziolo commented 3 years ago

@ocean90, good catch. It's definitely a huge deal.

Do you think we could downgrade React to 16.13.x and publish a patch release, then add an entry in the changelog and bump again to 17.0.x to ensure that all other packages pick it up correctly next time we publish all changed packages?

We could also check if making React and React DOM a peer dependency would work in this case. Not sure what npm 7 would install by default in that case though. Projects using npm 6 would have to explicitly set React as a dependency.

gziolo commented 3 years ago

I haven't figured out how to make the current version of @wordpress/element compatible with React 16 and 17.

However, I have PR with entries to all CHANGELOG files in packages that ship React components: https://github.com/WordPress/gutenberg/pull/33731. This will at least trigger a major version bump. We can try to fix @wordpress/element` v3.2.0 afterwards.

gziolo commented 3 years ago

We have new major version of packages published to npm in case they contain React components: 4e106dd6283fd742aeb521ebc0ae29f35d4274b4.

The remaining question is what we can do about @wordpress/element v3.2.0, any ideas?

ocean90 commented 3 years ago

Is it possible two create a branch based on the publish commit for @wordpress/element v3.2.0? If so, we could try to revert the changes from #29118 only in this branch and do a patch release.