Skip to content

Build: no React key warnings from the admin pages' JSX runtime - #2349

Merged
rudrakshi-gupta merged 1 commit into
developfrom
fix/jsx-runtime-static-children
Nov 18, 2026
Merged

rudrakshi-gupta merged 1 commit into
developfrom
fix/jsx-runtime-static-children

Conversation

@subodhr258

@subodhr258 subodhr258 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Part of the 2.10.1 release: https://github.com/rtCamp/godam-plugin-wp/issues/112 (moved from develop to main on 16 Nov).

Base branch

Targets main for 2.10.1. The JSX runtime shim it fixes came in with #2347 on main and reached develop through the main-to-develop sync #2353 (merged 11 Nov).

Why

#2347 added pages/jsx-runtime.js so the admin pages stop bundling React's own JSX runtime (Plugin Check inlined_react_jsx_runtime). The shim 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, so the admin pages log "Each child in a list should have a unique key prop" warnings.

This only shows on sites with SCRIPT_DEBUG on, which load React's development build. Production React prints nothing, and nothing renders differently.

Build Key warnings on the Media Editor (Transcription tab)
a8cd51e, before the shim 0
main (2.8.0, with the shim) 14
This PR 0

What changes

Only pages/jsx-runtime.js, plus a test.

  • jsxs (children written out in the source) now passes them to createElement as separate arguments, the way the classic transform does, so React treats them as static.
  • jsx passes its one child as an argument too. A child that is an array is a dynamic list (for example items.map( … )), so React still checks its keys.
  • jsxDEV picks one of the two from isStaticChildren.
  • key and ref are handled as before.

Testing

  • New pages/jsx-runtime.test.js renders with react-dom/client in jsdom: static children give no key warning (this test failed on main with the warning), an unkeyed dynamic list still warns, and key, ref, single children and Fragment come through.
  • Full Jest suite: 75 of 75 suites, 1010 of 1010 tests pass. Lint clean.
  • Built with npm run build:prod on a local site with SCRIPT_DEBUG on: 0 key warnings on the Media Editor (14 on main). 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.
  • Not checked: Plugin Check on this head (CI will run it), and a WordPress install without SCRIPT_DEBUG.

@subodhr258 subodhr258 added the risk: low QA automation only (Dependabot fixes, copy, CSS) label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
13 0 13

⚠️ Warnings (13)

📁 readme.txt (1 warning)
📍 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

@subodhr258
subodhr258 changed the base branch from main to develop November 11, 2026 06:29
@subodhr258 subodhr258 changed the title Build: no React key warnings from the admin pages' JSX runtime (2.8.1) Build: no React key warnings from the admin pages' JSX runtime Nov 11, 2026

@elifvish elifvish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-runtime on key warnings and on the elements it builds (single child, no children, string/number/null key, ref, static children with a key, an array child in jsx, defaultProps). Where the #2347 shim got it wrong, including not warning for an unkeyed rows.map(...), this one gets it right.
  • An unkeyed array nested among static children still warns, because createElement validates each argument.
  • FYI, not a request: jsxs( type, { children: [ 'a' ] } ) gives props.children === 'a' and children: [] gives undefined, where React's own jsxs keeps the array. Babel, TypeScript and esbuild only emit jsxs for 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 toConfig and 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. Full npx jest: 75/75 suites, 1010/1010 tests. eslint on both files: clean.
  • Rendered the real Media Editor Transcription tab and CaptionManager dialog 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 build succeeds (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 without SCRIPT_DEBUG, and React 19.

Comment thread pages/jsx-runtime.test.js
*/
import { createRef } from 'react';
import { createRoot } from 'react-dom/client';
import { act } from 'react-dom/test-utils';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pages/jsx-runtime.test.js
/**
* Internal dependencies
*/
import { jsx, jsxs, Fragment } from './jsx-runtime';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@subodhr258
subodhr258 force-pushed the fix/jsx-runtime-static-children branch from 6e71ef7 to ac4a779 Compare November 16, 2026 07:46
@subodhr258
subodhr258 changed the base branch from develop to main November 16, 2026 07:46
@KMchaudhary

Copy link
Copy Markdown
Collaborator

Code review — correct, and I couldn't find any bug. The fix faithfully reproduces React's classic-transform semantics: jsxs spreads static children as positional createElement args (so React treats them as static), jsx passes its single child positionally, and an array child still arrives as one argument so React key-checks dynamic lists. toConfig correctly strips children and re-attaches key/ref. Verified props.children identity (single vs array) matches what the real automatic runtime yields, so React.Children.* behaves the same. The test covers the key cases, including the "still warns for a dynamic list" direction.

Two negligible notes, neither needing a change:

  • jsxDEV takes 4 params and drops React's source/self dev-only args, so dev-build warnings on these elements won't carry a source location. Fine for a production externalization shim whose purpose is to reduce warnings.
  • jsxs's Array.isArray(...) ? ... : [child] fallback would unwrap a single-element array (props.children = child rather than [child]), diverging slightly from real React — but Babel only emits jsxs for 2+ static children, so that branch is effectively dead.

LGTM.

Reviewed with Claude Code

@rudrakshi-gupta

Copy link
Copy Markdown
Member

Code review

Verdict: LGTM on the code. I agree with Elif's and Kuldip's reviews and won't repeat them. On ac4a779 I re-ran pages/jsx-runtime.test.js (3/3 pass) and ESLint on both files (clean).

Two things still block the merge, neither of them code:

  1. Elif's two test suggestions are still open, and the open conversation blocks the merge:
    • jsx-runtime.test.js:12 still imports act from react-dom/test-utils. On React 18.3 that logs a deprecation warning, hidden by the console.error spy, and it's removed in React 19. import { createRef, act } from 'react'; matches the other tests here.
    • jsxDEV and its new isStaticChildren branch have no test. Two short cases mirroring the first two (true with static children gives no warning; false with unkeyed items warns once) would cover the path the dev build actually uses.
  2. The required CodeQL checks show "Expected" and never report. The base was switched from develop to main after the last push, so GitHub's default CodeQL setup hasn't run against main for this PR (Consent follow-ups: "Track visitors" setting, privacy-policy text, and the browser items in the readme #2374, also on main, has its CodeQL results). Pushing the test fix above, or closing and reopening the PR, should trigger it.

@elifvish elifvish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Summary

  • Fix: jsxs passes 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:530 alias.
  • Deploy checks: 1. Open the Media Editor with SCRIPT_DEBUG on. 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 main shim, 0 here.
  • ⏭️ Not covered: browser run on WordPress.

@rudrakshi-gupta
rudrakshi-gupta changed the base branch from main to develop November 18, 2026 13:56
@rudrakshi-gupta
rudrakshi-gupta merged commit c016bfd into develop Nov 18, 2026
5 checks passed
@rudrakshi-gupta
rudrakshi-gupta deleted the fix/jsx-runtime-static-children branch November 18, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: low QA automation only (Dependabot fixes, copy, CSS)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants