leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.91k stars 625 forks source link

SVG elements don't show under certain conditions. #3021

Open zakstucke opened 2 hours ago

zakstucke commented 2 hours ago

Describe the bug This seems to be similar to #2998 but might be unrelated. Svg elements seem to be invisible under certain reactive conditions. The svg still exists in the browser dom, but the elements have 0px dims.

This repro shows static svg elements now work, but reactive ones can still be invisible as shown here.

Leptos Dependencies Current main.

To Reproduce

#[component]
fn Foo() -> impl IntoView {
    let toggle = RwSignal::new(false);
    Effect::new(move |_| {
        if !toggle.get() {
            toggle.set(true);
        }
    });
    view! {
        {move || {
            if toggle.get() {
                Either::Left(
                    view! {
                        <p>A_START</p>
                        <MyIcon />
                        <p>A_END</p>
                    },
                )
            } else {
                Either::Right(view! { <p>A_INITIAL</p> })
            }
        }}
        <p>B_START</p>
        <MyIcon />
        <p>B_END</p>
    }
}

#[component]
fn MyIcon() -> impl IntoView {
    view! {
        <svg
            xmlns="http://www.w3.org/2000/svg"
            class="w-full h-full"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            width="3em"
            height="3em"
        >
            <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path>
            <path d="M15 2H9a1 1 0 0 0-1 1v2a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1z"></path>
            <path d="M9 12h6"></path>
            <path d="M9 16h6"></path>
            <path d="M9 8h1"></path>
        </svg>
    }
}

https://github.com/user-attachments/assets/0f3d3c11-225f-4b43-87a8-15a2b09f73e8

zakstucke commented 2 hours ago

I just checked this also happens with <Show when={move || toggle.get()}>