WIP Use package.json React version for vendor script cache busting#76798
WIP Use package.json React version for vendor script cache busting#76798
Conversation
- Extend wp-build generated constants.php with react_version from root package.json (devDependencies or dependencies react field). - Define GUTENBERG_REACT_VENDOR_VERSION in load.php when present. - Pass that version to react, react-dom, and react-jsx-runtime registration; fall back to major "18" for older builds or projects without a react pin. Follow-up to the approach in #46768, tying ?ver= to the actual bundled React. Made-with: Cursor
| gutenberg_url( 'build/scripts/vendors/react-dom' . $extension ), | ||
| array( 'react' ), | ||
| '18' | ||
| $react_vendor_version |
|
Size Change: 0 B Total Size: 7.66 MB ℹ️ View Unchanged
|
|
Flaky tests detected in aeb7c05. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23526123657
|
| gutenberg_url( 'build/scripts/vendors/react-jsx-runtime' . $extension ), | ||
| array( 'react' ), | ||
| '18' | ||
| $react_vendor_version |
There was a problem hiding this comment.
Using the react version here is good but I'm not a fan of the wp-build changes. I'll comment there.
There was a problem hiding this comment.
A good approach how to extract and use the React version is to generate .asset.php files in the buildVendors function that runs as part of the wp-build build. The version can be extracted during the build, and then this client-asset.php code will just read the .asset.php file and use what's there. That's what most other Gutenberg scripts are doing.
The version can be extracted from the package.json file corresponding to each name in the VENDOR_SCRIPTS array. Also, both react and react-dom export a version string as a named export, that's another way how JS code can detect the version.
The root package.json also works, but doesn't need to be 100% reliable. The might be a semver spec there, like ^18.0.0.
| '{{PREFIX}}': name, | ||
| '{{VERSION}}': version, | ||
| '{{BASE_URL}}': baseUrlExpression, | ||
| '{{REACT_VERSION}}': reactVersion, |
There was a problem hiding this comment.
WP build is a generic tool, so we shouldn't add random variables like that IMO.
|
If I understand properly, the issue started in this PR #74343 So IMO, that |
|
The caching problem and the related crashes are caused by a regression in #74343 where we switched from React's own UMD build to creating our own bundles. As a preparation for React 19 upgrade, because React 19 doesn't ship the UMD builds any more. The In the old UMD build of Therefore, our new build of What we should have done in #74343 is to change the |
|
Closed in favor of #76811 |
|
Thanks for looking, folks. I'll close in favor of #76811 |
|
#76811 is now merged, implementing the |
Note
Just a test to follow up on cache versioning for react scripts
package.json (devDependencies or dependencies react field).
fall back to major "18.3.1" for older builds or projects without a react pin.
Follow-up to the approach in #46768, tying ?ver= to the actual bundled React.
What?
Closes
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Use of AI Tools