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
Proposed fix to module federation to stop ignoring the singleton flag when requiredVersion is false #14884
Conversation
… when requiredVersion is false
|
For maintainers only:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add test cases
You can edit test case in to run only your test case |
And there are more regarding sharing in
|
Code changes look good. |
@colacadstink Thanks for your update. I labeled the Pull Request so reviewers will review it again. @vankop Please review the new changes. |
Massive thank you @sokra for pointing me to the sharing tests - I was able to very easily modify that to test what I added (and ended up catching a typo in the process - this is why we test!) |
Hi @colacadstink. Just a little hint from a friendly bot about the best practice when submitting pull requests:
You don't have to change it for this PR, just make sure to follow this hint the next time you submit a PR. |
Thanks |
This addresses (fixes #14795) . Previously, when using module federation, if requiredVersion was false, the singleton flag would be entirely ignored. Since it's entirely valid to require one instance of a package be instantiated, but not care at all what version it is, this seems like an oversight.
What kind of change does this PR introduce?
The core of this change is in
ConsumeSharedModule.codeGeneration
, which now includes logic for when requiredVersion is false but singleton is true. Specifically, it causes the generated code to call one of two new functions - loadSingleton, or loadSingletonFallback if a fallback is present. The code for these new functions is located inConsumeSharedRuntimeModule.generate
, along with a helper function, getSingleton, which acts similarly to getSingletonVersion but without doing a semver check.Did you add tests for your changes?
I did not. Pardon my ignorance, but I can't figure out where or how to add a test for this.
Does this PR introduce a breaking change?
No, or at least, I wouldn't think so. This technically changes the behavior of webpack, but I'd be shocked if anyone was depending on the existing behavior, given how this appears to be a bug instead of an intended feature.
What needs to be documented once your changes are merged?
Nothing, I don't think - this code change makes the code work as I'd expect from the current documentation, so I don't think any changes would be needed.