Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic with nested islands #2440

Open
boyswan opened this issue Mar 18, 2024 · 4 comments
Open

Panic with nested islands #2440

boyswan opened this issue Mar 18, 2024 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@boyswan
Copy link
Contributor

boyswan commented Mar 18, 2024

Currently, rendering an island directly in another panics (ex: OuterFailing). The only way around this is to render via children (ex: OuterWorking).

This can be problematic as it uses up the child prop, and the slot solution to this is incompatible with islands. As a workaround I have various "island wrappers" which wrap a component in an empty island component, but it can get quite messy.

Perhaps what I'm attempting is an anti-pattern and nesting islands should be best avoided?

use leptos::*;

#[island]
pub fn CommonIsland() -> impl IntoView {
    let val = RwSignal::new(0);
    view! {
        <div>
            {move || format!("CommonIsland value is {}", val.get())}
            <button on:click=move|_| val.update(|x| {*x += 1})>Click</button>
        </div>

    }
}

#[island]
pub fn OuterWorking(children: Children) -> impl IntoView {
    let val = RwSignal::new(0);
    view! {
        <>
            <div>
                {move || format!("outer value is {}", val.get())}
                <button on:click=move|_| val.update(|x| {*x += 1})>Click</button>
            </div>
            {children()}
        </>

    }
}

#[island]
pub fn OuterFailing() -> impl IntoView {
    let val = RwSignal::new(0);
    view! {
        <>
            <div>
                {move || format!("outer value is {}", val.get())}
                <button on:click=move|_| val.update(|x| {*x += 1})>Click</button>
            </div>
            <CommonIsland/>
        </>

    }
}
#[component]
pub fn Example() -> impl IntoView {
    view! {
        <OuterFailing/>

        <OuterWorking>
            <CommonIsland/>
        </OuterWorking>

        <CommonIsland/>
    }
}
@gbj gbj added the bug Something isn't working label Mar 18, 2024
@gbj
Copy link
Collaborator

gbj commented Mar 18, 2024

Perfectly reasonable bug report. It's not likely I'll have the time to investigate it further in the near future (say, before mid-April) but would appreciate any help you can give in understanding the cause.

@gbj
Copy link
Collaborator

gbj commented Mar 18, 2024

(Oh I should add: It is likely this will be fixed in 0.7, which is where I'm spending most of my energy, as the hydration works completely differently. I will tag this with 0.7 to make sure it is closed in that version if not before.)

@gbj gbj added this to the 0.7 milestone Mar 18, 2024
@boyswan
Copy link
Contributor Author

boyswan commented Mar 18, 2024

Great! In the meantime I'll do a little digging and see if I can find anything. Will update on here if so.

@boyswan
Copy link
Contributor Author

boyswan commented Mar 18, 2024

So I have found the offending unwrap:

Handling this removes the panic and the island works as expected, however hydration warnings remain. My knowledge of the inner works of Leptos are limited to the last hour, so I can only offer so much until I learn more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants