SIGN IN SIGN UP

gpui: Add binary data support to `Svg` element (#52319)

## Context

Add support for binary SVG data in the `Svg` component in the `gpui`
crate. The component now accepts raw SVG bytes via a new `.data()`
method, in addition to the existing `.path()` and `.external_path()`
methods.

**Example usage:**
```rust
svg().data(svg_bytes).color(colors::WHITE)
```

This solves the problem of unnecessary asset bundling and enables Rust's
dead code elimination to optimize binary size.

**Related issue:** Closes #52315

## How to Review

- Review `crates/gpui/src/elements/svg.rs` - the changes are localized
to this file
- Focus on: API design, caching strategy (hash-based virtual path),
priority ordering in paint()
- Verify the implementation properly integrates with existing
`SvgRenderer` and `Window::paint_svg`

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (none in this change)
- [x] The content is consistent with the UI/UX checklist (trivial UI
change)
- [x] Tests cover the new/changed behavior (manual testing may be needed
for SVG rendering)
- [x] Performance impact has been considered (hash calculation is
minimal; caching prevents redundant work)

## Technical Details

The implementation:
- Adds `data: Option<Arc<[u8]>>` and `data_path: Option<SharedString>`
fields to `Svg`
- Adds `pub fn data(mut self, data: &[u8]>) -> Self` builder method
- Generates deterministic virtual path from SHA256-like hash:
`__binary_svg__{hash}`
- `paint()` checks sources in priority order: binary data >
external_path > path
- Uses existing `Window::paint_svg(..., data: Some(&bytes))` path

This is a minimal, non-breaking change that leverages existing
infrastructure.

Release Notes:

- Added `.data()` method to `Svg` element to accept raw SVG bytes

Co-authored-by: Lukas Wirth <lukas@zed.dev>
Co-authored-by: Kirill Bulatov <kirill@zed.dev>
S
suxiaoshao committed
ff9f114cd39692450ef7646db1198f54417531b8
Parent: fc952d5
Committed by GitHub <noreply@github.com> on 8/12/2026, 6:55:51 PM