Skip to content

fix: add RN polyfills as runtime modules for correct execution order#1340

Merged
jbroma merged 11 commits intomainfrom
fix/rn-polyfills-as-runtime-modules
Feb 26, 2026
Merged

fix: add RN polyfills as runtime modules for correct execution order#1340
jbroma merged 11 commits intomainfrom
fix/rn-polyfills-as-runtime-modules

Conversation

@jbroma
Copy link
Member

@jbroma jbroma commented Feb 2, 2026

Summary

  • Add polyfills as runtime modules instead of entry modules to ensure they execute before the webpack startup function
  • This means polyfills now run before Module Federation v2's embed_federation_runtime wrapper
  • Runtime modules execute during webpack runtime initialization, before __webpack_require__.x() is called

Changes

  • Move NativeEntryPlugin to its own folder
  • Add PolyfillsRuntimeModule that inlines polyfill code directly into the webpack runtime
  • Use additionalTreeRuntimeRequirements hook to add polyfills as runtime modules
  • Add comprehensive tests with MF v2 integration

Execution Order

With this change, the execution order is now:

  1. Polyfills (as runtime modules - before startup)
  2. MF v2 federation runtime (via embed_federation_runtime wrapper)
  3. InitializeCore, app entry, etc. (via prevStartup())

Related Issues

This could potentially close:

Test Plan

  • Added unit tests that verify polyfills are added as runtime modules
  • Added tests that verify execution order with MF v2
  • All existing tests pass

🤖 Generated with Claude Code

…execution order

Polyfills are now added as runtime modules instead of entry modules.
This ensures they execute before the webpack startup function, which
means they run before Module Federation v2 embed_federation_runtime
wrapper.

Runtime modules execute during webpack runtime initialization, before
__webpack_require__.x() (the startup function) is called. This guarantees
polyfills run before any MF v2 federation runtime code.

Changes:
- Move NativeEntryPlugin to its own folder
- Add PolyfillsRuntimeModule that inlines polyfill code
- Use additionalTreeRuntimeRequirements hook to add polyfills
- Add comprehensive tests with MF v2 integration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
repack-website Ready Ready Preview, Comment Feb 26, 2026 11:25am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: 9f8a6f0

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

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Patch
@callstack/repack-plugin-expo-modules Patch
@callstack/repack-plugin-nativewind Patch
@callstack/repack-plugin-reanimated Patch
@callstack/repack-dev-server Patch
@callstack/repack-init 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

@jbroma
Copy link
Member Author

jbroma commented Feb 2, 2026

needs more tests being added:

  1. needs tests with MFv1
  2. needs tests with older versions of MF2 (without __webpack_require__.x use)
  3. needs tests with webpack

@jbroma jbroma changed the title fix(NativeEntryPlugin): add polyfills as runtime modules for correct execution order fix: add polyfills as runtime modules for correct execution order Feb 2, 2026
@jbroma jbroma changed the title fix: add polyfills as runtime modules for correct execution order fix: add RN polyfills as runtime modules for correct execution order Feb 2, 2026
jbroma and others added 6 commits February 17, 2026 14:31
… add integration tests

Polyfills are now added as entry modules (processed by loaders) and
referenced by module ID from the runtime module via __webpack_require__,
fixing Flow-typed polyfills like error-guard.js being inlined as raw
source. The runtime module guards against chunks that don't contain
polyfill modules (e.g. MF container chunks).

Migrates NativeEntryPlugin tests from Jest unit tests (rspack-only) to
vitest integration tests covering both bundlers (webpack/rspack) and all
federation variants (none, MF v1, MF v2) with explicit execution order
assertions verified against real bundle output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…1.0)

Parameterize MF v2 tests across three @module-federation/enhanced
versions to verify polyfill execution order is maintained. All three
versions run with rspack; webpack tests only run the base version due
to serializer registration conflicts when loading multiple MF versions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace machine-specific absolute paths with <rootDir> placeholder
for deterministic snapshots across different development environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jbroma jbroma marked this pull request as ready for review February 26, 2026 11:20
@jbroma jbroma merged commit 7ee1b83 into main Feb 26, 2026
6 checks passed
@jbroma jbroma deleted the fix/rn-polyfills-as-runtime-modules branch February 26, 2026 11:30
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