Skip to content

fix: incorrect version provided to the scope when multiple versions are available #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

RavenColEvol
Copy link
Contributor

Firstly I want to thank for taking such initiative to solve this problem!

Description

I tried using this package to create remoteEntry from vite and consume in webpack. But I was constantly facing a problem of double react getting loaded. On deep investigation I understood that the webpack in shareScope was providing 2 versions of react { 16: //, 18: // } even though I provided required verison 18 in the federationPlugin it used to take 16 since the code assumes only one package will be coming.

I tried to fix it by

  1. allow all versions to be part of federation_shared so that whichever is required will be accessible
  2. based on requiredVersion proper package will be provided to the scope

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Code of Conduct and follow the Commit Convention guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

globalThis.__federation_shared__[scope] = globalThis.__federation_shared__[scope] || {};
const shared= globalThis.__federation_shared__[scope];
(shared[key] = shared[key]||{})[versionKey] = versionValue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before

__federation_shared__ = {
  default: { react: { 16: /*code*/ } }
}

After

__federation_shared__ = {
  default: { react: { 16: /*code*/ , 18: /*code*/ } }
}

@Jiannan-dev
Copy link
Collaborator

Thanks 🙏

@Jiannan-dev Jiannan-dev merged commit ff0527f into originjs:main Mar 14, 2025
8 checks passed
@RavenColEvol RavenColEvol deleted the fix-multiple-version-of-package branch March 14, 2025 08:17
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