feat(plugin-svgr): support SVG text import attributes - #8047
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d05622519c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
📝 WalkthroughWalkthroughChangesThis PR adds support for importing SVG files as plain text using import attributes (`with { type: 'text' }`). A new `SVG_TEXT` chain identifier is added to `CHAIN_ID.ONE_OF` in the core config chain, and `pluginSvgr` is updated to configure a rule routing matching modules to the `asset/source` loader with `type: 'text'`. A new end-to-end test case is added under `plugin-svgr/import-attributes-text`, including an Rsbuild config registering `pluginSvgr`, a source script importing `circle.svg` as text and assigning it to `window.svgText`, and a test asserting the imported text matches the file's actual contents in both serve modes. Sequence Diagram(s)sequenceDiagram
participant Test as E2E Test
participant App as index.js
participant Bundler
participant pluginSvgr
Test->>App: run app (both serve modes)
App->>Bundler: import circle.svg with { type: 'text' }
Bundler->>pluginSvgr: resolve module via SVG_TEXT rule
pluginSvgr-->>Bundler: return asset/source (type text)
Bundler-->>App: svg text content
App->>App: window.svgText = content
Test->>App: read window.svgText
Test->>Test: assert equals circle.svg file contents
Related Issues: None found in provided context. Related PRs: None found in provided context. Suggested labels: enhancement, plugin-svgr, e2e-test Suggested reviewers: None specified. Poem 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates @rsbuild/plugin-svgr so that when it rebuilds/overrides Rsbuild’s built-in SVG rule, it also preserves support for importing an SVG as source text via import attributes (with { type: 'text' }). This aligns the plugin’s overridden SVG handling with Rsbuild’s built-in static asset behavior (which already supports with: { type: 'text' }).
Changes:
- Add a new SVG
oneOfchain id (SVG_TEXT) to represent the import-attributes text branch. - Re-introduce the
asset/source+with { type: 'text' }SVG branch into the plugin’s rebuilt SVG rule (placed before the?rawbranch). - Add a plugin-specific e2e case verifying SVG text import attributes work when
pluginSvgr()is enabled.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/plugin-svgr/src/index.ts | Preserves SVG import-attributes text handling when the plugin rebuilds the SVG rule. |
| packages/core/src/configChain.ts | Adds CHAIN_ID.ONE_OF.SVG_TEXT (svg-asset-text) for consistent rule identification. |
| packages/plugin-svgr/tests/snapshots/index.test.ts.snap | Updates snapshots to reflect the new with: { type: 'text' } SVG oneOf branch. |
| e2e/cases/plugin-svgr/import-attributes-text/src/index.js | Adds a minimal runtime hook (window.svgText) for validating imported SVG text. |
| e2e/cases/plugin-svgr/import-attributes-text/rsbuild.config.ts | Configures the new e2e case to use pluginSvgr(). |
| e2e/cases/plugin-svgr/import-attributes-text/index.test.ts | Adds e2e coverage asserting the imported SVG text equals the original SVG file contents. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This PR adds
with { type: 'text' }support for SVG imports when@rsbuild/plugin-svgrrebuilds the SVG rule. It preserves the built-in text-import branch before the raw-query branch, adds aSVG_TEXTchain id, and includes plugin-specific e2e coverage for importing an SVG as source text.