Skip to content

Agents Manager: externalize react-dom/client to the host's ReactDOM#112428

Closed
iamchughmayank wants to merge 1 commit into
trunkfrom
update/am-externalise-react-dom
Closed

Agents Manager: externalize react-dom/client to the host's ReactDOM#112428
iamchughmayank wants to merge 1 commit into
trunkfrom
update/am-externalise-react-dom

Conversation

@iamchughmayank

@iamchughmayank iamchughmayank commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

  • Externalize react-dom/client in the Agents Manager widget build so createRoot resolves to WordPress's ReactDOM instead of bundling a copy of react-dom, and map the subpath to the react-dom script handle so it is declared as a dependency.

Why are these changes being made?

The Agents Manager widgets externalize react and react-dom to the React that WordPress provides, but the dependency-extraction plugin does not externalize the react-dom/client subpath — so createRoot pulls a bundled copy of react-dom into the widget. A bundled react-dom ships its own React runtime, which is incompatible with the host's React whenever the versions differ.

Now that calypso builds against React 19 (#112339), a widget rebuilt from trunk bundles react-dom 19 while the block-editor host still runs React 18, which crashes the sidebar at mount (Cannot read properties of undefined (reading 'S') / minified React error 525). Externalizing react-dom/client makes the widget use the host's react-dom, so it always matches the host — React 18 today and React 19 automatically once the host migrates.

Same rationale as odyssey-stats and blaze-dashboard, which externalize the React runtime to the host; this change additionally maps the react-dom/client subpath.

Testing Instructions

  1. Sandbox widgets.wp.com and run cd apps/agents-manager && yarn dev --sync.
  2. Open the post editor on a Simple or Atomic site and open the AI sidebar — the FAB should render with no React console errors.
  3. Confirm the suggestions in the sidebar are working as expected

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • For UI changes, have you tested the affected components in dark mode?
  • Have you tested accessibility for your changes?
  • Have you used memoizing on expensive computations?
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@iamchughmayank
iamchughmayank requested a review from Copilot July 8, 2026 14:58
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jul 8, 2026
@iamchughmayank
iamchughmayank marked this pull request as ready for review July 8, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Agents Manager widget webpack build to ensure react-dom/client is treated as a WordPress-provided external, preventing the widget from bundling its own react-dom (and avoiding React runtime/version mismatches with the block editor host).

Changes:

  • Externalize react-dom/client to the host’s ReactDOM global so createRoot uses WordPress’s react-dom.
  • Map react-dom/client to the react-dom script handle via requestToHandle so the generated *.asset.json declares the correct dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/agents-manager/webpack.config.js Outdated
@iamchughmayank
iamchughmayank force-pushed the update/am-externalise-react-dom branch from 65f903e to 32201fb Compare July 8, 2026 15:03
- Map react-dom/client → ReactDOM external + the react-dom script handle
- Stops bundling react-dom, which shipped its own React runtime and clashed
  with the editor host's React (calypso builds React 19, host is React 18)
- Mirrors odyssey-stats / blaze-dashboard, which externalize the React runtime

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Looks like one of the E2E tests has failed.

You can fix them following these steps:

  1. Check out this branch locally:
    gh pr checkout 112428
  2. Start Claude Code in the repo:
    claude
  3. Run the /fix-e2e-tests skill, passing this PR number:
    /fix-e2e-tests 112428
    

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@wellyshen

Copy link
Copy Markdown
Contributor

Seems duplicated: #112421

@iamchughmayank

Copy link
Copy Markdown
Contributor Author

closing in favour of #112428 (comment)

@github-actions github-actions Bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jul 8, 2026
@matticbot

Copy link
Copy Markdown
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants