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(plugin-asset-retry): support async chunk retry #2086

Merged
merged 7 commits into from
Apr 25, 2024

Conversation

SoonIter
Copy link
Member

@SoonIter SoonIter commented Apr 15, 2024

Summary

  1. implement asyncChunkRetry rspack plugin based on compilation.hooks.runtimeModule feat: support compilation.hooks.runtimeModule rspack#5370
  2. design based on https://github.com/mattlewis92/webpack-retry-chunk-load-plugin

Design

We will rewrite __webpack_require__.ensureChunk and __webpack_require.loadScript to achieve this feature.

  1. __webpack_require__.ensureChunk is a way how webpack loads async chunks and it returns a promise. We intercepted the error of this Promise.
  2. __webpack_require__.loadScript is to calculate the request url and it defines the src of <script> and we intercepted the url calculation

Related Links

close #91

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Apr 15, 2024

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 7b488a4
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/6629586375849a000832371d
😎 Deploy Preview https://deploy-preview-2086--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 91 (🔴 down 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

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

@SoonIter SoonIter changed the title feat(plugin-asset-retry): init e2e and package plugin feat(plugin-asset-retry): runtimeChunkRetry and init e2e Apr 15, 2024
@SoonIter SoonIter force-pushed the feat/plugin-assets-retry branch 2 times, most recently from 052a17e to 9bc1df7 Compare April 18, 2024 06:52
@SoonIter SoonIter force-pushed the feat/plugin-assets-retry branch 4 times, most recently from 6be522b to c9221b5 Compare April 19, 2024 08:27
@SoonIter SoonIter marked this pull request as ready for review April 19, 2024 08:36
@SoonIter SoonIter force-pushed the feat/plugin-assets-retry branch 2 times, most recently from 066c791 to 4788b75 Compare April 23, 2024 10:06
@SoonIter SoonIter changed the title feat(plugin-asset-retry): runtimeChunkRetry and init e2e feat(plugin-asset-retry): support async chunk retry Apr 23, 2024

// If the requested failed chunk is async chunk,skip it, because async chunk will be retried by asyncChunkRetry runtime
if (
window &&
Copy link
Member

Choose a reason for hiding this comment

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

When will the window be undefined here

Copy link
Member Author

Choose a reason for hiding this comment

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

when target is web-worker? I don't know.

Copy link
Member

Choose a reason for hiding this comment

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

When target is web-worker, the assets runtime will not be injected, see:

image

Copy link
Member

Choose a reason for hiding this comment

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

Also window && xxx is not a valid way to judge, usually we use typeof window !== 'undefined' && xx

@chenjiahan chenjiahan merged commit 2a8f821 into main Apr 25, 2024
10 checks passed
@chenjiahan chenjiahan deleted the feat/plugin-assets-retry branch April 25, 2024 06:03
@nanianlisao
Copy link
Contributor

@SoonIter
I just tried out this feature, and it's really great. However, I noticed an issue where onFail gets executed multiple times, which is not what was expected.

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.

[Feature]: Assets retry supports dynamic chunks
3 participants