Skip to content
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

feat: add remote-entry script resource retry for retry-plugin #3321

Merged
merged 7 commits into from
Dec 10, 2024

Conversation

danpeen
Copy link
Contributor

@danpeen danpeen commented Dec 5, 2024

Description

feat: add remote-entry script resource retry for retry-plugin

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.

Copy link

changeset-bot bot commented Dec 5, 2024

🦋 Changeset detected

Latest commit: a2f18c9

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

This PR includes changesets to release 27 packages
Name Type
@module-federation/retry-plugin Patch
@module-federation/runtime 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/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/enhanced Patch
@module-federation/modern-js Patch
@module-federation/rspack Patch
@module-federation/rsbuild-plugin Patch
@module-federation/storybook-addon Patch
@module-federation/modernjsapp Patch
@module-federation/sdk Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/error-codes Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch
website-new 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

Copy link

netlify bot commented Dec 5, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 5607734
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/6752f8eb6c4b2c0008ac7571
😎 Deploy Preview https://deploy-preview-3321--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
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

The key changes in this pull request are:

  • Introduce a new loadEntryError hook in the FederationHost class to handle errors that may occur during the loading of remote entry scripts. This hook provides access to relevant information such as the getRemoteEntry function, the FederationHost instance, the RemoteInfo object, the RemoteEntryExports, and a globalLoading object. This allows for more robust error handling and potentially retrying the remote entry script loading process.
  • Add a try-catch block to the getRemoteEntry function, which triggers a custom loadEntryError event in case of a failure. This event can be used to implement a retry mechanism or other error handling logic for remote-entry script resource retries.

These changes aim to improve the reliability and resilience of the remote entry script loading process, which is an important aspect of the federation-based architecture used in this project.

File Summaries
File Summary
packages/runtime/src/core.ts The code changes introduce a new loadEntryError hook in the FederationHost class. This hook is designed to handle errors that may occur during the loading of remote entry scripts. The hook provides access to various relevant information, such as the getRemoteEntry function, the FederationHost instance, the RemoteInfo object, the RemoteEntryExports, and a globalLoading object. This addition allows for more robust error handling and potentially retrying the remote entry script loading process.
packages/runtime/src/module/index.ts The code changes introduce a new feature to handle remote-entry script resource retries for the retry-plugin. The key modifications include adding a try-catch block to the getRemoteEntry function, which allows for error handling and triggering a custom loadEntryError event in case of a failure. This event can be used to implement a retry mechanism or other error handling logic.

Copy link
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: 3

Configuration

Squadron Mode: essential

Commits Reviewed

cafc5f040274ccb274f13d16910146415e8bd973...18b8abb96e41b8e94e32b7296edc1aa34af8f868

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

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

  • .changeset/small-eyes-change.md
  • apps/router-demo/router-host-2000/rsbuild.config.ts
  • apps/router-demo/router-host-2000/src/App.tsx
  • packages/retry-plugin/src/index.ts
  • packages/retry-plugin/src/util.ts

packages/runtime/src/module/index.ts Outdated Show resolved Hide resolved
packages/runtime/src/module/index.ts Outdated Show resolved Hide resolved
packages/runtime/src/module/index.ts Show resolved Hide resolved
Copy link
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: 5

Configuration

Squadron Mode: essential

Commits Reviewed

cafc5f040274ccb274f13d16910146415e8bd973...e23607305c2fe98c12cad9827cd295cca1e95b25

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

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

  • .changeset/small-eyes-change.md
  • apps/router-demo/router-host-2000/rsbuild.config.ts
  • apps/router-demo/router-host-2000/src/App.tsx
  • packages/retry-plugin/src/index.ts
  • packages/retry-plugin/src/util.ts

packages/runtime/src/core.ts Show resolved Hide resolved
packages/runtime/src/core.ts Show resolved Hide resolved
packages/runtime/src/module/index.ts Show resolved Hide resolved
packages/runtime/src/module/index.ts Outdated Show resolved Hide resolved
packages/runtime/src/module/index.ts Show resolved Hide resolved
@2heal1
Copy link
Member

2heal1 commented Dec 6, 2024

can you add new test cases for the feature?

let remoteEntryExports;
const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
remoteEntryExports =
await this.host.loaderHook.lifecycle.getRemoteEntryExports.emit({
Copy link
Member

Choose a reason for hiding this comment

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

it looks like the same as loadEntry hook

Copy link
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: 5

Configuration

Squadron Mode: essential

Commits Reviewed

b9187f5c558c19679dfef7ba5b577c075bc69334...a2f18c98d3a91e1cb319f51a11e3f16bb333e375

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

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

  • .changeset/small-eyes-change.md
  • apps/router-demo/router-host-2000/rsbuild.config.ts
  • apps/router-demo/router-host-2000/src/App.tsx
  • packages/retry-plugin/src/fetch-retry.ts
  • packages/retry-plugin/src/index.ts
  • packages/retry-plugin/src/types.d.ts
  • packages/retry-plugin/src/util.ts

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

Choose a reason for hiding this comment

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

The AsyncHook type parameters could be more descriptive. Consider using a type alias to better document the purpose of this hook:

Suggested change
[string, RequestInit],
Promise<Response> | void | false
>(),
type RemoteEntryRequestHookParams = [string, RequestInit];
type RemoteEntryRequestResult = Promise<Response> | void | false;
requestRemoteEntry: new AsyncHook<
RemoteEntryRequestHookParams,
RemoteEntryRequestResult
>(),

Comment on lines 118 to 121
getRemoteEntryExports: new AsyncHook<
[
{
getRemoteEntry: typeof getRemoteEntry;
Copy link
Contributor

Choose a reason for hiding this comment

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

The loadEntryError hook's parameter structure appears to be incomplete and lacks type information. Consider adding proper type definitions for error handling:

Suggested change
getRemoteEntryExports: new AsyncHook<
[
{
getRemoteEntry: typeof getRemoteEntry;
loadEntryError: new AsyncHook<
[{
error: Error;
origin: string;
retryCount?: number;
}],
void
>(),

Comment on lines 39 to 44
const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
remoteEntryExports =
await this.host.loaderHook.lifecycle.getRemoteEntryExports.emit({
getRemoteEntry,
origin: this.host,
remoteInfo: this.remoteInfo,
Copy link
Contributor

Choose a reason for hiding this comment

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

The initial getRemoteEntry call could benefit from more specific error typing and context. Consider adding a custom error type:

Suggested change
const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
remoteEntryExports =
await this.host.loaderHook.lifecycle.getRemoteEntryExports.emit({
getRemoteEntry,
origin: this.host,
remoteInfo: this.remoteInfo,
try {
remoteEntryExports = await getRemoteEntry({
origin: this.host,
remoteInfo: this.remoteInfo,
remoteEntryExports: this.remoteEntryExports,
}) as RemoteEntryExports;
} catch (err: unknown) {

Comment on lines 47 to 56
uniqueKey,
});

// get exposeGetter
if (!remoteEntryExports) {
remoteEntryExports = await getRemoteEntry({
origin: this.host,
remoteInfo: this.remoteInfo,
remoteEntryExports: this.remoteEntryExports,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The error recovery flow could benefit from a timeout to prevent hanging in case the error handler itself fails. Add a timeout wrapper:

Suggested change
uniqueKey,
});
// get exposeGetter
if (!remoteEntryExports) {
remoteEntryExports = await getRemoteEntry({
origin: this.host,
remoteInfo: this.remoteInfo,
remoteEntryExports: this.remoteEntryExports,
});
const RECOVERY_TIMEOUT = 15000; // 15 seconds timeout
remoteEntryExports = await Promise.race([
this.host.loaderHook.lifecycle.loadEntryError.emit({
getRemoteEntry,
origin: this.host,
remoteInfo: this.remoteInfo,
remoteEntryExports: this.remoteEntryExports,
globalLoading,
uniqueKey,
}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Error recovery timeout')), RECOVERY_TIMEOUT)
)
]);

getRemoteEntry,
origin: this.host,
remoteInfo: this.remoteInfo,
remoteEntryExports: this.remoteEntryExports,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add logging for debugging and monitoring purposes before entering error recovery:

Suggested change
remoteEntryExports: this.remoteEntryExports,
} catch (err) {
console.warn(`Remote entry load failed for ${this.remoteInfo.name}, attempting recovery:`, err);

Copy link
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: 5

Configuration

Squadron Mode: essential

Commits Reviewed

a2f18c98d3a91e1cb319f51a11e3f16bb333e375...5607734548eaa04990479d4390c163bf403c1685

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

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

  • .changeset/small-eyes-change.md
  • apps/router-demo/router-host-2000/rsbuild.config.ts
  • apps/router-demo/router-host-2000/src/App.tsx
  • packages/retry-plugin/src/fetch-retry.ts
  • packages/retry-plugin/src/index.ts
  • packages/retry-plugin/src/types.d.ts
  • packages/retry-plugin/src/util.ts

Comment on lines +118 to +121
loadEntryError: new AsyncHook<
[
{
getRemoteEntry: typeof getRemoteEntry;
Copy link
Contributor

Choose a reason for hiding this comment

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

The loadEntryError hook appears to be incomplete and missing critical error handling properties. Enhance it with a more comprehensive error interface:

Suggested change
loadEntryError: new AsyncHook<
[
{
getRemoteEntry: typeof getRemoteEntry;
loadEntryError: new AsyncHook<
[{
error: Error;
origin: string;
retryCount: number;
retryLimit?: number;
retryDelay?: number;
}],

This provides better type safety and documentation for retry-related error handling parameters.

remoteInfo: this.remoteInfo,
remoteEntryExports: this.remoteEntryExports,
});
let remoteEntryExports;
Copy link
Contributor

Choose a reason for hiding this comment

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

The remoteEntryExports variable declaration could be more strictly typed to match its expected type. Add explicit typing:

Suggested change
let remoteEntryExports;
let remoteEntryExports: RemoteEntryExports | undefined;

packages/runtime/src/module/index.ts Show resolved Hide resolved
packages/runtime/src/module/index.ts Show resolved Hide resolved
packages/runtime/src/module/index.ts Show resolved Hide resolved
@zhoushaw zhoushaw merged commit fa7a0bd into main Dec 10, 2024
16 checks passed
@zhoushaw zhoushaw deleted the fix/retry-remote-entry branch December 10, 2024 11:34
@KyrieLii KyrieLii mentioned this pull request Dec 11, 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.

3 participants