feat: add data-rsbuild-assets-retry attribute to retry scripts#25
feat: add data-rsbuild-assets-retry attribute to retry scripts#25chenjiahan merged 3 commits intorstackjs:mainfrom
Conversation
d473485 to
a2adf60
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds a data attribute to retry scripts so they can be easily filtered in custom HTML templates.
- Introduces a new
ASSETS_RETRY_DATA_ATTRIBUTEconstant - Updates inline and external script tags to include
data-rsbuild-assets-retry - Adds tests and documentation showing how to filter by the new attribute
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/basic/dataAttribute.test.ts | Adds Playwright tests verifying the presence and values of the data attribute on retry scripts |
| src/index.ts | Defines ASSETS_RETRY_DATA_ATTRIBUTE and applies it to script tags |
| README.zh-CN.md | Documents the new data attribute usage in the Chinese README |
| README.md | Documents the new data attribute usage in the English README |
Comments suppressed due to low confidence (5)
src/index.ts:24
- [nitpick] This comment is in Chinese while the rest of the code and README are in English; consider translating it to English to maintain consistency.
// 唯一标识符,用于在 HTML 模板中筛选重试脚本
README.md:494
- [nitpick] If you intend to output the filtered tags in a template, you probably need
<%=instead of<%to actually render the result.
<% htmlWebpackPlugin.tags.headTags.filter(tag => tag.attributes['data-rsbuild-assets-retry'] === 'inline') %>
README.zh-CN.md:492
- [nitpick] In this Chinese README example, use
<%=rather than<%to ensure the filtered array is actually injected into the render output.
<% htmlWebpackPlugin.tags.headTags.filter(tag => tag.attributes['data-rsbuild-assets-retry'] === 'inline') %>
test/basic/dataAttribute.test.ts:7
- import.meta.dirname is not a standard property and may be undefined at runtime; consider using path.dirname(fileURLToPath(import.meta.url)) for a reliable directory path.
cwd: import.meta.dirname,
src/index.ts:141
- [nitpick] The indentation of this attribute key does not match the surrounding object keys; aligning it with
src: urlwill improve readability.
[ASSETS_RETRY_DATA_ATTRIBUTE]: 'external',
|
@SoonIter Please help with the code review. |
chenjiahan
left a comment
There was a problem hiding this comment.
Can you explain why we need to implement this? I think for most scenarios, the plugin need to ensure that the retry script is the first script, and it should not be left to the user to handle this.
|
real production example : // asstes retry
<%= htmlWebpackPlugin.tags.headTags.filter(tag => tag.attributes['data-rsbuild-assets-retry']) %>
// some runtime scripts(like unpkg)
<script async src="react.js"></script>
<script src="logger.js"></script>
<script type="module" src="xxx"></script>
// other scripts that depend on the above runtime scripts.
<%= htmlWebpackPlugin.tags.headTags.filter(tag => !tag.attributes['data-rsbuild-assets-retry']) %>If I want react script can retry, What should I do ? |
|
Get👌 this makes sense |
✨ Features
Add Data Attribute to Retry Scripts for HTML Template Filtering
This release adds a unique
data-rsbuild-assets-retryattribute to retry scripts, enabling developers to easily identify and position them in custom HTML templates.Key Changes:
ASSETS_RETRY_DATA_ATTRIBUTEconstant for type-safe attribute accessdata-rsbuild-assets-retry="inline"for inline scriptsdata-rsbuild-assets-retry="external"for external scriptsUsage Example:
Benefits:
Testing:
This enhancement addresses the common need for precise control over retry script placement in custom HTML templates while maintaining backward compatibility.