Skip to content

Comments

fix(rsbuild-plugin): support app SSR node target with custom environment#4427

Open
ScriptedAlchemy wants to merge 23 commits intomainfrom
fix/rsbuild-plugin-app-ssr-node-env
Open

fix(rsbuild-plugin): support app SSR node target with custom environment#4427
ScriptedAlchemy wants to merge 23 commits intomainfrom
fix/rsbuild-plugin-app-ssr-node-env

Conversation

@ScriptedAlchemy
Copy link
Member

Summary

This PR makes @module-federation/rsbuild-plugin support plugin-only SSR for Rsbuild app mode when using target: 'node' with a custom environment (for example ssr) without introducing breaking behavior.

Problem

Using pluginModuleFederation(..., { target: 'node', environment: 'ssr' }) in app-mode SSR was not reliable:

  • setup path hardcoded config.environments['mf']
  • custom node environment names could fail with undefined env/tooling paths
  • commonjs-like SSR outputs could be skipped by isMFFormat gating, which could leave mf_remote/* unresolved

Root Cause

  1. Node-target setup in pluginModuleFederation used a hardcoded env key (mf) instead of the configured environment option.
  2. onBeforeCreateCompiler returned early for non-MF-format configs before considering that target: 'node' needs to run for the selected environment even when output is commonjs-like.
  3. Node patching was broad (target === 'node' && isMFFormat(...)) rather than constrained to the selected environment.

Changes

  • Update node-target environment selection to use config.environments[environment].
  • Add explicit error when target: 'node' env is missing, including available environment names.
  • Keep default environment behavior ('mf') unchanged for backward compatibility.
  • Adjust compiler gating to always process the selected node-target environment.
  • Constrain node patching to only the selected environment.
  • Keep existing target: 'dual' restrictions/behavior intact (no app-mode dual enablement in this PR).

Tests

Added /packages/rsbuild-plugin/src/cli/node-target.spec.ts covering:

  • custom env support (environment: 'ssr') without requiring mf
  • clear missing-environment error
  • commonjs-like selected node env still receives MF plugin injection
  • target: 'dual' restriction remains unchanged for non-Rslib/non-Rspress callers
  • default mf environment behavior still works

Verification

  • pnpm -s nx run rsbuild-plugin:test
  • pnpm -s nx run rsbuild-plugin:build

Both pass.

Docs and Release Notes

  • Updated packages/rsbuild-plugin/README.md with app-mode node target example.
  • Updated website docs:
    • apps/website-new/docs/en/guide/build-plugins/plugins-rsbuild.mdx
    • apps/website-new/docs/zh/guide/build-plugins/plugins-rsbuild.mdx
  • Added changeset:
    • .changeset/quick-forks-wonder.md

@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 7f039bb
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/69969045ee194d0008c70548
😎 Deploy Preview https://deploy-preview-4427--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@changeset-bot
Copy link

changeset-bot bot commented Feb 12, 2026

🦋 Changeset detected

Latest commit: 7f039bb

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

This PR includes changesets to release 43 packages
Name Type
@module-federation/rsbuild-plugin Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
@module-federation/rspress-plugin Patch
remote5 Patch
remote6 Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
website-new Patch
@module-federation/runtime Patch
@module-federation/enhanced Patch
@module-federation/rspack 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-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/retry-plugin Patch
@module-federation/data-prefetch 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-rnc-cli Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/esbuild 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

Copy link

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

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: eb2b405e83

ℹ️ 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 on lines +376 to +380
if (
!isMFFormat(bundlerConfig) &&
!isRspress &&
!isNodeTargetEnvironmentConfig
) {

Choose a reason for hiding this comment

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

P1 Badge Restrict node-target flow to the selected environment

This condition still allows any MF-format bundler config to enter the node-target processing path even when its name does not match the configured environment, so target: 'node' can still affect extra environments. In builds with multiple MF-format environments, if the selected env is processed first, patchNodeMFConfig(moduleFederationOptions) mutates shared options and later non-selected environments receive node runtime/library settings, which can break client/web outputs; this is reproducible with environment: 'ssr' and an env order like ssr then client.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

Bundle Size Report

3 package(s) changed, 38 unchanged.

Package Total dist Delta ESM gzip Delta
rsbuild-plugin 119.4 kB +7.0 kB (+6.2%) 91 B no change
sdk 105.1 kB +492 B (+0.5%) 8.2 kB +65 B (+0.8%)
vue3-bridge 159.1 kB +235 B (+0.1%) 23.2 kB +14 B (+0.1%)

Total dist: 6.89 MB (+7.7 kB (+0.1%))
Total ESM gzip: 138.7 kB (+79 B (+0.1%))

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 14, 2026

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/devtools@7f039bb

@module-federation/cli

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/cli@7f039bb

create-module-federation

pnpm add https://pkg.pr.new/module-federation/core/create-module-federation@7f039bb

@module-federation/data-prefetch

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/data-prefetch@7f039bb

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/dts-plugin@7f039bb

@module-federation/enhanced

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/enhanced@7f039bb

@module-federation/error-codes

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/error-codes@7f039bb

@module-federation/managers

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/managers@7f039bb

@module-federation/manifest

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/manifest@7f039bb

@module-federation/metro

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro@7f039bb

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro-plugin-rnc-cli@7f039bb

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro-plugin-rnef@7f039bb

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/modern-js-v3@7f039bb

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/retry-plugin@7f039bb

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rsbuild-plugin@7f039bb

@module-federation/rspack

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rspack@7f039bb

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rspress-plugin@7f039bb

@module-federation/runtime

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime@7f039bb

@module-federation/runtime-core

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime-core@7f039bb

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime-tools@7f039bb

@module-federation/sdk

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/sdk@7f039bb

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/third-party-dts-extractor@7f039bb

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/treeshake-frontend@7f039bb

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/treeshake-server@7f039bb

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/webpack-bundler-runtime@7f039bb

@module-federation/bridge-react

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-react@7f039bb

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-react-webpack-plugin@7f039bb

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-shared@7f039bb

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-vue3@7f039bb

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/inject-external-runtime-core-plugin@7f039bb

commit: 7f039bb

@github-actions
Copy link
Contributor

github-actions bot commented Feb 14, 2026

Android Release APK for all devices

🔗 Download link.

Note: if the download link expires, please re-run the workflow to generate a new build.

Generated at 2026-02-15T21:46:23.410Z UTC

@github-actions
Copy link
Contributor

github-actions bot commented Feb 14, 2026

iOS Release APP for simulators

🔗 Download link.

Note: if the download link expires, please re-run the workflow to generate a new build.

Generated at 2026-02-15T21:51:57.206Z UTC

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.

2 participants