# gpui: Add binary data support to \`Svg\` element \(\#52319\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/ff9f114cd39692450ef7646db1198f54417531b8)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: ff9f114cd39692450ef7646db1198f54417531b8

Requested commit: ff9f114cd39692450ef7646db1198f54417531b8

Commit: ff9f114cd39692450ef7646db1198f54417531b8

Tree: c19fc80b1cd8b31e3d8249dc25a9548eb7781b11

Author: suxiaoshao

Committer: GitHub

## Message

````
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>
````

## Parents

- [fc952d52dab0920732b01d031d7324e664e6734f](https://git.cafe/gitcafe/zed/commit/fc952d52dab0920732b01d031d7324e664e6734f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/ff9f114cd39692450ef7646db1198f54417531b8?format=markdown)
