Skip to content

fix(retry-plugin): error-boundary should render until script retry finished#3127

Merged
danpeen merged 23 commits intomainfrom
fix/retry-plugin
Oct 30, 2024
Merged

fix(retry-plugin): error-boundary should render until script retry finished#3127
danpeen merged 23 commits intomainfrom
fix/retry-plugin

Conversation

@danpeen
Copy link
Copy Markdown
Contributor

@danpeen danpeen commented Oct 28, 2024

Description

fix: error-boundary should render until script retry finished. after fixing it will act like this:
20241028184710_rec_

Related Issue

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Oct 28, 2024

🦋 Changeset detected

Latest commit: d49710d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@module-federation/retry-plugin Patch
@module-federation/runtime Patch
host Patch
@module-federation/devtools Patch
@module-federation/data-prefetch Patch
@module-federation/dts-plugin Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/runtime-tools Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/enhanced Patch
@module-federation/modern-js Patch
@module-federation/rspack Patch
@module-federation/rsbuild-plugin Patch
@module-federation/storybook-addon Patch
3008-runtime-remote Patch
host-v5 Patch
host-vue3 Patch
@module-federation/modernjs Patch
modernjs-ssr-dynamic-nested-remote Patch
modernjs-ssr-dynamic-remote-new-version Patch
modernjs-ssr-dynamic-remote Patch
modernjs-ssr-host Patch
modernjs-ssr-nested-remote Patch
modernjs-ssr-remote-new-version Patch
modernjs-ssr-remote Patch
remote1 Patch
remote2 Patch
remote3 Patch
remote4 Patch
@module-federation/sdk Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch

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

@netlify
Copy link
Copy Markdown

netlify bot commented Oct 28, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit d49710d
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/6721adca955907000876c92f
😎 Deploy Preview https://deploy-preview-3127--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Copy Markdown
Contributor

@squadronai squadronai bot left a 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 introduces a fix to the error-boundary component in the retry-plugin, ensuring that it continues to render until the script retry process is finished. The changes aim to improve the user experience by preventing the component from prematurely unmounting during the retry operation.

The key changes include:

  • Introducing a new getModuleFactory hook in the FederationHost class, which is responsible for fetching the module factory for a remote entry. This is necessary for handling script retries in the error boundary.
  • Fixing the issue where the error-boundary component would unmount before the script retry was completed, leading to an inconsistent user experience.
  • Ensuring that the error-boundary component continues to render until the script retry process is finished, providing a more seamless and reliable application behavior.

These changes are focused on improving the integration of the retry-plugin with the existing codebase, enhancing the overall reliability and user experience of the application.

File Summaries
File Summary
packages/runtime/src/core.ts The code changes introduce a new getModuleFactory hook in the FederationHost class. This hook is responsible for fetching the module factory for a remote entry, which is necessary for handling script retries in the error boundary. The changes aim to ensure that the error boundary continues to render until the script retry is finished, providing a better user experience.
packages/runtime/src/module/index.ts The code changes introduce a fix to ensure that the error-boundary component continues to render until the script retry process is finished. This change ensures that the application's behavior aligns with the expected user experience, as depicted in the provided image.
packages/runtime/src/remote/index.ts The code changes introduce a fix to ensure that the error-boundary component continues to render until the script retry process is finished. This ensures a consistent user experience by preventing the component from prematurely unmounting during the retry operation.

@danpeen danpeen changed the title fix: fix script retry plugin fix(retry-plugin): error-boundary should render until script retry finished Oct 28, 2024
Copy link
Copy Markdown
Contributor

@squadronai squadronai bot left a 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: 7

Configuration

Squadron Mode: essential

Commits Reviewed

87a28620bc9139b07365b6755addb1924333e930...2d1c9fa08c658bcbd3e916bea49663d3edb7c745

Files Reviewed
  • packages/runtime/src/remote/index.ts
  • packages/runtime/src/module/index.ts
  • packages/runtime/src/core.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/blue-poets-play.md
  • apps/router-demo/router-host-2000/src/App.tsx
  • apps/router-demo/router-host-2000/src/runtime-plugin/retry.ts
  • apps/website-new/docs/en/plugin/plugins/retry-plugin.mdx
  • apps/website-new/docs/zh/plugin/plugins/retry-plugin.mdx
  • packages/retry-plugin/src/constant.ts
  • packages/retry-plugin/src/fetch-retry.ts
  • packages/retry-plugin/src/index.ts
  • packages/retry-plugin/src/types.d.ts

Comment on lines 210 to 212
const moduleOrFactory = (await module.get(
idRes,
expose,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The module.get() call should include the optional parameters to ensure proper error handling during retries. Add the loadFactory and remoteSnapshot parameters explicitly:

Suggested change
const moduleOrFactory = (await module.get(
idRes,
expose,
const moduleOrFactory = (await module.get(
idRes,
expose,
{ loadFactory: true },
remoteSnapshot
)))

This ensures consistent behavior with the retry plugin and error boundary, making the parameters explicit rather than relying on defaults.

Comment on lines 210 to 212
const moduleOrFactory = (await module.get(
idRes,
expose,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider wrapping the module.get() call in a try-catch block to handle potential failures during the remote module loading, especially since this is related to the retry plugin:

Suggested change
const moduleOrFactory = (await module.get(
idRes,
expose,
try {
const moduleOrFactory = (await module.get(
idRes,
expose,
{ loadFactory: true },
remoteSnapshot
));
} catch (error) {
// Let the error boundary handle the retry
throw error;
}

This makes error handling more explicit and ensures proper integration with the error boundary's retry mechanism.

Comment on lines +117 to +122
let moduleFactory;
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
remoteEntryExports,
expose,
moduleInfo: this.remoteInfo,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The moduleFactory assignment could benefit from destructuring and more descriptive variable naming. Here's a clearer way to write it:

Suggested change
let moduleFactory;
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
remoteEntryExports,
expose,
moduleInfo: this.remoteInfo,
});
const { moduleFactory: hookModuleFactory } = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
remoteEntryExports,
expose,
moduleInfo: this.remoteInfo,
});
let moduleFactory = hookModuleFactory;

This makes it clearer that we're getting the moduleFactory from the hook and allows for better tracking of where the value comes from.

Comment on lines +125 to +127
if (!moduleFactory) {
moduleFactory = await remoteEntryExports.get(expose);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fallback logic for moduleFactory could be more robust with error handling. Consider adding a try-catch block:

Suggested change
if (!moduleFactory) {
moduleFactory = await remoteEntryExports.get(expose);
}
if (!moduleFactory) {
try {
moduleFactory = await remoteEntryExports.get(expose);
} catch (error) {
throw new Error(`Failed to get module factory for ${expose}: ${error.message}`);
}
}

Comment on lines 129 to 131
assert(
moduleFactory,
`${getFMId(this.remoteInfo)} remote don't export ${expose}.`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The assertion message appears to be truncated. Ensure the error message provides complete information about what went wrong:

Suggested change
assert(
moduleFactory,
`${getFMId(this.remoteInfo)} remote don't export ${expose}.`,
assert(
moduleFactory,
`${getFMId(this.remoteInfo)} remote module factory not found for expose "${expose}"`
);

Comment on lines +118 to +127
getModuleFactory: new AsyncHook<
[
{
remoteEntryExports: RemoteEntryExports;
expose: string;
moduleInfo: RemoteInfo;
},
],
Promise<(() => Promise<Module>) | undefined>
>(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The AsyncHook type definition could be improved for better type safety and readability. Consider adding more specific types for the module factory return value:

Suggested change
getModuleFactory: new AsyncHook<
[
{
remoteEntryExports: RemoteEntryExports;
expose: string;
moduleInfo: RemoteInfo;
},
],
Promise<(() => Promise<Module>) | undefined>
>(),
getModuleFactory: new AsyncHook<
[{
remoteEntryExports: RemoteEntryExports;
expose: string;
moduleInfo: RemoteInfo;
}],
Promise<ModuleFactory | undefined>
>;
type ModuleFactory = () => Promise<Module>;

This makes the return type more explicit and self-documenting, while also allowing for better type checking and IDE support.

Comment on lines 115 to 117
[string, RequestInit],
Promise<Response> | void | false
>(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The first type parameter appears to be for a request interceptor. Consider adding a descriptive type alias to improve code readability:

Suggested change
[string, RequestInit],
Promise<Response> | void | false
>(),
type RequestInterceptor = [string, RequestInit];
// Then use it as:
RequestInterceptor,
Promise<Response> | void | false

This makes the purpose of the tuple type more clear and maintainable.

@danpeen danpeen merged commit ec31539 into main Oct 30, 2024
@danpeen danpeen deleted the fix/retry-plugin branch October 30, 2024 04:28
ciandt-crodrigues pushed a commit to ciandt-crodrigues/mf-core that referenced this pull request Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants