Skip to content

feat(bridge-react): support React Router 8 package layout#4837

Open
BleedingDev wants to merge 6 commits into
module-federation:mainfrom
BleedingDev:fix/bridge-react-router-8-support
Open

feat(bridge-react): support React Router 8 package layout#4837
BleedingDev wants to merge 6 commits into
module-federation:mainfrom
BleedingDev:fix/bridge-react-router-8-support

Conversation

@BleedingDev

Copy link
Copy Markdown
Contributor

Description

Fixes #4836.

React Router 8 removes react-router-dom and moves DOM-specific router APIs behind react-router/dom. This updates the React bridge to support that package layout without keeping a v8 react-router-dom bridge path.

What changed:

  • Adds separate router-v8 and router-v8-dom bridge entries so react-router and react-router/dom are proxied independently.
  • Updates the bridge webpack plugin to detect React Router 8, alias react-router/dom, and map bridge-internal dist imports back to the user's installed react-router package to avoid alias loops.
  • Moves the default bridge router-data helper off react-router-dom so importing @module-federation/bridge-react does not require react-router-dom during module initialization.
  • Widens react-router peers for @module-federation/bridge-react and @module-federation/modern-js-v3 while keeping react-router-dom capped at v7.
  • Documents the manual v8 alias shape, adds focused tests, and includes a changeset.

Related Issue

Impact

Apps preparing for React Router 8 can migrate imports to react-router and react-router/dom, then let the bridge plugin select the v8 proxy entries. Existing v5/v6/v7 router aliases are kept on their current paths, including the v7 react-router-dom compatibility alias.

Validation

  • pnpm install --frozen-lockfile
  • pnpm --filter @module-federation/bridge-react-webpack-plugin run test
  • pnpm --filter @module-federation/bridge-react exec jest --config jest.config.ts __tests__/default-import.spec.ts __tests__/router.spec.tsx --runInBand
  • pnpm exec prettier --check packages/bridge/bridge-react/src/router/v8.tsx packages/bridge/bridge-react/src/router/v8-dom.tsx packages/bridge/bridge-react/vite.config.ts packages/bridge/bridge-react/package.json packages/bridge/bridge-react/README.md packages/bridge/bridge-react/jest.config.ts packages/bridge/bridge-react/__tests__/default-import.spec.ts packages/bridge/bridge-react/__tests__/router.spec.tsx packages/bridge/bridge-react-webpack-plugin/src/router-alias.ts packages/bridge/bridge-react-webpack-plugin/src/utils.ts packages/bridge/bridge-react-webpack-plugin/src/index.ts packages/bridge/bridge-react-webpack-plugin/__tests__/utils.spec.ts packages/bridge/bridge-react-webpack-plugin/README.md packages/modernjs-v3/package.json .changeset/react-router-eight-bridge.md
  • git diff --check
  • pnpm exec turbo run build --filter=@module-federation/bridge-react --filter=@module-federation/bridge-react-webpack-plugin --filter=@module-federation/modern-js-v3

Notes:

  • Local validation ran with Node v26.3.0 and pnpm 10.28.0; pnpm emitted the existing repo engine warning because package.json currently asks for Node ^20.
  • The targeted build passed with existing dependency/build warnings, including API Extractor TypeScript-version notices, direct-eval warnings in unrelated packages, and existing publint warnings for rsbuild-plugin/modern-js-v3.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

@changeset-bot

changeset-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1d9bb03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 46 packages
Name Type
@module-federation/bridge-react Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
remote5 Patch
remote6 Patch
@module-federation/enhanced Patch
@module-federation/rspack Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Patch
@module-federation/rspress-plugin Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch
website-new Patch
@module-federation/runtime Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/dts-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/devtools Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/retry-plugin Patch
@module-federation/error-codes Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/runtime-core Patch
create-module-federation Patch
@module-federation/cli Patch
@module-federation/treeshake-server Patch
@module-federation/treeshake-frontend Patch
@module-federation/metro Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rock Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/esbuild Patch
@module-federation/observability-plugin Patch
@module-federation/utilities Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Jun 21, 2026

Copy link
Copy Markdown

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 1d9bb03
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6a3a8dcdf63a680008dc78d9
😎 Deploy Preview https://deploy-preview-4837--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b33c04f893

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/remote/router-component/component.tsx Outdated
Comment thread packages/bridge/bridge-react-webpack-plugin/src/router-alias.ts Outdated
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from b33c04f to 9f6924a Compare June 21, 2026 20:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f6924a185

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react-webpack-plugin/src/router-alias.ts Outdated
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from 9f6924a to 8be9ecf Compare June 21, 2026 21:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8be9ecf6e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/router/v8-dom.tsx Outdated
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from 8be9ecf to 1fa6d1b Compare June 21, 2026 21:24

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1fa6d1bffd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react-webpack-plugin/src/router-alias.ts
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from 1fa6d1b to 02aad5c Compare June 21, 2026 21:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02aad5c432

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/remote/router-component/component.tsx Outdated
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from 02aad5c to 25c516c Compare June 21, 2026 22:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25c516c7da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/remote/router-component/router-loader.ts Outdated
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from 25c516c to 461ec05 Compare June 21, 2026 22:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 461ec055c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/remote/router-component/router-loader.ts Outdated
Comment thread packages/bridge/bridge-react/src/remote/router-component/component.tsx Outdated
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch 2 times, most recently from 3684bd5 to 803b0fc Compare June 21, 2026 23:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 803b0fc34d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/README.md
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from 803b0fc to c8781ec Compare June 22, 2026 00:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8781ecabe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/router/v8.tsx
@BleedingDev BleedingDev force-pushed the fix/bridge-react-router-8-support branch from c8781ec to bcbbe88 Compare June 22, 2026 07:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bcbbe88d74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/bridge/bridge-react/src/remote/router-component/router-runtime.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6dc6833ff2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc7a54f2ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

routerPackagePath: string,
): Record<string, string> => {
return {
'react-router$': reactRouterV8AliasPath,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard shared react-router for v8 aliases

When a React Router 8 remote also configures shared: ['react-router'] or the object equivalent, the Module Federation shared consume path can take the real router package before this new react-router$ proxy is used, so BrowserRouter/RouterProvider are not wrapped and the host basename/memoryRoute context is ignored. The plugin constructor still only rejects shared react-router-dom, which covered the old package name; please apply the same guard to react-router for the v8 path.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support React Router 8 in bridge-react without react-router-dom

1 participant