Skip to content

Comments

feat(runtime): add webpack require and bundler-ignore accessors#4457

Open
ScriptedAlchemy wants to merge 27 commits intomainfrom
cursor/bundler-runtime-require-access-725d
Open

feat(runtime): add webpack require and bundler-ignore accessors#4457
ScriptedAlchemy wants to merge 27 commits intomainfrom
cursor/bundler-runtime-require-access-725d

Conversation

@ScriptedAlchemy
Copy link
Member

Description

Centralizes access to __webpack_require__ and dynamic webpackIgnore/vite-ignore imports into dedicated helpers. This prevents direct global references from being inlined or patched during bundling, allowing downstream packages to import these functionalities externally.

Specifically:

  • Introduced getWebpackRequire() and getWebpackRequireOrThrow() in @module-federation/webpack-bundler-runtime/accessor for safe __webpack_require__ access.
  • Created importWithBundlerIgnore() in @module-federation/sdk to encapsulate /* webpackIgnore: true */ /* @vite-ignore */ dynamic imports, avoiding dependency cycles.
  • Migrated existing direct __webpack_require__ and magic-comment dynamic import usages in runtime-core and utilities to use these new helpers.
  • Cleaned up one direct __webpack_require__ reference within webpack-bundler-runtime itself.

Related Issue

Addresses the need to provide stable, importable accessors for webpack runtime globals and magic-comment-driven dynamic imports, as discussed in the conversation.

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.

Open in Cursor Open in Web

@cursor
Copy link

cursor bot commented Feb 17, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: bcff4b2

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/webpack-bundler-runtime Patch
@module-federation/runtime-core Patch
@module-federation/utilities Patch
@module-federation/node Patch
@module-federation/sdk Patch
@module-federation/enhanced Patch
@module-federation/nextjs-mf Patch
@module-federation/runtime-tools Patch
@module-federation/runtime Patch
@module-federation/bridge-react Patch
@module-federation/storybook-addon Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
@module-federation/rsbuild-plugin Patch
@module-federation/devtools Patch
@module-federation/cli Patch
@module-federation/data-prefetch Patch
@module-federation/dts-plugin Patch
@module-federation/esbuild Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/metro Patch
@module-federation/retry-plugin Patch
@module-federation/rspack Patch
@module-federation/rspress-plugin Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/bridge-vue3 Patch
@module-federation/inject-external-runtime-core-plugin Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
remote5 Patch
remote6 Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/metro-plugin-rnef Patch
website-new Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-shared Patch
@module-federation/error-codes Patch
create-module-federation Patch
@module-federation/treeshake-server Patch
@module-federation/treeshake-frontend 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
Copy link

netlify bot commented Feb 17, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit bcff4b2
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6996903661f1e90008e58892
😎 Deploy Preview https://deploy-preview-4457--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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 17, 2026

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/devtools@55fa8f6

@module-federation/cli

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/cli@55fa8f6

create-module-federation

pnpm add https://pkg.pr.new/module-federation/core/create-module-federation@55fa8f6

@module-federation/data-prefetch

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

@module-federation/dts-plugin

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

@module-federation/enhanced

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/enhanced@55fa8f6

@module-federation/error-codes

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

@module-federation/managers

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/managers@55fa8f6

@module-federation/manifest

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/manifest@55fa8f6

@module-federation/metro

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro@55fa8f6

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/modern-js-v3

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rspack@55fa8f6

@module-federation/rspress-plugin

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

@module-federation/runtime

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime@55fa8f6

@module-federation/runtime-core

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime-core@55fa8f6

@module-federation/runtime-tools

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

@module-federation/sdk

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/sdk@55fa8f6

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: 55fa8f6

@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2026

Bundle Size Report

7 package(s) changed, 34 unchanged.

Package Total dist Delta ESM gzip Delta
utils 125.2 kB +14.6 kB (+13.2%) 328 B no change
sdk 108.4 kB +3.8 kB (+3.6%) 8.1 kB no change
node 123.9 kB +830 B (+0.7%) 489 B no change
webpack-bundler-runtime 76.7 kB +213 B (+0.3%) 5.9 kB +21 B (+0.3%)
vue3-bridge 159.0 kB +143 B (+0.1%) 23.2 kB +17 B (+0.1%)
bridge-react 359.7 kB +126 B (+0.0%) 1.3 kB +1 B (+0.1%)
runtime-core 305.1 kB +83 B (+0.0%) 25.5 kB +1 B (+0.0%)

Total dist: 6.91 MB (+19.7 kB (+0.3%))
Total ESM gzip: 138.7 kB (+40 B (+0.0%))

@ScriptedAlchemy ScriptedAlchemy changed the title Bundler runtime require access feat(runtime): add webpack require and bundler-ignore accessors Feb 17, 2026
@ScriptedAlchemy ScriptedAlchemy marked this pull request as ready for review February 17, 2026 22:44
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: e3de5a394f

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a dedicated SDK subpath entrypoint for bundler/runtime-sensitive helpers, then migrates multiple runtime loaders to use those helpers instead of directly referencing __webpack_require__ or embedding bundler-specific magic comments in dynamic imports.

Changes:

  • Added @module-federation/sdk/bundler helpers: getWebpackRequire(), getWebpackRequireOrThrow(), and importWithBundlerIgnore().
  • Replaced direct __webpack_require__ usage and webpackIgnore/@vite-ignore inline imports across runtime-core, node, utilities, and webpack-bundler-runtime.
  • Added/updated Jest coverage to validate new fallbacks and ESM remote namespace wrapping behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/webpack-bundler-runtime/src/init.ts Uses SDK accessor to safely retrieve federation bundlerRuntime instead of direct __webpack_require__ access.
packages/webpack-bundler-runtime/tests/init.spec.ts Adds a test ensuring the init path falls back to the provided webpackRequire when the SDK accessor returns undefined.
packages/utilities/src/utils/pure.ts Switches script loader path from direct __webpack_require__.l to getWebpackRequireOrThrow().l.
packages/utilities/src/utils/pure.test.ts Adds tests ensuring loadScript doesn’t resolve webpack require when asyncContainer is already a promise or a factory.
packages/utilities/src/utils/importRemote.ts Centralizes ignored dynamic import usage and adds validation/wrapping for immutable ESM namespace containers.
packages/utilities/src/utils/importRemote.test.ts Adds a test verifying immutable namespace objects are wrapped before runtime flags are attached.
packages/sdk/src/bundler.ts Introduces new accessor + bundler-ignore dynamic import helper functions.
packages/sdk/project.json Adds bundler.ts as an additional Rollup entrypoint so it’s built as a standalone subpath export.
packages/sdk/package.json Exposes the new ./bundler export and typesVersions mapping.
packages/runtime-core/src/utils/load.ts Replaces inline ignored dynamic import with importWithBundlerIgnore.
packages/node/src/utils/hot-reload.ts Avoids direct global access by using getWebpackRequire() before clearing federation module cache.
packages/node/src/runtimePlugin.ts Replaces direct __webpack_require__ usage with an accessor-backed helper throughout runtime plugin logic.
packages/node/src/filesystem/stratagies.ts Uses accessor-backed webpack require for chunk url/base path resolution.
packages/node/src/tests/runtimePlugin.test.ts Updates test fixtures so mocked __webpack_require__ matches webpack’s callable function shape.
.changeset/twelve-forks-whisper.md Adds changeset for patch releases across affected packages and describes the new subpath export.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member Author

@ScriptedAlchemy ScriptedAlchemy left a comment

Choose a reason for hiding this comment

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

I found one regression in packages/utilities/src/utils/pure.ts: loadScript now resolves getWebpackRequireOrThrow() before checking whether the remote container is already present on globalScope. In non-webpack hosts with preloaded globals, this throws early (__webpack_require__ missing) instead of returning the existing container. Consider resolving webpack require only in the branch that actually calls webpackRequire.l(...).

Copy link
Member Author

Re-reviewed latest head ce7453a4cdaafc9363c9462cdb341fde4cddd768: one runtime regression still appears unresolved in packages/utilities/src/utils/pure.ts.

loadScript currently resolves getWebpackRequireOrThrow() before checking if globalScope[remoteGlobal] already exists. In non-webpack hosts with preloaded globals, this still throws early (__webpack_require__ missing) instead of returning the existing container. Please move webpack require resolution into the branch that actually calls webpackRequire.l(...).

@ScriptedAlchemy
Copy link
Member Author

@codex review the pr

Copy link
Member Author

Re-review on head f2ba7eb: loadScript in packages/utilities/src/utils/pure.ts still resolves getWebpackRequireOrThrow() before checking whether globalScope[remoteGlobal] already exists. In non-webpack hosts that preload the remote container on the global object, this now throws for missing __webpack_require__ and regresses loadScript/importDelegatedModule flows that intentionally skip script injection. Please defer webpack require resolution to the branch that actually calls webpackRequire.l(...).

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Nice work!

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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