Skip to content

fix(svgrloader): isolate SVG transforms from discovered SVGR configuration - #12926

Open
mvanhorn wants to merge 1 commit into
meta:mainfrom
mvanhorn:fix/8646-isolate-svgr-runtime-config
Open

mvanhorn wants to merge 1 commit into
meta:mainfrom
mvanhorn:fix/8646-isolate-svgr-runtime-config

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 7, 2026 •

Copy link
Copy Markdown

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

A scaffolded site prints that it is running, then the client bundle fails to compile. Inline SVGs are emitted with a TypeScript interface, and the bundler stops on SyntaxError: Unexpected reserved word 'interface'. The failure shows up when custom SVGR settings live in a directory above the site and turn on TypeScript output.

SVGR walks upward from each SVG and applies the first configuration file it finds, including one outside the site. createDefaultSVGRConfig left that search enabled, so a parent file with typescript: true was honored and the transform emitted TypeScript into the JavaScript client compile.

The default SVGR options now set runtimeConfig to false, which skips svgr.config.js in the site directory and in ancestor directories. Sites that still want file discovery pass svgrConfig with runtimeConfig true. The plugin docs record the new default and point configuration at the svgrConfig option. Loader tests cover a parent TypeScript config, that opt-in, a config inside the site, and a parent file that does not parse.

Test Plan

npx --no-install vitest run src/tests/svgrLoader.test.ts passed all 8 tests in @docusaurus/plugin-svgr.
The tests in packages/docusaurus-plugin-svgr/src/__tests__/svgrLoader.test.ts fail without the fix in the docusaurus createDefaultSVGRConfig change (checked by reverting the source changes).

Test links

Covered in the summary above.

Related issues/PRs

Closes #8646

AI was used for assistance.

Summary by CodeRabbit

  • Bug Fixes
    • SVGR no longer loads configuration files from the site or its parent directories by default, preventing unexpected changes to generated React output.
    • Existing configurations can still be honored by enabling runtime config.
  • Documentation
    • Updated the SVGR plugin documentation to describe the default behavior and configuration options.

…ation

The default SVGR options now set runtimeConfig to false, which skips
svgr.config.js in the site directory and in ancestor directories. Sites
that still want file discovery pass svgrConfig with runtimeConfig true.
The plugin docs record the new default and point configuration at the
svgrConfig option. Loader tests cover a parent TypeScript config, that
opt-in, a config inside the site, and a parent file that does not parse.

Fixes meta#8646
@netlify

netlify Bot commented Nov 7, 2026

Copy link
Copy Markdown

✅ [V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 92ee2fb
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6aef1a44f6cbe219d841e043
😎 Deploy Preview https://deploy-preview-12926--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The SVGR plugin now disables runtime configuration-file discovery by default. Tests cover parent and site config files, malformed parent configs, and explicit opt-in. The plugin documentation describes the default and directs users to svgrConfig.

Changes: SVGR runtime config

Layer / File(s) Summary
Default config and coverage
packages/docusaurus-plugin-svgr/src/svgrLoader.ts, packages/docusaurus-plugin-svgr/src/__tests__/svgrLoader.test.ts, website/docs/api/plugins/plugin-svgr.mdx
The default sets runtimeConfig to false. Tests cover parent and site configs, malformed parent config, and enabling runtimeConfig. The documentation describes the default and directs users to svgrConfig.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: pr: breaking change

Merge Risk: Minimal · up to 92ee2

The change disables automatic SVGR configuration discovery while retaining explicit opt-in. No merge-blocking issue is identified in the supplied evidence; merge after normal checks pass.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: preventing discovered SVGR configuration from affecting SVG transforms by default.
Linked Issues check Passed [#8646] The default SVGR configuration disables runtime file discovery, preventing the reported parent TypeScript configuration from breaking client compilation. Loader tests cover the parent configur…
Out of Scope Changes check Passed [#8646] The loader change addresses the reported failure. The tests verify the change and its opt-in. The documentation explains the new default and configuration option.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

[#8646] The default SVGR configuration disables runtime file discovery, preventing the reported parent TypeScript configuration from breaking client compilation. Loader tests cover the parent configuration, explicit opt-in, site-local configuration, and a malformed parent configuration. The issue suggests logging as a possible solution; the default prevents the unintended configuration from being used.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d89452f6-e684-436e-8529-16869e3e8cfb
Commits

Reviewing files that changed from the base of the PR and between c00f04e and 92ee2fb.

Files selected for processing: 3

  • packages/docusaurus-plugin-svgr/src/__tests__/svgrLoader.test.ts
  • packages/docusaurus-plugin-svgr/src/svgrLoader.ts
  • website/docs/api/plugins/plugin-svgr.mdx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scaffolded project not working when custom SVGR config placed in parent directory

1 participant