-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
When a remote is offline, it takes multiple seconds on Windows before a remote is considered as unavailable. #2367
Comments
createScript hook is probbably what you are after: https://module-federation.io/plugin/dev/index.html#createscript |
@ScriptedAlchemy I have been on this road, the issue with the |
cant you throw the script after timeout? |
@ScriptedAlchemy not exactly. If I always throw an createScript({ url }) {
throw new Error(`Remote script "${url}" time-outed.`);
} Then, it kinds of work as expected since the await loadRemote("remote1/HelloWorld.jsx")
.then(mod => {
console.log("Loaded remote 1", mod);
})
.catch((error) => console.log("Failed to load remote 1", error)); But the error that is catched, is not the exception I thrown:
Then, if I delay the throw of the createScript({ url }) {
const element = document.createElement("script");
// Adding a timestamp to make sure the remote entry points are never cached.
// View: https://github.com/module-federation/module-federation-examples/issues/566.
element.src = `${url}?t=${Date.now()}`;
element.type = "text/javascript";
element.async = true;
let timeoutId = undefined;
element.onload = () => {
window.clearTimeout(timeoutId);
}
// Eagerly reject the loading of a script, it's too long when a remote is unavailable.
timeoutId = window.setTimeout(() => {
throw new Error(`Remote script "${url}" time-outed.`);
}, 500);
return element;
} It doesn't work anymore as the error is not catched anymore by the |
I also tried hustling something with the |
@patricklafrance https://github.com/module-federation/core/pull/2433/files hows that? This would change the return types of createScript return htmlElement | {script?: htmlElement, timeout?:number} return {script: myScript} |
@ScriptedAlchemy LGTM. One question thought, as a consumer, how do I handle:
Is it with either the |
Stale issue message |
Describe the bug
When a remote is offline, it takes multiple seconds on Windows before a remote is considered as unavailable, leaving the users with a blank page until the shared dependencies negotiation is done and the application is rendered.
According to my POC, a production build hosted on Netlify, when a remote is offline on Windows, it takes approximately 2500ms until the application is rendered.
On macOS, it takes about 20ms, which is a lot faster.
This delay doesn't seems to be related to any custom code but rather on how Windows behave when a connection is refused. It seems to retry 3 times before failing with
ERR_CONNECTION_REFUSED
.Similar issues has been observed for other projects:
@ryok90 and I have been extensively discussing about this issue in the past few days on the Module Federation Discord's server and came to the conclusion that there is currently nothing offered by Module Federation to actually help with this issue: https://discord.com/channels/1055442562959290389/1060923312043212920/threads/1232010715381108929
👉🏻 We believe that the solution would be for Module Federation to include a mechanism allowing the authors to specify a timeout delay to fetch a remote, rather the relying on the OS defaults.
When the host is configuring a remote with a
mf-manifest.json
file, it seems like the manifest is fetched withfetch
, a timeout could be introduced with anAbortSignal
.When the host is configuring a remote with a
remoteEntry.js
file, it seems like the remote is fetched with ascript
element. Something similar to the following code could be added to eagerly reject a remote when it is offline. This is how we used to do it with Module Federation 1.0:Thank you,
Patrick
Reproduction
https://pat-mf-enhanced-poc.netlify.app/
Used Package Manager
pnpm
System Info
Validations
The text was updated successfully, but these errors were encountered: