-
-
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
Can't create Error Fallback when any Remote fails. #2672
Comments
You can use a runtime plugin to handle such cases, since the v1 way or catching errors was unreliable and did not work for import from '' |
Couldn't try it yet due to the recent workload of my own. Gonna update as soon as I can. |
@ScriptedAlchemy, the error persists, I created a repo example: When a shared is set, an uncaughtable error is thrown. |
also interested in fix for this issue. |
@2heal1 this seems like a legitimate issue in the runtime. https://github.com/danieloprado/mf-offline Any ideas on how we can patch it so it doesn't fail |
The error happens because the default shared strategy is version first which means it will fetch remote entry first and then sync the sharedScope . But in this case , the remote is offline , so the request failed . It can be solved by change the default shared strategy without any source code change:
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
const sharedStrategy: () => FederationRuntimePlugin = () => ({
name: 'shared-strategy-plugin',
beforeInit(args) {
const { userOptions } = args;
const shared = userOptions.shared;
if (shared) {
Object.keys(shared).forEach((sharedKey) => {
const sharedConfigs = shared[sharedKey];
const arraySharedConfigs = Array.isArray(sharedConfigs)
? sharedConfigs
: [sharedConfigs];
arraySharedConfigs.forEach((s) => {
s.strategy = 'loaded-first';
});
});
}
return args;
},
});
export default sharedStrategy;
// rsbuild.config.ts
import path from 'path';
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
export default defineConfig({
server: { port: 3000 },
dev: { assetPrefix: 'http://localhost:3000' },
plugins: [pluginReact()],
html: {
title: 'MFE Offline Test'
},
tools: {
rspack: {
plugins: [
new ModuleFederationPlugin({
name: 'test_host',
remotes: {
'app_offline': 'app_offline@http://localhost:3001/manifest.json'
},
+ runtimePlugins:[path.resolve(__dirname,'shared-strategy.ts')],
shared: ['react'] // comment and it will work
})
]
}
}
}); And to prevent this issue , i think we should add |
yes with this one issue solved .
i personally think that its a good idea . |
Setting this a default strategy would be a nice DX boost |
Glad to stumble upon this solution as we were just noticing similar problems with our own Error Fallbacks not working. Question for @2heal1 about the implications of this strategy: does Or is the |
For those who are using rspack v1, and getting this warning on the console To solve this, you can just use this code
|
As the shared-strategy is mentioned as solution in several Issues, I will move the solution from @2heal1 to the Error catalog section of the docs for more transpareny |
Amazing, thank you! |
Docs updated, issue can be closed |
Describe the bug
Hey,
I was using the old Module Federation ('webpack/lib/container/ModuleFederationPlugin'), and decided to migrate to the new Module Federation 2.0.
However, in the previous MF version, I had to implement some ErrorBoundary components:
ErrorBoundary:
DynamicImport:
Usage of DynamicImport:
With this method, I was able to show Error UI when one of the remote is failing and has errors, or unavailable.
With Module Federation 2.0 I now get this error thrown by @module-federation/enhanced:
The versions of used packages:
webpack
:^5.57.1
,@module-federation/enhanced
:^0.2.1
,Example remotes object that I use:
Issue is that, webpack throws error and I cannot use my website as expected. Main goal is to keep Host(Shell) app to be continue working even if a remote fails. Users should be able to use other remotes and shell app layout.
I tried to implement the Dynamic System Host example. Here again, if I don't start one of the remotes, when user tries to load the failing remote, it immediately throws error and breaks the shell.
Wouldn't it be convenient that we can catch the Remote load errors and provide a fallback UI to the user?
Reproduction
https://github.com/module-federation/module-federation-examples/tree/master/dynamic-system-host
Used Package Manager
npm
System Info
Validations
The text was updated successfully, but these errors were encountered: