Repository navigation
Build: no React key warnings from the admin pages' JSX runtime - #2349
Conversation
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
mismatched_plugin_name | Plugin name "GoDAM - Video Hosting for LMS & Online Courses" is different from the name declared in plugin header "GoDAM". |
📁 assets/build/pages/video-editor.min.js (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
2 |
react_removed_api | This file calls "ReactDOM.findDOMNode", which was removed in React 19 and stops working once WordPress upgrades React. Use a ref on the element instead. |
📁 assets/build/css/main.css (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedStylesScope | This style is being loaded in all contexts. |
📁 assets/src/libs/analytics.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/11/16/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
📁 assets/build/js/main.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/11/16/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
elifvish
left a comment
There was a problem hiding this comment.
Nice fix. I went through it against React's own runtime and it does what the description says. Two small suggestions on the test file below; nothing blocking.
Security
No issues. This is a build-time shim: no input handling, no network or file access, no new dependency. Bundles built from this head contain no inlined React element factory (react.element), so the Plugin Check fix from #2347 still holds.
Correctness
- The shim matches React's own
react/jsx-runtimeon key warnings and on the elements it builds (single child, no children, string/number/nullkey,ref, static children with a key, an array child injsx,defaultProps). Where the #2347 shim got it wrong, including not warning for an unkeyedrows.map(...), this one gets it right. - An unkeyed array nested among static children still warns, because
createElementvalidates each argument. - FYI, not a request:
jsxs( type, { children: [ 'a' ] } )givesprops.children === 'a'andchildren: []givesundefined, where React's ownjsxskeeps the array. Babel, TypeScript and esbuild only emitjsxsfor two or more static children, so compiled JSX never hits it.
Others
- Two test nits (inline).
- I looked at per-element overhead from the destructuring in
toConfigand it is within noise (2M three-element trees on production React), so no change needed there.
Consumers
Only webpack.config.js:464-465 in this repo aliases to this file. Nothing in the other repos I have checked out imports it. Unaffected.
Verification
- Commit tested:
6e71ef753357a84951efaa277e2e817a90be7159(still the PR head when I finished). Linux, Node 24, React/ReactDOM 18.3.1. npx jest pages/jsx-runtime.test.js: 3/3 pass. Fullnpx jest: 75/75 suites, 1010/1010 tests.eslinton both files: clean.- Rendered the real Media Editor
Transcriptiontab andCaptionManagerdialog in jsdom with the real@wordpress/components(data hooks stubbed), once per runtime: the #2347 shim gives 10 key warnings, this PR gives 0, React's own runtime gives 0. Rendered DOM is identical apart from Emotion's dev-only class labels. NODE_ENV=production wp-scripts buildsucceeds (only the existing CSS and asset-size warnings); no bundle contains React's element factory.- CI is green on this head, including Plugin Check.
- Not covered: a browser run on a WordPress site with
SCRIPT_DEBUG(no local WordPress site available to me, so I haven't reproduced your 14 -> 0 number in a browser or checked the other admin pages), a site withoutSCRIPT_DEBUG, and React 19.
| */ | ||
| import { createRef } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
| import { act } from 'react-dom/test-utils'; |
There was a problem hiding this comment.
Small one: on this repo's React 18.3.1, act from react-dom/test-utils logs "ReactDOMTestUtils.act is deprecated in favor of React.act" (your console.error spy hides it), and it is removed in React 19. The other tests here import it from react (e.g. TopProductsTable.test.js, CTALayer.test.js). Suggest import { createRef, act } from 'react'; and dropping this line.
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { jsx, jsxs, Fragment } from './jsx-runtime'; |
There was a problem hiding this comment.
jsxDEV is exported and aliased (react/jsx-dev-runtime), and this PR adds the isStaticChildren branch to it, but the tests only import jsx, jsxs and Fragment. I checked it by hand: jsxDEV( 'ul', { children: [ ... ] }, undefined, true ) gives no key warning and false with unkeyed lis warns once. Could you add two short cases mirroring the first two tests?
…runtime The JSX runtime shim from 2.8.0 handed every element's children to createElement inside props. React's development build then treated children written out in the source as an unkeyed list, and the admin pages logged "Each child in a list should have a unique key prop" warnings when SCRIPT_DEBUG is on (14 on the Media Editor). jsxs now passes them as separate arguments, as the classic transform does; jsx still passes a dynamic list as one child, so its keys are still checked.
6e71ef7 to
ac4a779
Compare
|
Code review — correct, and I couldn't find any bug. The fix faithfully reproduces React's classic-transform semantics: Two negligible notes, neither needing a change:
LGTM. Reviewed with Claude Code |
Code reviewVerdict: LGTM on the code. I agree with Elif's and Kuldip's reviews and won't repeat them. On Two things still block the merge, neither of them code:
|
elifvish
left a comment
There was a problem hiding this comment.
LGTM
Summary
- Fix:
jsxspasses static children as arguments, so React stops warning about keys. - The 2 test suggestions from the earlier review are still open. The test file did not change.
Consumers
- none affected
Release checks
- Migrations: none. JS shim only.
- Consumers: only the
webpack.config.js:530alias. - Deploy checks: 1. Open the Media Editor with
SCRIPT_DEBUGon. 2. Confirm 0 key warnings. - Rollback: Revert the commit and rebuild.
Verification
- ✅ Jest: 1283/1283 on
ac4a779. New test: 3/3. - ✅ Babel + jsdom: 5 key warnings with the
mainshim, 0 here. - ⏭️ Not covered: browser run on WordPress.
Part of the 2.10.1 release: https://github.com/rtCamp/godam-plugin-wp/issues/112 (moved from
developtomainon 16 Nov).Base branch
Targets
mainfor 2.10.1. The JSX runtime shim it fixes came in with #2347 onmainand reacheddevelopthrough the main-to-develop sync #2353 (merged 11 Nov).Why
#2347 added
pages/jsx-runtime.jsso the admin pages stop bundling React's own JSX runtime (Plugin Checkinlined_react_jsx_runtime). The shim handed every element's children tocreateElementinsideprops. React's development build then treated children written out in the source as an unkeyed list, so the admin pages log "Each child in a list should have a unique key prop" warnings.This only shows on sites with
SCRIPT_DEBUGon, which load React's development build. Production React prints nothing, and nothing renders differently.main(2.8.0, with the shim)What changes
Only
pages/jsx-runtime.js, plus a test.jsxs(children written out in the source) now passes them tocreateElementas separate arguments, the way the classic transform does, so React treats them as static.jsxpasses its one child as an argument too. A child that is an array is a dynamic list (for exampleitems.map( … )), so React still checks its keys.jsxDEVpicks one of the two fromisStaticChildren.keyandrefare handled as before.Testing
pages/jsx-runtime.test.jsrenders withreact-dom/clientin jsdom: static children give no key warning (this test failed onmainwith the warning), an unkeyed dynamic list still warns, andkey,ref, single children andFragmentcome through.npm run build:prodon a local site withSCRIPT_DEBUGon: 0 key warnings on the Media Editor (14 onmain). The Dashboard, Media Editor, Settings, Tools, Analytics and Help pages all render with no React errors. The only console errors are two 500s from that site's local analytics stand-in, which wasn't running.SCRIPT_DEBUG.