Skip to content

feat: support multiple retry rules #21

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

Conversation

LuciferChiu
Copy link
Contributor

This pull request introduces support for multiple retry rules in the Assets Retry plugin, enabling more granular control over retry strategies for different asset types or domains. Key changes include updates to the plugin's configuration structure, runtime logic, and documentation in both English and Chinese.

Configuration Updates:

  • Enhanced AssetsRetryOptions Type: Added support for specifying multiple retry rules via the rules property, along with options for inlineScript and minify. This allows users to define retry strategies tailored to specific assets or domains. (README.md: [1] README.zh-CN.md: [2]
  • Updated Plugin Configuration: Modified PluginAssetsRetryOptions type to accommodate single or multiple retry rules. Introduced logic in pluginAssetsRetry to handle both modes. (src/types.ts: [1] src/index.ts: [2] [3]

Runtime Logic Enhancements:

  • Matching Configurations: Implemented findMatchingConfig function to identify the appropriate retry rule based on asset URLs. This function is used across runtime modules for dynamic rule evaluation. (src/runtime/asyncChunkRetry.ts: [1] [2] [3]; src/runtime/initialChunkRetry.ts: [4] [5] [6]
  • Retry Initialization and Execution: Updated initRetry, nextRetry, and ensureChunk functions to incorporate rule-based retry logic, ensuring compatibility with both single and multiple configurations. (src/runtime/asyncChunkRetry.ts: [1] [2] [3]

Documentation Updates:

  • English Documentation: Added detailed descriptions and examples for the rules property, illustrating use cases for different asset types and CDNs. (README.md: README.mdR332-R401)
  • Chinese Documentation: Provided equivalent updates in Chinese, ensuring localization for the new features. (README.zh-CN.md: README.zh-CN.mdR330-R399)

Code Refactoring:

  • Runtime Code Adjustments: Refactored runtime modules to support dynamic rule evaluation and added fallback mechanisms for unmatched configurations. (src/runtime/asyncChunkRetry.ts: [1] [2]; src/runtime/initialChunkRetry.ts: [3]

These changes collectively enhance the flexibility and robustness of the Assets Retry plugin, making it easier to handle diverse retry requirements in complex asset loading scenarios.

@LuciferChiu LuciferChiu marked this pull request as ready for review June 25, 2025 12:43
@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 12:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for multiple retry rules in the Assets Retry plugin, allowing more granular and customizable retry strategies for different asset types or domains. The key changes are:

  • Enhancements to configuration types and normalization functions to support an array of retry rules.
  • Updates to runtime logic (in both initial and async chunk retry modules) to select the matching rule dynamically.
  • Documentation updates in both English and Chinese, as well as additional tests validating the new functionality.

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/basic/multiRules.test.ts New tests added covering various scenarios for multiple retry rules.
src/types.ts Updated PluginAssetsRetryOptions type to support multiple rules.
src/runtime/initialChunkRetry.ts Added findMatchingConfig function and updated retry flow for arrays.
src/runtime/asyncChunkRetry.ts Similar updates for runtime logic to handle rule arrays and dynamic matching.
src/index.ts Updated normalization and option handling to support rules mode.
src/AsyncChunkRetryPlugin.ts Updated runtimeOptions type to accept both single and multiple configurations.
README.md & README.zh-CN.md Expanded documentation to explain the multiple rules feature.
Comments suppressed due to low confidence (1)

src/runtime/initialChunkRetry.ts:288

  • The catch block rethrows 'error', which is undefined in this scope. Replace it with 'throw e' to rethrow the caught exception.
}

// Find matching config
const config = findMatchingConfig(originalSrcUrl, configs);
if (!config) {
throw error;
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

The code throws 'error' when no matching config is found but 'error' is not defined; consider throwing a new Error with an appropriate message or rethrowing a caught exception.

Suggested change
throw error;
throw new Error('No matching config found for the original source URL');

Copilot uses AI. Check for mistakes.

@LuciferChiu
Copy link
Contributor Author

@SoonIter 我又基于main搞了一版,刚看到你也提了哈哈哈,你参考下两边的实现看看吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant