natemoo-re / astro-icon

Inline and sprite-based SVGs in Astro made easy!
https://astroicon.dev
Other
990 stars 57 forks source link

Rendering Issue with Adjusted viewBox SVGs in astro-icon v1.1.0 #212

Open tetracalibers opened 3 months ago

tetracalibers commented 3 months ago

What version of astro-icon are you using?

v1.1.0

Astro Info

Astro                    v4.4.14
Node                     v20.4.0
System                   macOS (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             astro-icon

If this issue only occurs in one browser, which browser is a problem?

Chrome, Safari, Firefox

Describe the Bug

SVG icons adjusted with tools like SVG Crop are partially missing when rendered using astro-icon v1.1.0.

スクリーンショット 2024-03-08 8 57 40

The following situations do not cause problems:

What's the expected result?

Removing the viewBox from svg elements and assigning it to the symbol element resolves the issue:

<!-- Removed viewBox from svg element -->
<svg width="100" height="100" data-icon="astro-cropped">
  <!-- Instead, a viewBox is specified for the symbol element -->
  <symbol id="ai:local:astro-cropped" viewBox="4.93 2 22.15 28">
    <!-- ... -->
  </symbol>
  <use xlink:href="#ai:local:astro-cropped"></use>
</svg>

<!-- Removed viewBox from svg element -->
<svg width="100" height="100" data-icon="astro-cropped">
  <use xlink:href="#ai:local:astro-cropped"></use>
</svg>

Link to Minimal Reproducible Example

https://github.com/tetracalibers/astro-icon-symbol-viewbox-test