Skip to content

feat(browser): support Module Federation in Browser Mode - #1639

Open
9aoy wants to merge 1 commit into
mainfrom
9aoy/feat-mf-browser-mode
Open

feat(browser): support Module Federation in Browser Mode#1639
9aoy wants to merge 1 commit into
mainfrom
9aoy/feat-mf-browser-mode

Conversation

@9aoy

@9aoy 9aoy commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR enables Module Federation in Rstest Browser Mode using the bundler's web federation runtime while preserving the existing Node runner compatibility shims.

  • allow federation and @module-federation/rstest in browser projects, including browser runtime config projection
  • keep the standard Browser Mode HMR and lazy-compilation behavior without federation-specific disabling
  • add a real HTTP-remote Browser Mode example, headed-watch coverage, and English/Chinese documentation

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings July 29, 2026 03:15

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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: 16bbd5be33

ℹ️ 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/core/src/core/browser/loader.ts Outdated
Comment thread packages/core/src/core/browser/loader.ts Outdated
Comment thread packages/browser/src/hostController.ts Outdated
Comment thread packages/core/src/core/browser/loader.ts Outdated
@9aoy
9aoy marked this pull request as draft July 29, 2026 03:23
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 13 projects in monorepo, 3 projects with changes.

📊 Quick Summary
Project Total Size Change
browser 1.1 MB -208.0 B (-0.0%)
adapter-rsbuild 6.1 KB 0
browser-react 6.4 KB 0
browser-ui 811.2 KB 0
coverage-istanbul 19.2 KB 0
coverage-v8 80.1 KB 0
playwright 47.6 KB 0
adapter-rslib 50.4 KB 0
adapter-rspack 9.2 KB 0
core/browser 578.1 KB -37.0 B (-0.0%)
core/main 1.8 MB +15.0 B (0.0%)
vscode/extension 1.2 MB 0
vscode/worker 14.8 KB 0
📋 Detailed Reports (Click to expand)

📁 browser

Path: packages/browser/.rsdoctor/rsdoctor-data.json

📌 Baseline Commit: 1820b0ce6f | PR: #1652

Metric Current Baseline Change
📊 Total Size 1.1 MB 1.1 MB -208.0 B (-0.0%)
📄 JavaScript 1.0 MB 1.0 MB -208.0 B (-0.0%)
🎨 CSS 11.6 KB 11.6 KB 0
🌐 HTML 765.0 B 765.0 B 0
📁 Other Assets 43.4 KB 43.4 KB 0

📦 Download Diff Report: browser Bundle Diff

📁 core/browser

Path: packages/core/.rsdoctor/browser/rsdoctor-data.json

📌 Baseline Commit: 1820b0ce6f | PR: #1652

Metric Current Baseline Change
📊 Total Size 578.1 KB 578.2 KB -37.0 B (-0.0%)
📄 JavaScript 435.0 KB 435.0 KB 0
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 143.1 KB 143.2 KB -37.0 B (-0.0%)

📦 Download Diff Report: core/browser Bundle Diff

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 1820b0ce6f | PR: #1652

Metric Current Baseline Change
📊 Total Size 1.8 MB 1.8 MB +15.0 B (0.0%)
📄 JavaScript 1.4 MB 1.4 MB +47.0 B (0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 385.2 KB 385.3 KB -32.0 B (-0.0%)

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

Copilot AI review requested due to automatic review settings July 29, 2026 03:39
@9aoy
9aoy force-pushed the 9aoy/feat-mf-browser-mode branch from 16bbd5b to c4064aa Compare July 29, 2026 03:39
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4604e31
Status: ✅  Deploy successful!
Preview URL: https://dc69f7b2.rstest.pages.dev
Branch Preview URL: https://9aoy-feat-mf-browser-mode.rstest.pages.dev

View logs

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@9aoy
9aoy changed the base branch from main to 9aoy/fix-browser-ui-html-route July 29, 2026 03:40
Base automatically changed from 9aoy/fix-browser-ui-html-route to main July 29, 2026 04:41
@9aoy
9aoy force-pushed the 9aoy/feat-mf-browser-mode branch from c4064aa to 6621527 Compare July 30, 2026 03:59
Copilot AI review requested due to automatic review settings July 30, 2026 03:59

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 30, 2026 04:39
@9aoy
9aoy force-pushed the 9aoy/feat-mf-browser-mode branch from 6621527 to 387dfab Compare July 30, 2026 04:39

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@9aoy
9aoy marked this pull request as ready for review July 30, 2026 06:13
@9aoy
9aoy requested a review from ScriptedAlchemy July 30, 2026 06:26
@9aoy
9aoy force-pushed the 9aoy/feat-mf-browser-mode branch from 387dfab to 4604e31 Compare July 30, 2026 09:29
Copilot AI review requested due to automatic review settings July 30, 2026 09:29

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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: 4604e31562

ℹ️ 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".

},
plugins: [
pluginReact(),
federation({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Select the browser target for the federation plugin

In this Browser Mode config, calling federation without its second argument retains the plugin's Node-target default, so ComponentRemote.browser.test.tsx is bundled with the Node federation setup instead of the web runtime and cannot load the browser remote. The headed-watch fixture correctly passes { target: 'browser' }; apply the same option here and in the Browser Mode documentation example.

Useful? React with 👍 / 👎.


export default defineConfig({
federation: true,
globalSetup: ['./scripts/rstestBrowserGlobalSetup.ts'],

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 Run browser global setup before collecting federated tests

When this configuration is used with rstest list, browser collection goes directly through executor.collect() without running runBrowserGlobalSetupStage, unlike node collection. The static component-app/Button import is evaluated during collection, but this setup is what starts the remote on port 3001, so discovery returns a BrowserCollectError or times out; run and tear down browser global setup around non-files-only collection.

Useful? React with 👍 / 👎.

'serve',
]);
globalThis.__RSTEST_MF_CHILDREN__!.push(server);
await waitForUrl(browserRemoteEntryUrl, 30_000);

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 Clean up the remote when readiness fails

If the browser server starts but remoteEntry.js never becomes reachable—for example, because the output filename changes or serve cannot expose the build—this await throws before the global setup successfully registers its exported teardown. Rstest's failed-setup path therefore terminates the setup worker without calling cleanupRemote, leaving the spawned pnpm serve process and port 3001 behind; catch this readiness failure, clean up the tracked child, and then rethrow.

Useful? React with 👍 / 👎.

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.

2 participants