-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
fix: clear globalLoading cache in node env #3173
Conversation
🦋 Changeset detectedLatest commit: 035aa79 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
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 |
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.
Summary
This pull request aims to address an issue with the bundler, where the GLOBAL_LOADING_REMOTE_ENTRY
was being bundled into a shared object closure, preventing it from being accessed via globalThis
. The changes focus on clearing the globalLoading
cache in the node environment to resolve this problem.
The key changes include:
- Removing the assignment of an empty object to the
__GLOBAL_LOADING_REMOTE_ENTRY__
property of the global scope in thehot-reload.ts
file, which was causing issues with accessing theglobalLoading
cache. - Iterating over the keys in the
globalLoading
object and deleting them in theglobal.ts
file, ensuring that the cache is properly cleared when theresetFederationGlobalInfo()
function is called.
These modifications should help improve the overall functionality of the application by addressing the issue with the GLOBAL_LOADING_REMOTE_ENTRY
and ensuring that the globalLoading
cache is properly cleared in the node environment.
File Summaries
File | Summary |
---|---|
packages/node/src/utils/hot-reload.ts | The code changes aim to clear the globalLoading cache in the node environment. The changes involve removing the assignment of an empty object to the __GLOBAL_LOADING_REMOTE_ENTRY__ property of the global scope, which was causing issues with accessing the globalLoading cache. This modification should help resolve the problem and improve the overall functionality of the application. |
packages/runtime/src/global.ts | The code changes aim to clear the globalLoading cache in the node environment. This is done by iterating over the keys in the globalLoading object and deleting them, ensuring that the cache is properly cleared when the resetFederationGlobalInfo() function is called. |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Incremental Review
Comments posted: 6
Configuration
Squadron Mode: essential
Commits Reviewed
54bfd1cf730a842fd323d88d1b7c8ff72678f0ce...fb49d7518b62c3f579702986bae95a61f1ea03b1
Files Reviewed
- packages/node/src/utils/hot-reload.ts
- packages/runtime/src/helpers.ts
Files Ignored
These files were ignored due to the filter in the squadron.yaml file.
- .changeset/beige-cheetahs-tap.md
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.
Can I get a canary version so that I can test whether this fixes the issue ?
Object.keys(helpers.global.globalLoading).forEach((key) => { | ||
delete helpers.global.globalLoading[key]; | ||
}); |
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.
We already have a function exposed as part of helpers:
helpers.global.resetFederationGlobalInfo();
Can we move this logic to that function ?
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.
Ohh I forget this function , yes , we can do it , let me move it
Tested and worked! @2heal1 |
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.
Incremental Review
Comments posted: 3
Configuration
Squadron Mode: essential
Commits Reviewed
fb49d7518b62c3f579702986bae95a61f1ea03b1...a62ac79219d2e78753aa26dcad8bec74894c7eb4
Files Reviewed
- packages/runtime/src/global.ts
Files Ignored
These files were ignored due to the filter in the squadron.yaml file.
- .changeset/beige-cheetahs-tap.md
Object.keys(globalLoading).forEach((key) => { | ||
delete globalLoading[key]; | ||
}); |
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.
The current approach to clearing the globalLoading object could be simplified using Object.keys().length. A more efficient way would be to reassign the object:
Object.keys(globalLoading).forEach((key) => { | |
delete globalLoading[key]; | |
}); | |
// Reset globalLoading to empty object | |
Object.assign(globalLoading, {}); |
This achieves the same result with better performance, especially when dealing with objects that have many properties.
packages/runtime/src/global.ts
Outdated
globalThis.__FEDERATION__.moduleInfo = {}; | ||
globalThis.__FEDERATION__.__SHARE__ = {}; | ||
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; |
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.
Consider adding type safety checks before resetting these global objects to prevent potential runtime errors:
globalThis.__FEDERATION__.moduleInfo = {}; | |
globalThis.__FEDERATION__.__SHARE__ = {}; | |
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; | |
if (!globalThis.__FEDERATION__) { | |
globalThis.__FEDERATION__ = {}; | |
} | |
globalThis.__FEDERATION__.moduleInfo = {}; | |
globalThis.__FEDERATION__.__SHARE__ = {}; | |
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; |
packages/runtime/src/global.ts
Outdated
globalThis.__FEDERATION__.moduleInfo = {}; | ||
globalThis.__FEDERATION__.__SHARE__ = {}; | ||
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; | ||
|
||
Object.keys(globalLoading).forEach((key) => { | ||
delete globalLoading[key]; | ||
}); | ||
} |
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.
Consider adding error handling around the global state reset operations. If any of these operations fail, it could leave the system in an inconsistent state. A try-catch block would help handle potential errors gracefully:
globalThis.__FEDERATION__.moduleInfo = {}; | |
globalThis.__FEDERATION__.__SHARE__ = {}; | |
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; | |
Object.keys(globalLoading).forEach((key) => { | |
delete globalLoading[key]; | |
}); | |
} | |
try { | |
if (!globalThis.__FEDERATION__) { | |
globalThis.__FEDERATION__ = {}; | |
} | |
globalThis.__FEDERATION__.moduleInfo = {}; | |
globalThis.__FEDERATION__.__SHARE__ = {}; | |
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; | |
Object.assign(globalLoading, {}); | |
} catch (error) { | |
console.error('Failed to clear federation cache:', error); | |
throw error; // Re-throw to maintain error propagation | |
} |
@MadaraUchiha-314 Yeah sure , try this |
a62ac79
to
035aa79
Compare
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.
Incremental Review
Comments posted: 1
Configuration
Squadron Mode: essential
Commits Reviewed
5fc6045a328c943878328da3349f945d2610c999...035aa792e5a2d3c6e0438513f77628a28263d3b6
Files Reviewed
- packages/runtime/src/global.ts
Files Ignored
These files were ignored due to the filter in the squadron.yaml file.
- .changeset/beige-cheetahs-tap.md
CurrentGlobal.__FEDERATION__.moduleInfo = {}; | ||
CurrentGlobal.__FEDERATION__.__SHARE__ = {}; | ||
CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {}; |
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.
The code resets global federation state without checking if these properties exist first. Add property existence checks to prevent potential undefined errors:
CurrentGlobal.__FEDERATION__.moduleInfo = {}; | |
CurrentGlobal.__FEDERATION__.__SHARE__ = {}; | |
CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {}; | |
if (CurrentGlobal.__FEDERATION__.moduleInfo) CurrentGlobal.__FEDERATION__.moduleInfo = {}; | |
if (CurrentGlobal.__FEDERATION__.__SHARE__) CurrentGlobal.__FEDERATION__.__SHARE__ = {}; | |
if (CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__) CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {}; |
This defensive programming approach prevents errors if any of these objects haven't been initialized yet.
Note: The existing comments already cover other important aspects like type safety, error handling, and the globalLoading optimization, so I've focused on this additional safety concern.
Description
The bundler bundle GLOBAL_LOADING_REMOTE_ENTRY into share object closure ,and it can not access via globalThis .
This PR aims to solve this issue and clear globalLoading internally in revalidate method.
Related Issue
#3119
Types of changes
Checklist