Skip to content

feat(app-tools): integrate built-in module federation - #9035

Open
2heal1 wants to merge 15 commits into
feat/module-federation-builtinfrom
feat/module-federation-builtin-core
Open

2heal1 wants to merge 15 commits into
feat/module-federation-builtinfrom
feat/module-federation-builtin-core

Conversation

@2heal1

@2heal1 2heal1 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Integrate Modern.js v3 Module Federation as a built-in app-tools capability. Applications install @module-federation/enhanced and retain module-federation.config.ts, which app-tools detects automatically. Set moduleFederation: false to keep the legacy plugin. Simultaneous activation fails before legacy configuration evaluation, including nested plugin registration.

  • Preserve CSR/SSR configuration, merged manifests, Node assets and bounded caching, data-fetch middleware, development revalidation, DTS and the existing secondary shared tree-shaking switch.
  • Keep the adapter on lower-level builder, plugin, utility and server APIs, without reverse dependencies on app-tools or runtime. Retain root CLI registration, config-plugin, ssr-plugin, data-fetch-server-plugin, configuration types and package metadata. Resolve injected SSR/server files internally under strict pnpm layouts and CJS/ESM outputs.
  • Retain CLI integration entry points and type exports. Remove the broad Enhanced runtime forwarding facade, its obsolete alias and DTS injection, and unused Bridge forwarding entries. Applications import Enhanced runtime and Bridge directly. Future framework-specific runtime APIs remain outside this change and will follow the framework metaName alias convention.
  • Default top-level shareStrategy to loaded-first at build time while honoring explicit configuration and custom runtime plugins. Remove obsolete runtime strategy and fetch/IPv4 compatibility helpers under the Node >=20 baseline. Remove redundant browser crypto/stream/vm fallbacks while retaining the existing browser exclusion of Node utilities.
  • Use published MF preview 0.0.0-feat-enhanced-runtime-unification-20261022085654. Runtime APIs and types use @module-federation/enhanced/runtime without direct runtime/runtime-core application dependencies. Reuse the preview's SSRPublicPathPlugin, including its matching Rslib Node/dual producer fix.
  • Prefer final bundler output paths, then the resolved application distDirectory and configured server directory with SERVER_BUNDLE_DIRECTORY. Use Modern's selected development port. Serve federated JavaScript from the configured server output directory.
  • Use the shared logger from @modern-js/utils for CLI configuration, bundler and development-server messages. Remove the MF SDK logger wrapper; application runtime entries do not reference it.
  • Add a dedicated Linux MF e2e workflow for pull requests targeting the integration branch or main, pushes to either branch, and manual dispatch. Build app-tools/runtime with their dependencies, install Puppeteer's pinned Chrome and run the MF package's serial dev/production suite, stopping at the first failure with fixture diagnostics. Exclude MF cases from the general framework runner so its shorter setup timeout does not apply.
  • Preserve Modern router integration while honoring explicit Bridge router settings. Migrate the lab and four official examples, retain legacy compatibility coverage, and update documentation and changesets.

Validation

  • Adapter CJS/ESM/declaration builds and app-tools build passed.
  • Adapter unit tests: 50 passed on Node 20.20.2 and Node 24.18.1.
  • App-tools unit tests: 122 passed.
  • Complete MF lab before the CLI export metadata restoration: 7 files, 87 tests passed in 4m 29s using the existing Chrome and one test worker, covering development and production. The preceding parallel run while independent example validation was active encountered setup/navigation timeouts and a chunk-loading failure; these did not reproduce in the full serial run.
  • Four official examples passed independent production builds and TypeScript checks using current app-tools/adapter tarballs and published MF packages. Host builds consumed live remote manifests and downloaded remote types.
  • The restored CLI entries load from an installed tarball under CJS and ESM. Type consumption passes with Bundler resolution and a NodeNext CJS consumer. Runtime forwarding subpaths remain unavailable. The existing default server-export declaration has an ESM NodeNext interoperability limitation; that check did not pass, and this metadata-only restoration does not change declaration formats.
  • Regression tests cover final output paths, configured roots/server directories, default server directory, selected development port, configured server asset prefixes and preservation of user DTS options.
  • Changed-source lint/formatting, dependency-version consistency and diff checks passed.
  • Workflow validation with actionlint, the exact Nx build command and test collection checks passed: the dedicated suite collects all 87 cases, and the general framework suite excludes them.
  • Initial Linux runs exposed fixture port/hydration races and progressive dev-server slowdown. Diagnostics showed all three dev processes sustaining about one CPU core and growing from roughly 750 MB to 3.4 GB RSS. TCP connections took milliseconds while static-response headers took seconds. Local CPU profiles traced the background work to type-checker Chokidar dependency traversal and glob matching.
  • Fixture tsconfigs now explicitly exclude node_modules and build directories. The type-checker directory watcher consumes raw tsconfig exclusions and did not inherit TypeScript's implicit node_modules exclusion, so it traversed the linked monorepo dependency tree. Keep type checking/DTS enabled. Restore the original 60-second test budgets instead of relying on the interim 120-second extension.
  • After the watcher fix, all 87 cases passed locally under Node 22.23.2 with CI=true and resource diagnostics enabled in 4m39s. Dev-server CPU returned near idle and hot-revalidation took about 0.5s. Lint/format/actionlint/diff checks passed. Linux validation of the fix passed on commit 947204d: all 7 files and 87 dev/production tests passed in 6m35s, with the original 60-second budgets and retry:0. Recovery comparisons now take 2.4–2.6 seconds, SSR data-error cases about 0.4 seconds, and hot-revalidation 1 second. Dev-process RSS remains around 470–590 MB during the recovery sequence. The Diff workflow also passed.
  • No internal document URLs were added.

Related Links

Target feat/module-federation-builtin. New framework runtime APIs, service apps and additional tree-shaking work remain outside this change. No automatic merge.

Checklist

  • I have added a changeset.
  • I have updated the documentation.
  • I have added tests to cover my changes.

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 947204d

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

This PR includes changesets to release 121 packages
Name Type
@modern-js/plugin-module-federation Minor
@modern-js/app-tools Minor
@modern-js/adapter-rstest Minor
@modern-js/plugin-bff Minor
@modern-js/plugin-ssg Minor
@modern-js/plugin-styled-components Minor
@modern-js/plugin-i18n Minor
@modern-js/image Minor
@modern-js/runtime Minor
@modern-js/plugin-polyfill Minor
@integration-test/alias-set Patch
app-document Patch
async-entry-test Patch
tmp Patch
bff-api-app Patch
bff-client-app Patch
bff-indep-client-app Patch
bff-hono Patch
integration-clean-dist-path Patch
integration-compatibility Patch
integration-custom-dist-path Patch
custom-file-system-entry Patch
integration-custom-template Patch
deploy Patch
deploy-server Patch
dev-server Patch
integration-disable-html Patch
entries-app-builder Patch
app-custom-entries Patch
app-custom-routes-runtime Patch
app-custom Patch
app-entry Patch
app-route Patch
app-entry-server Patch
i18n-app-csr-html-lang Patch
i18n-app Patch
i18n-app-ssr-html-lang Patch
i18n-app-ssr Patch
i18n-custom-i18n-wrapper Patch
i18n-mf-app-provider Patch
i18n-mf-component-provider Patch
i18n-mf-consumer Patch
i18n-routes Patch
i18n-routes-ssr Patch
@integration-test/image-component Patch
main-entry-name Patch
nonce Patch
pure-esm-project Patch
react-compiler-test Patch
routes-match Patch
routes Patch
app-rsbuild-hooks Patch
rsc-csr-app Patch
rsc-csr-routes Patch
rsc-ssr-app Patch
rsc-ssr-routes Patch
basic-app-rstest-browser Patch
basic-app-rstest Patch
runtime-custom-plugin Patch
runtime-custom-config-plugin Patch
select-mul-entry-test Patch
select-one-entry-test Patch
server-config Patch
server-esm-tsx Patch
server-json-script Patch
server-monitors Patch
server-prod Patch
server-routes Patch
@source-code-build/app Patch
ssg-fixtures-mega-list-routes Patch
ssg-fixtures-nested-routes Patch
ssg-fixtures-simple Patch
ssg-fixtures-web-server Patch
ssr-base-async-entry-test Patch
ssr-base-async-pre-entry-test Patch
ssr-base-json-test Patch
ssr-base-test Patch
ssr-base-fallback-test Patch
init Patch
ssr-base-loadable Patch
ssr-partial-test Patch
rsc-closing-tags-test Patch
ssr-script-loading Patch
ssr-useid-test Patch
ssr-streaming-inline-test Patch
ssr-streaming-lazy-test Patch
ssr-streaming-test Patch
styled-components-stream Patch
styled-components-string Patch
integration-tailwindcss-v2 Patch
integration-tailwindcss-v3 Patch
integration-tailwindcss-v4-tools Patch
integration-tailwindcss-v4 Patch
tmp-dir Patch
tools-plugin-options-test Patch
write-to-dist Patch
@modern-js/bundle-diff-benchmark Minor
@modern-js/main-doc Minor
@modern-js/tsconfig Minor
@modern-js/builder Minor
@modern-js/plugin-data-loader Minor
@modern-js/render Minor
@modern-js/bff-core Minor
@modern-js/bff-runtime Minor
@modern-js/server-core Minor
@modern-js/create-request Minor
@modern-js/prod-server Minor
@modern-js/server-runtime Minor
@modern-js/server Minor
@modern-js/server-utils Minor
@modern-js/create Minor
@modern-js/i18n-utils Minor
@modern-js/plugin Minor
@modern-js/runtime-utils Minor
@modern-js/sandpack-react Minor
@modern-js/types Minor
@modern-js/utils Minor
@modern-js/rslib Minor
@scripts/prebundle Patch
@scripts/rstest-config Patch
@scripts/release-node 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

@github-actions

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

📊 Quick Summary
Project Total Size Change
bundle-diff 502.0 KB 0

Generated by Rsdoctor GitHub Action

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.

1 participant