Skip to content

feat(plugin-svgr): support SVG text import attributes - #8047

Merged
chenjiahan merged 1 commit into
mainfrom
chenjiahan/feat-svgr-import-attributes-text
Jul 2, 2026
Merged

feat(plugin-svgr): support SVG text import attributes#8047
chenjiahan merged 1 commit into
mainfrom
chenjiahan/feat-svgr-import-attributes-text

Conversation

@chenjiahan

Copy link
Copy Markdown
Member

Summary

This PR adds with { type: 'text' } support for SVG imports when @rsbuild/plugin-svgr rebuilds the SVG rule. It preserves the built-in text-import branch before the raw-query branch, adds a SVG_TEXT chain id, and includes plugin-specific e2e coverage for importing an SVG as source text.

Copilot AI review requested due to automatic review settings July 2, 2026 07:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/plugin-svgr/src/index.ts
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c02dc9a-c911-4d28-9da4-fb58e8cfcc63

📥 Commits

Reviewing files that changed from the base of the PR and between e53c071 and d056225.

⛔ Files ignored due to path filters (1)
  • packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • e2e/cases/plugin-svgr/import-attributes-text/index.test.ts
  • e2e/cases/plugin-svgr/import-attributes-text/rsbuild.config.ts
  • e2e/cases/plugin-svgr/import-attributes-text/src/index.js
  • packages/core/src/configChain.ts
  • packages/plugin-svgr/src/index.ts

📝 Walkthrough

Walkthrough

Changes

This 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
Loading

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
A rabbit hopped through circles round,
Text where SVG shapes are found,
With `type: 'text'` it now can say,
"I'm just a string" — hip hip hooray!
Chain IDs grow, one entry more,
A tiny hop, but tested sure. 🐰📄

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding SVG text import-attribute support to plugin-svgr.
Description check ✅ Passed The description is directly aligned with the changeset and accurately describes the new SVG text-import support and e2e coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 oneOf chain 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 ?raw branch).
  • 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.

@chenjiahan
chenjiahan merged commit fe2803c into main Jul 2, 2026
8 checks passed
@chenjiahan
chenjiahan deleted the chenjiahan/feat-svgr-import-attributes-text branch July 2, 2026 07:54
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.

2 participants