Skip to content

feat: enhance HoistContainerReferencesPlugin for better module hoisting#3903

Merged
ScriptedAlchemy merged 33 commits intomainfrom
feat/enhanced-hoist-container-refs
Jul 18, 2025
Merged

feat: enhance HoistContainerReferencesPlugin for better module hoisting#3903
ScriptedAlchemy merged 33 commits intomainfrom
feat/enhanced-hoist-container-refs

Conversation

@ScriptedAlchemy
Copy link
Copy Markdown
Member

@ScriptedAlchemy ScriptedAlchemy commented Jul 12, 2025

Summary

  • Enhanced HoistContainerReferencesPlugin to improve module hoisting for runtime chunks
  • Better support for runtimeChunk: 'single' configuration
  • Proper handling of remote modules using the new addRemoteDependency hook

Key Improvements

  1. Separate dependency handling: Container, federation runtime, and remote dependencies are now handled separately for better control
  2. Improved runtime chunk support: Changed runtime chunk detection to include all chunks with runtime (not just entry chunks)
  3. Remote module hoisting: Properly hoists remote modules using the new addRemoteDependency hook
  4. Simplified cleanup logic: More efficient cleanup that only disconnects modules from non-runtime chunks
  5. Comprehensive tests: Added unit tests to ensure the plugin works correctly

Files Changed

  • packages/enhanced/src/lib/container/HoistContainerReferencesPlugin.ts - Enhanced implementation
  • packages/enhanced/test/compiler-unit/container/HoistContainerReferencesPlugin.test.ts - New unit tests

- Separate handling for container, federation, and remote dependencies
- Improved support for runtimeChunk: 'single' configuration
- Proper remote module hoisting using the new addRemoteDependency hook
- Simplified cleanup logic for better performance
- Changed runtime chunk detection to include all chunks with runtime
- Added comprehensive unit tests
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 12, 2025

🦋 Changeset detected

Latest commit: 2cf38f1

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

This PR includes changesets to release 33 packages
Name Type
@module-federation/enhanced Patch
@module-federation/modern-js 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
@module-federation/modernjsapp Patch
remote5 Patch
website-new Patch
@module-federation/runtime 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/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

Base automatically changed from refactor/hook-renaming-cleanup-v2 to main July 15, 2025 20:04
@netlify
Copy link
Copy Markdown

netlify bot commented Jul 15, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 2cf38f1
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/68798a1e990c4d0008292f5c
😎 Deploy Preview https://deploy-preview-3903--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.

- Add browser caching for Playwright and Cypress
- Add explicit Cypress installation step
- Add PLAYWRIGHT_CACHE_HIT environment variable
- Add warm Nx cache step
- Use --parallel=4 for faster builds
- Align with build-and-test workflow strategy
- Add addRemoteDependency hook calls in RemoteModule.ts build method
- Ensures HoistContainerReferencesPlugin can properly track remote dependencies
- Calls hook for both RemoteToExternalDependency and FallbackDependency
- Brings current branch in sync with share-filter branch hook implementations
- Update tsconfig.json to use TypeScript project references structure
- Create missing tsconfig.lib.json and tsconfig.spec.json files
- Update project.json to use tsconfig.lib.json and add external dependencies
- Fix missing return statement in isStoryBook function
- Fix NODE_ENV access to use bracket notation for strict mode
- Brings rsbuild-plugin build configuration in line with other rollup packages
The main entry was pointing to the wrong path (packages/rsbuild-plugin/cli/src/index.ts)
when it should be packages/rsbuild-plugin/src/cli/index.ts. This was causing TypeScript
compilation errors during the build process.
…nfig

Similar to how SDK and other packages handle it, explicitly set the external
array in rollup config to ensure proper handling of workspace dependencies
during TypeScript compilation.
- Add missing "types" field to package.json (like rspack and sdk have)
- Add "noImplicitAny": false to tsconfig.json to match rspack's config
- This should help TypeScript resolve workspace dependencies correctly
Use path.resolve with process.cwd() to create absolute paths for the
input files, matching how other packages like rspack handle their
rollup configuration.
Match the path format used by other packages like data-prefetch
which use 'packages/package-name/src/...' relative paths.
…lution

The root cause was manually overriding rollupConfig.external which broke
nx's automatic workspace dependency resolution mechanism. By removing this
override and letting nx handle externals via project.json, TypeScript can
now properly resolve workspace dependencies during the rollup build.

This aligns rsbuild-plugin with working packages like cli and data-prefetch
that don't manually override external configuration.
Remove dep-graph.json and deps.json files that were accidentally
committed during the investigation process.
Add explicit TypeScript path mappings in tsconfig.json to help
the TypeScript compiler resolve workspace dependencies during
CI builds. This should resolve the module resolution issues
in stricter CI environments.
- Build SDK with skip cache first to ensure workspace dependencies are available
- Then build all packages with normal caching to resolve TypeScript module resolution issues
- This ensures workspace packages are properly built and available for dependent packages
Update the RemoteModule test build describe block to properly mock
the FederationModulesPlugin.getCompilationHooks method to match
the implementation on share-filter branch. This resolves the TypeError
about compilation argument validation.
Add comment to force CI to rebuild modernjs package which was missing files.
Ensure proper cleanup of module mocks between test runs to prevent
compilation instance validation errors.
Replace instance-level mocking with module-level mocking to avoid
webpack Compilation instance validation errors.
Fix the mock to directly export the plugin instead of wrapping it in
a default property, matching the actual default import pattern.
Trigger another build attempt to resolve missing dist files in CI.
ScriptedAlchemy and others added 8 commits July 15, 2025 18:13
Reduce parallel build workers in devtools workflow to prevent
race conditions and improve build reliability.
Allow the warm cache step to use cache for better performance
while keeping skip cache only for the main build step.
- Resolved conflict in .github/workflows/build-and-test.yml
- Kept main branch version as requested
- Remove Warm Nx Cache step
- Keep Run Affected Build with --skip-nx-cache flag
- Maintain all other cache configurations
- Remove CI fix comment from packages/modernjs/src/constant.ts
- Remove added comments from packages/rsbuild-plugin/rollup.config.js
- Reset packages/rsbuild-plugin/tsconfig.json paths to match main branch
- Keep extends and references in tsconfig.json
@ScriptedAlchemy ScriptedAlchemy force-pushed the feat/enhanced-hoist-container-refs branch from 6ae92a4 to 787ba92 Compare July 17, 2025 22:55
@ScriptedAlchemy ScriptedAlchemy merged commit bc3bc10 into main Jul 18, 2025
17 checks passed
@ScriptedAlchemy ScriptedAlchemy deleted the feat/enhanced-hoist-container-refs branch July 18, 2025 03:45
@2heal1 2heal1 mentioned this pull request Jul 24, 2025
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