example stream-markdown dont work isolation on new catalog

Author: AveNRUCreated Sep 25, 2026Updated Sep 28, 2026
Labelsquickjs

main.rs

rust
use gpui_kit::assets::Assets;
use gpui_kit::component::{
    button::Button,
    h_flex,
    switch::Switch,
    text::{TextView, TextViewState},
    v_flex,
};
use gpui_kit::*;

pub struct Example {
    markdown_state: Entity<TextViewState>,
    tx: smol::channel::Sender<(usize, String)>,
    scroll_handle: ScrollHandle,
    replay_id: usize,
    stream_fade: bool,
    _task: Task<()>,
    _update_task: Task<()>,
}

const EXAMPLE: &str = include_str!("../../fixtures/test.md");

impl Example {
    pub fn new(_: &mut Window, cx: &mut Context<Self>) -> Self {
        let markdown_state =
            cx.new(|cx| TextViewState::markdown("# Streaming Markdown Parse\n\n", cx));
        let scroll_handle = ScrollHandle::new();

        let (tx, rx) = smol::channel::unbounded::<(usize, String)>();
        let _task = cx.spawn({
            async move |weak_self, cx| {
                while let Ok((replay_id, chunk)) = rx.recv().await {
                    _ = weak_self.update(cx, |this, cx| {
                        if replay_id != this.replay_id {
                            return;
                        }

                        // Push the new chunk to the markdown state,
                        // it will reparse and re-render automatically.
                        this.markdown_state.update(cx, |state, cx| {
                            state.push_str(&chunk, cx);
                        });
                        this.scroll_handle.scroll_to_bottom();
                    });
                }
            }
        });

        Self {
            markdown_state,
            scroll_handle,
            tx,
            replay_id: 0,
            stream_fade: true,
            _task,
            _update_task: Task::ready(()),
        }
    }

    fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
        cx.new(|cx| Self::new(window, cx))
    }

    /// Simulate streaming by updating markdown state in chunks
    /// 50ms for a iteration, every time adding about 5 - 20 characters
    /// This is just for demonstration; in a real app, you'd stream from a source.
    fn replay(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
        self.replay_id = self.replay_id.wrapping_add(1);
        let replay_id = self.replay_id;
        let tx = self.tx.clone();
        let mut current = 0;
        self.markdown_state.update(cx, |state, cx| {
            state.set_text("", cx);
        });

        self._update_task = cx.background_executor().spawn(async move {
            let chars: Vec<char> = EXAMPLE.chars().collect();
            while current < chars.len() {
                let chunk_size = (5 + rand::random::<usize>() % 15).min(chars.len() - current);
                let chunk: String = chars[current..current + chunk_size].iter().collect();
                _ = tx.try_send((replay_id, chunk));
                current += chunk_size;
                std::thread::sleep(std::time::Duration::from_millis(50));
            }
        });
    }
}

impl Render for Example {
    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
        v_flex()
            .id("example")
            .size_full()
            .p_4()
            .gap_4()
            .child(
                h_flex()
                    .w_full()
                    .gap_4()
                    .child(
                        Button::new("replay")
                            .outline()
                            .label("Replay")
                            .on_click(cx.listener(move |this, _, window, cx| {
                                this.replay(window, cx);
                            })),
                    )
                    .child(
                        Switch::new("stream-fade")
                            .checked(self.stream_fade)
                            .label("Fade in streamed text")
                            .on_click(cx.listener(|this, checked: &bool, _, cx| {
                                this.stream_fade = *checked;
                                cx.notify();
                            })),
                    ),
            )
            .child(
                div()
                    .id("contents")
                    .flex_1()
                    .w_full()
                    .track_scroll(&self.scroll_handle)
                    .overflow_y_scroll()
                    .size_full()
                    .child(
                        TextView::new(&self.markdown_state)
                            .selectable(true)
                            .stream_fade(self.stream_fade),
                    ),
            )
    }
}

fn main() {
    let app = gpui_kit::application().with_assets(Assets);

    app.run(move |cx| {
        gpui_component_story::init(cx);
        cx.activate(true);

        gpui_component_story::create_new_window_with_size(
            "Stream Markdown",
            Some(size(px(600.), px(800.))),
            Example::view,
            cx,
        );
    });
}

cargo.toml

toml
[package]
name = "example-stream-markdown3"
version = "0.1.0"
publish = false

[dependencies]
gpui-kit.workspace = true
gpui-component-story = { path = "E:/Rust/gpui-kit/crates/story" }
anyhow.workspace = true
gpui.workspace = true
gpui_platform.workspace = true
gpui_web.workspace = true
gpui_macros.workspace = true
reqwest_client.workspace = true
sum-tree.workspace = true
reqwest.workspace = true
rand = "0.8"
smol = "2"
#объявление раздела gpui
[workspace.dependencies]
gpui-kit = { path = "E:/Rust/gpui-kit/crates/kit", version = "0.6.4" }
gpui-component = { path = "E:/Rust/gpui-kit/crates/component", version = "0.6.4" }
gpui-base = { path = "E:/Rust/gpui-kit/crates/base", version = "0.6.4" }
gpui-component-macros = { path = "E:/Rust/gpui-kit/crates/component-macros", version = "0.6.4" }
gpui-kit-assets = { path = "E:/Rust/gpui-kit/crates/assets", version = "0.6.4" }
gpui-fps = { path = "E:/Rust/gpui-kit/crates/fps", version = "0.6.4" }
gpui-shell = { path = "E:/Rust/gpui-kit/crates/shell", version = "0.6.4" }
gpui-wry = { path = "E:/Rust/gpui-kit/crates/webview", version = "0.6.4" }
gpui-component-shell = { path = "E:/Rust/gpui-kit/crates/component-shell", version = "0.6.4" }
story = { path = "E:/Rust/gpui-kit/crates/story" }
anyhow = "*"
#
gpui = { package = "gpui-pre", version = "0.3.6" }
gpui_platform = { package = "gpui-pre-platform", version = "0.3.6", features = ["font-kit", "x11", "wayland", "runtime_shaders"] }
gpui_web = { package = "gpui-pre-web", version = "0.3.6" }
gpui_macros = { package = "gpui-pre-macros", version = "0.3.6" }
reqwest_client = { package = "gpui-pre-reqwest-client", version = "0.3.6" }
sum-tree = { package = "gpui-pre-sum-tree", version = "0.3.6" }
reqwest = { package = "gpui-pre-reqwest", version = "0.12.15", default-features = false, features = [
    "charset",
    "http2",
    "macos-system-configuration",
    "multipart",
    "rustls-tls-native-roots",
    "socks",
    "stream",
] }

dir

PS E:\rust> dir

    Каталог: E:\rust


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        21.09.2026     16:25                gpui-kit
d-----        21.09.2026     15:30                gpui_example
d-----        21.09.2026     16:24                gpui_example2

Errors

error[E0277]: the trait bound `BufferModule: ModuleDef` is not satisfied
   --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:53:32
    |
 53 |         .with_module("buffer", quickjs_jit_stdlib::buffer::BufferModule)
    |          -----------           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ModuleDef` is not implemented for `BufferModule`
    |          |
    |          required by a bound introduced by this call
    |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ^^^^^^^^^^^^^^^^^^^ this is the expected trait
    |
   ::: C:\Users\AveN\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rquickjs-core-0.12.2\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ------------------- this is the found trait
    = help: you can use `cargo tree` to explore your dependency tree
    = help: the following other types implement trait `ModuleDef`:
              ConsoleModule
              FsModule
              GpuiAliasModule
              GpuiBaseModule
              GpuiFpsModule
              GpuiModule
              GpuiShellModule
              NetModule
            and 3 others
note: required by a bound in `ModuleLoader::with_module`
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\loader\module_loader.rs:34:44
    |
 34 |     pub fn with_module<N: Into<String>, M: ModuleDef>(mut self, name: N, module: M) -> Self {
    |                                            ^^^^^^^^^ required by this bound in `ModuleLoader::with_module`

error[E0277]: the trait bound `CryptoModule: ModuleDef` is not satisfied
   --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:55:32
    |
 55 |         .with_module("crypto", quickjs_jit_stdlib::crypto::CryptoModule)
    |          -----------           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ModuleDef` is not implemented for `CryptoModule`
    |          |
    |          required by a bound introduced by this call
    |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ^^^^^^^^^^^^^^^^^^^ this is the expected trait
    |
   ::: C:\Users\AveN\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rquickjs-core-0.12.2\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ------------------- this is the found trait
    = help: you can use `cargo tree` to explore your dependency tree
    = help: the following other types implement trait `ModuleDef`:
              ConsoleModule
              FsModule
              GpuiAliasModule
              GpuiBaseModule
              GpuiFpsModule
              GpuiModule
              GpuiShellModule
              NetModule
            and 3 others
note: required by a bound in `ModuleLoader::with_module`
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\loader\module_loader.rs:34:44
    |
 34 |     pub fn with_module<N: Into<String>, M: ModuleDef>(mut self, name: N, module: M) -> Self {
    |                                            ^^^^^^^^^ required by this bound in `ModuleLoader::with_module`

error[E0277]: the trait bound `PathModule: ModuleDef` is not satisfied
   --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:59:30
    |
 59 |         .with_module("path", quickjs_jit_stdlib::path::PathModule)
    |          -----------         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ModuleDef` is not implemented for `PathModule`
    |          |
    |          required by a bound introduced by this call
    |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ^^^^^^^^^^^^^^^^^^^ this is the expected trait
    |
   ::: C:\Users\AveN\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rquickjs-core-0.12.2\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ------------------- this is the found trait
    = help: you can use `cargo tree` to explore your dependency tree
    = help: the following other types implement trait `ModuleDef`:
              ConsoleModule
              FsModule
              GpuiAliasModule
              GpuiBaseModule
              GpuiFpsModule
              GpuiModule
              GpuiShellModule
              NetModule
            and 3 others
note: required by a bound in `ModuleLoader::with_module`
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\loader\module_loader.rs:34:44
    |
 34 |     pub fn with_module<N: Into<String>, M: ModuleDef>(mut self, name: N, module: M) -> Self {
    |                                            ^^^^^^^^^ required by this bound in `ModuleLoader::with_module`

error[E0277]: the trait bound `UrlModule: ModuleDef` is not satisfied
   --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:61:29
    |
 61 |         .with_module("url", quickjs_jit_stdlib::url::UrlModule)
    |          -----------        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ModuleDef` is not implemented for `UrlModule`
    |          |
    |          required by a bound introduced by this call
    |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ^^^^^^^^^^^^^^^^^^^ this is the expected trait
    |
   ::: C:\Users\AveN\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rquickjs-core-0.12.2\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ------------------- this is the found trait
    = help: you can use `cargo tree` to explore your dependency tree
    = help: the following other types implement trait `ModuleDef`:
              ConsoleModule
              FsModule
              GpuiAliasModule
              GpuiBaseModule
              GpuiFpsModule
              GpuiModule
              GpuiShellModule
              NetModule
            and 3 others
note: required by a bound in `ModuleLoader::with_module`
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\loader\module_loader.rs:34:44
    |
 34 |     pub fn with_module<N: Into<String>, M: ModuleDef>(mut self, name: N, module: M) -> Self {
    |                                            ^^^^^^^^^ required by this bound in `ModuleLoader::with_module`

error[E0277]: the trait bound `ZlibModule: ModuleDef` is not satisfied
   --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:63:30
    |
 63 |         .with_module("zlib", quickjs_jit_stdlib::zlib::ZlibModule)
    |          -----------         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ModuleDef` is not implemented for `ZlibModule`
    |          |
    |          required by a bound introduced by this call
    |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ^^^^^^^^^^^^^^^^^^^ this is the expected trait
    |
   ::: C:\Users\AveN\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rquickjs-core-0.12.2\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ------------------- this is the found trait
    = help: you can use `cargo tree` to explore your dependency tree
    = help: the following other types implement trait `ModuleDef`:
              ConsoleModule
              FsModule
              GpuiAliasModule
              GpuiBaseModule
              GpuiFpsModule
              GpuiModule
              GpuiShellModule
              NetModule
            and 3 others
note: required by a bound in `ModuleLoader::with_module`
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\loader\module_loader.rs:34:44
    |
 34 |     pub fn with_module<N: Into<String>, M: ModuleDef>(mut self, name: N, module: M) -> Self {
    |                                            ^^^^^^^^^ required by this bound in `ModuleLoader::with_module`

error[E0308]: mismatched types
  --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:69:30
   |
69 |     quickjs_jit_stdlib::init(ctx)?;
   |     ------------------------ ^^^ expected `rquickjs_core::context::ctx::Ctx<'_>`, found `Ctx<'_>`
   |     |
   |     arguments to this function are incorrect
   |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
  --> C:\Users\AveN\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rquickjs-core-0.12.2\src\context\ctx.rs:82:1
   |
82 | pub struct Ctx<'js> {
   | ^^^^^^^^^^^^^^^^^^^ this is the expected type
   |
  ::: C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\context\ctx.rs:82:1
   |
82 | pub struct Ctx<'js> {
   | ------------------- this is the found type
   = help: you can use `cargo tree` to explore your dependency tree
note: function defined here
  --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\605da48\stdlib\src\lib.rs:40:8
   |
40 | pub fn init(ctx: &Ctx<'_>) -> Result<()> {
   |        ^^^^

error[E0277]: `?` couldn't convert the error to `rquickjs::Error`
  --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:69:34
   |
66 | pub(super) fn install(ctx: &Ctx<'_>) -> Result<()> {
   |                                         ---------- expected `rquickjs::Error` because of this
...
69 |     quickjs_jit_stdlib::init(ctx)?;
   |     -----------------------------^ the trait `std::convert::From<rquickjs_core::result::Error>` is not implemented for `rquickjs::Error`
   |     |
   |     this can't be annotated with `?` because it has type `Result<_, rquickjs_core::result::Error>`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: `rquickjs::Error` implements trait `std::convert::From<T>`:
             std::convert::From<FromBytesWithNulError>
             std::convert::From<FromUtf8Error>
             std::convert::From<NulError>
             std::convert::From<UserDataError<T>>
             std::convert::From<Utf8Error>
             std::convert::From<rquickjs_core::value::array_buffer::AsSliceError>
             std::convert::From<std::io::Error>
   = note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   = help: you can use `cargo tree` to explore your dependency tree

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `gpui-shell` (lib) due to 7 previous errors
PS E:\Rust\gpui_example2> cargo check
warning: Cargo.toml: `package.edition` is unspecified, defaulting to `2015` while the latest is `2024`
warning: `example-stream-markdown3` (manifest) generated 1 warning
    Checking gpui-shell v0.6.4 (E:\Rust\gpui-kit\crates\shell)
error[E0277]: the trait bound `BufferModule: ModuleDef` is not satisfied
   --> E:\Rust\gpui-kit\crates\shell\src\engine\quickjs\standard\mod.rs:53:32
    |
 53 |         .with_module("buffer", quickjs_jit_stdlib::buffer::BufferModule)
    |          -----------           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ModuleDef` is not implemented for `BufferModule`
    |          |
    |          required by a bound introduced by this call
    |
note: there are multiple different versions of crate `rquickjs_core` in the dependency graph
   --> C:\Users\AveN\.cargo\git\checkouts\quickjs-jit-85f77f3fd15b7d92\82d3808\core\src\value\module.rs:113:1
    |
113 | pub trait ModuleDef {
    | ^^^^^^^^^^^^

Source: longbridge/gpui-component