Make WordPress Core

Opened 4 months ago

Last modified 4 days ago

#64958 new enhancement

Copy React vendor scripts from Gutenberg, update version number

Reported by: jsnajdr Owned by:
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch has-unit-tests gutenberg-merge
Cc: Focuses:

Description

Gutenberg started building its own bundles for the react, react-dom and react-jsx-runtime vendor scripts. Previously we've been copying React's own UMD bundles shipped as part of their NPM packages, but React 19 is going to remove these UMD bundles, and we are preparing for the migration by abandoning the UMD bundles in advance.

Instead of copying the UMD files, we'll copy them from the Gutenberg build.
We'll also update the version strings of the packages by appending a -wp suffix, so that we can differentiate them from previous versions. Even though it's still the same React 18.3.1, the build method has changed.

Change History (24)

This ticket was mentioned in PR #11359 on WordPress/wordpress-develop by @jsnajdr.


4 months ago
#1

  • Keywords has-patch has-unit-tests added

Gutenberg started building its own bundles for the react, react-dom and react-jsx-runtime vendor scripts. Previously we've been copying React's own UMD bundles shipped as part of their NPM packages, but React 19 is going to remove these UMD bundles, and we are preparing for the migration by abandoning the UMD bundles in advance.

Instead of copying the UMD files, we copy them from the Gutenberg build.

We also update the version strings of the packages by appending a -wp suffix, so that we can differentiate them from previous versions. Even though it's still the same React 18.3.1, the build method has changed.

Trac ticket: https://core.trac.wordpress.org/ticket/64958
Backports Gutenberg PR: https://github.com/WordPress/gutenberg/pull/74343 and https://github.com/WordPress/gutenberg/pull/76811

## Use of AI Tools

Autocomplete with Cursor and Opus 4.6.

#2 @desrosj
4 months ago

  • Milestone Awaiting Review7.1
  • Version trunk

@jsnajdr Is this a requirement for the 7.0 release? If not, we should hold off on merging this at least until after branching, preferably after 7.0 is released just to give it some proper testing and confirmation given the volume of changes to the build script this cycle.

#3 @jsnajdr
4 months ago

Waiting for 7.1 is fine, because 7.0 is not broken in any way. The corresponding Gutenberg fixes are urgent, because the equivalent Gutenberg functionality is broken, but the backport is not.

@Mamaduka commented on PR #11359:


4 months ago
#4

We also update the version strings of the packages by appending a -wp suffix, so that we can differentiate them from previous versions. Even though it's still the same React 18.3.1, the build method has changed.

We should probably get wider feedback on this new suffix. IIRC, WP always used version numbers for scripts, but vendors might be excluded from this policy.

cc @desrosj, @peterwilsoncc

@desrosj commented on PR #11359:


4 months ago
#5

Noting that I've seen this and it's on my list, but there are still build script bugs that need to be ironed out for 7.0. So I'm prioritizing those first.

#6 @desrosj
7 weeks ago

@jsnajdr Does the React 19 revert upstream impact this at all?

It seems this is still targeted for 7.1, but perhaps the PR will take a different form now?

#7 @wildworks
6 weeks ago

  • Keywords gutenberg-merge added

#8 @jsnajdr
6 weeks ago

Hi @desrosj, this PR is still relevant and is quite independent from the React 19 adventures. It starts copying the vendor scripts in a way that will be forward-compatible with React 19.

After the recent refactors of the copy code it needed to be rebased. And there is one additional thing that the original version of the PR didn't do: copy only the react.* files and exclude the new react-19.* ones that recent Gutenberg also builds.

I rebased and updated the PR, it's now again ready to merge.

@wildworks commented on PR #11359:


4 weeks ago
#9

I would appreciate it if we could confirm whether this PR is ready to ship for 7.1 Beta1.

@jsnajdr commented on PR #11359:


4 weeks ago
#10

A similar question was raised and answered on Trac (https://core.trac.wordpress.org/ticket/64958#comment:8) and the answer is yes, the PR is relevant and ready to be approved and shipped.

@wildworks commented on PR #11359:


4 weeks ago
#11

@Mamaduka @desrosj, could you re-review this PR?

@desrosj commented on PR #11359:


4 weeks ago
#12

I will take a look in the next 24 hours.

This ticket was mentioned in Slack in #core by adrianduffell. View the logs.


3 weeks ago

@jsnajdr commented on PR #11359:


3 weeks ago
#14

I believe that the react and react-dom dependencies can be removed from the package.json file.

@wordpress/* packages and others typically declare react as a peer dependency, and then it's up to the consuming package to provide that peer. In such cases it's correct for package.json to declare it, even if there is not direct usage.

Also, the react-is package is listed as a dependency.

Maybe @youknowriad remembers why he needed to add it in this commit 2 years ago. A typical reason is to pin the exact version, or to provide a peer dependency.

One interesting thing about that 2 years old commit is that at the time the root package.json declared many @wordpress/* dependencies. Packages with Gutenberg code, not just tooling. Today they are no longer there. I don't know what has changed.

It's quite likely that the package.json dependencies are no longer needed, but I think it's off topic for this PR.

Will there be a situation where someone would like the standard React asset and not the UMD format that we're continuing to provide?

I'm not aware of any situation where a consumer would observe a difference between the old-style and new-style asset.

@wildworks commented on PR #11359:


3 weeks ago
#15

@jsnajdr, Should this PR be committed before the 7.1 beta1 release, or is it okay for beta2? This is because the beta 1 release is only an hour away.

@youknowriad commented on PR #11359:


3 weeks ago
#16

It's quite likely that the package.json dependencies are no longer needed, but I think it's off topic for this PR. I'm a bit worried about entering some NPM dependency rabbit hole.

Today WordPress doesn't consume Gutenberg packages and code from npm, instead they're downloaded from a zip of a built Gutenberg basically.

@desrosj commented on PR #11359:


3 weeks ago
#17

Today WordPress doesn't consume Gutenberg packages and code from npm, instead they're downloaded from a zip of a built Gutenberg basically.

Do you recall any of the context around when react-is was added as a dependency here? I can't find where it was ever consumed by the build processes. And it seems like it's currently compiled into the built version that we now maintain.

I'm uncertain if it's good practice to note something as a dependency in package.json even when it's not actually required for the building and publishing process (which would make then make sense for it being included), or if it was included accidentally.

@desrosj commented on PR #11359:


3 weeks ago
#18

@wordpress/* packages and others typically declare react as a peer dependency, and then it's up to the consuming package to provide that peer. In such cases it's correct for package.json to declare it, even if there is not direct usage.

Actually, that may be what @jsnajdr is saying here? But I'm not clear if this is still the case for all three of these listed dependencies (react, react-dom, react-is).

@jsnajdr commented on PR #11359:


3 weeks ago
#19

Should this PR be committed before the 7.1 beta1 release, or is it okay for beta2?

Beta 2 is fine, this is not urgent. It's a preparation for future React 19 migration.

@youknowriad commented on PR #11359:


3 weeks ago
#20

Do you recall any of the context around when react-is

I'm afraid not, my guess is npm version conflicts but I can't tell for sure at the moment.

@jsnajdr commented on PR #11359:


3 weeks ago
#21

I pushed a commit that removes the react, react-dom and react-is dependencies. They are most likely a leftover from times when the project did its own build of Gutenberg. Now when we just download and unpack a ZIP file, they are no longer needed.

I also removed part of unit tests that checks the registered script versions against versions in package.json. React is no longer sourced from node_modules, so that check is no longer relevant.

@wildworks commented on PR #11359:


4 days ago
#22

@youknowriad @desrosj,do you have the bandwidth to review this PR? We want to decide whether to ship this PR as the 7.1 RC1 release is approaching.

@jsnajdr commented on PR #11359:


4 days ago
#23

Let's punt this from the 7.1 release, it's not really that important until we start really shipping the React 19 upgrade.

After @desrosj's feedback about doing the copying in copy.js vs the Gruntfile, there are still some issues I need to think trough.

Most importantly, the 18.3.1-wp version string is now hardcoded in the script-loader.php script and that's not good. It should be derived from the Gutenberg build artifact that we're copying from. There is a standard *.asset.php file there that contains the real version number and we should read it. That means that the React copying and registering code should be mostly identical to how other Gutenberg scripts are registered: by reading the .asset.php. And that code should live together. Maybe the React registration should be at a different place.

Note: See TracTickets for help on using tickets.