Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: select import:false shared providers by strategy#841

Merged
gioboa merged 2 commits into
module-federation:mainfrom
dmchoi77:fix/import-false-shared-provider-selection
Jun 22, 2026
Merged

fix: select import:false shared providers by strategy#841
gioboa merged 2 commits into
module-federation:mainfrom
dmchoi77:fix/import-false-shared-provider-selection

Conversation

@dmchoi77

Copy link
Copy Markdown
Contributor

Summary

This fixes provider selection for import: false shared modules when the shared scope contains multiple providers for the same package.

Previously, the remote entry bridge picked the first provider from the shared scope object. That made the selected shared module depend on object key order rather than the configured share strategy, provider load state, version ordering, and strict version behavior.

When import: false shared modules are configured, the generated remote entry imports the public runtime share helper and emits a small bridge for selecting providers before seeding the __mf_module_cache__ entry.

This aligns the import: false bridge with the documented shareStrategy behavior for version-first and loaded-first.

Problem

The import: false bridge selected a provider like this:

const provider = versions && versions[Object.keys(versions)[0]];

When multiple providers existed for the same shared package, this could select whichever version appeared first in the object.

Example failure before this change:

const versions = {
  '18.3.1': react18Provider,
  '19.2.0': react19Provider,
};

If 18.3.1 was inserted first, Object.keys(versions)[0] selected the React 18 provider. A remote configured with react as singleton, import: false, and requiredVersion: '^19.0.0' could then seed __mf_module_cache__.share['default:react'] with React 18 before the exposed module imported React. Since singleton cache entries are reused, later shared imports could keep reading the wrong provider instead of the React 19 provider expected by version-first.

The generated share config also did not include strictVersion, so strict version mismatch handling was not preserved when the bridge delegated selection to the runtime helper.

Changes

@pkg-pr-new

pkg-pr-new Bot commented Jun 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@module-federation/vite@841

commit: a3a2856

@dmchoi77

Copy link
Copy Markdown
Contributor Author

@gioboa CI was failing because an integration test still asserted the old first-key provider selection logic.
I updated the assertion to expect the new __mfSelectSharedProvider path and pushed the fix. Could you please review it when you get a chance?πŸ™

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this PR, I'll check this out in few hours πŸ‘

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tests With Different Frameworks

Screenshot 2026-06-22 at 11 13 10

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @dmchoi77
this looks awesome to me πŸ‘

@gioboa gioboa merged commit fc1f67b into module-federation:main Jun 22, 2026
19 checks passed
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.

2 participants