Skip to content

Attribute assignment with attr: is lost when component initially renders as () then as any element #4470

@RougeEtoile

Description

@RougeEtoile

Describe the bug
attr:* are not applied to Top Level elements rendered by components when component switches from rendering () then to any element. This can occur with <Show> if/else or match statements. This occurs in dev builds but not release builds. #[component(transparent)] also fixes the issue. I have only tested this in SSR mode with cargo-leptos.

Leptos Dependencies

leptos = { version = "0.8.12" }
wasm-bindgen = "=0.2.105"
leptos_router = { version = "0.8.9" }
leptos_meta = { version = "0.8.5" }
console_error_panic_hook = "0.1.7"
console_log = "1.0.0"
axum = "0.8.7"
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros"] }
leptos_axum = "0.8.6"

To Reproduce

use leptos::prelude::*;
use leptos::either::Either;

#[component]
pub fn TheBug() -> impl IntoView {
    let (show, set_show) = signal(false);
    
    Effect::new(move |_| {
        set_timeout(move || set_show.set(true), std::time::Duration::from_millis(100));
    });

    move || {
        if show.get() {
            Either::Left(view! { <div class="bugged">"I should be red"</div> })
        } else {
            Either::Right(())
        }
    }
}

#[component]
pub fn App() -> impl IntoView {
    view! {
        // Style is missing on the child div
        <TheBug attr:style="background-color: red;" />
    }
}

Next Steps

  • I will make a PR
  • [ x] I would like to make a PR, but need help getting started
  • I want someone else to take the time to fix this
  • This is a low priority for me and is just shared for your information

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions