Skip to content

feat: replace dynamic require() with static SVG import map for Vite/Astro support#226

Merged
sergical merged 3 commits intogetsentry:masterfrom
sergical:feat/static-svg-imports
Feb 25, 2026
Merged

feat: replace dynamic require() with static SVG import map for Vite/Astro support#226
sergical merged 3 commits intogetsentry:masterfrom
sergical:feat/static-svg-imports

Conversation

@sergical
Copy link
Member

Summary

  • Adds a code generator (scripts/generate-icons.js) that produces src/icons.generated.ts with static imports for all 218 SVG icons in both sizes (436 total imports)
  • Replaces dynamic require() with template literals in platformIcon.tsx and preload.tsx with static import map lookups
  • CJS build produces static require() calls (webpack/Gatsby compatible), ESM build produces static import statements (Vite/Astro compatible)
  • No change to the public API

Why

Dynamic require() with template literals (e.g. require(`../svg/${icon}.svg`)) works in webpack but breaks in Vite/esbuild (Astro) — the bundler can't resolve non-JS dynamic requires at build time, causing 436 errors.

Test plan

  • yarn build succeeds with zero errors
  • build/icons.generated.js contains static require("../svg/foo.svg") calls
  • esmbuild/icons.generated.js contains static import statements
  • Existing webpack/Gatsby consumers unaffected (static require() is strictly more analyzable)
  • Astro/Vite consumers can now resolve the ESM imports

🤖 Generated with Claude Code

Dynamic `require()` with template literals doesn't work in Vite/esbuild
(Astro). This adds a code generator that produces static imports for all
218 SVG icons in both sizes, so TypeScript compiles them to:
- CJS: static require() calls (webpack/Gatsby compatible)
- ESM: static import statements (Vite/Astro compatible)

No change to the public API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- LG format now falls back to iconsLg["default"] instead of icons["default"]
- preloadIcons filters out undefined entries from the icon map

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Prefix identifiers starting with a digit (e.g. "3d" → "_3d")
- Fail generation if svg_80x80/ is missing icons present in svg/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@sergical sergical merged commit dcbbcea into getsentry:master Feb 25, 2026
9 checks passed
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