Skip to content

Commit f9d57b5

Browse files
authored
component_preview: Fix example rendering no text or icons (#59241)
`cargo run -p component_preview --example component_preview` does not work. On current main it panics at startup: ``` thread 'main' panicked at crates/gpui/src/action.rs:296:13: Action with name `zed::Quit` already registered ``` With that panic fixed, the window opens but renders no text and no icons (see Showcase below).s ## Solution Root cause for the blank window: `component_preview` package resolves `gpui_platform` with just `"screen-capture"`. On macOS the missing `font-kit` feature makes `MacPlatform` fall back to `gpui::NoopTextSystem`, as mentiond also in README (or CONTRIBUTE) file. On Linux the missing `wayland`/`x11` features leave no windowing backend at all. list of changes: - Enable the same `gpui_platform` features as the `zed` binary. - Attach `Assets` and load the embedded fonts. - Initialize `env_logger` so platform warnings reach the terminal. - Fix three startup panics: move the example's `Quit` action to the `component_preview` namespace. ## Testing Tested on macOS/Linux, not tested on Windows. I use Parallel VMs. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) ## Showcase Before: <img width="1312" height="945" alt="cp_pr1_before" src="https://github.com/user-attachments/assets/4611596f-6775-4863-bd4a-5f4d8c642e35" /> After: <img width="1312" height="945" alt="cp_pr1_after" src="https://github.com/user-attachments/assets/8f8082e6-c8cd-48f5-946a-032ce8186d30" /> --- Release Notes: - N/A
1 parent f39cf25 commit f9d57b5

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/component_preview/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ uuid.workspace = true
4040
workspace.workspace = true
4141

4242
[dev-dependencies]
43-
gpui_platform = { workspace = true, features = ["screen-capture"] }
43+
assets.workspace = true
44+
editor.workspace = true
45+
env_logger.workspace = true
46+
gpui_platform = { workspace = true, features = ["screen-capture", "font-kit", "wayland", "x11"] }
4447

4548
[[example]]
4649
name = "component_preview"

crates/component_preview/examples/component_preview.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Component Preview Example
22
//!
33
//! Run with: `cargo run -p component_preview --example component_preview"`
4+
use assets::Assets;
45
use fs::RealFs;
56
use gpui::{AppContext as _, Bounds, KeyBinding, WindowBounds, WindowOptions, actions, size};
67

@@ -16,20 +17,28 @@ use workspace::{AppState, Workspace, WorkspaceStore};
1617

1718
use component_preview::{ComponentPreview, init};
1819

19-
actions!(zed, [Quit]);
20+
actions!(component_preview, [Quit]);
2021

2122
fn quit(_: &Quit, cx: &mut App) {
2223
cx.quit();
2324
}
2425

2526
fn main() {
26-
gpui_platform::application().run(|cx| {
27+
env_logger::builder()
28+
.filter_level(log::LevelFilter::Warn)
29+
.init();
30+
31+
gpui_platform::application().with_assets(Assets).run(|cx| {
2732
component::init();
2833

2934
cx.on_action(quit);
3035
cx.bind_keys([KeyBinding::new("cmd-q", Quit, None)]);
3136
let version = release_channel::AppVersion::load(env!("CARGO_PKG_VERSION"), None, None);
3237
release_channel::init(version, cx);
38+
cx.set_global(db::AppDatabase::new());
39+
Assets
40+
.load_fonts(cx)
41+
.expect("Failed to load embedded fonts");
3342

3443
let http_client =
3544
ReqwestClient::user_agent("component_preview").expect("Failed to create HTTP client");
@@ -68,6 +77,7 @@ fn main() {
6877
AppState::set_global(app_state.clone(), cx);
6978

7079
workspace::init(app_state.clone(), cx);
80+
editor::init(cx);
7181
init(app_state.clone(), cx);
7282

7383
let size = size(px(1200.), px(800.));

0 commit comments

Comments
 (0)