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

Hydration error with Suspense > Outlet > Suspense #1863

Closed
gbj opened this issue Oct 8, 2023 · 0 comments · Fixed by #1864
Closed

Hydration error with Suspense > Outlet > Suspense #1863

gbj opened this issue Oct 8, 2023 · 0 comments · Fixed by #1864
Labels
bug Something isn't working

Comments

@gbj
Copy link
Collaborator

gbj commented Oct 8, 2023

Describe the bug
Using a Suspense-based route guard to conditionally render an Outlet, with a child route that itself loads something via Suspense, causes a hydration issue.

Leptos Dependencies

leptos = { version = "0.5", features = ["nightly"] }
leptos_axum = { version = "0.5", optional = true }
leptos_meta = { version = "0.5", features = ["nightly"] }
leptos_router = { version = "0.5", features = ["nightly"] }

To Reproduce

use leptos::*;
use leptos_router::*;

#[server]
pub async fn get_user() -> Result<(), ServerFnError> {
    Ok(())
}

#[server]
pub async fn data() -> Result<(), ServerFnError> {
    Ok(())
}

#[component]
pub fn App() -> impl IntoView {
    view! {
        <Router>
            <div>
                <div>"NavBar"</div>
                <main>
                    <div>
                        <Routes>
                            <Route path="" view=LoginGuard>
                                <Route path="" view=Child/>
                            </Route>
                        </Routes>
                    </div>
                    <div>
                        <div>
                            <button on:click=move |_| leptos::logging::log!("Did I hydrate?")>"Click"</button>
                        </div>
                    </div>
                </main>
            </div>
        </Router>
    }
}

#[component]
fn LoginGuard() -> impl IntoView {
    let guard_data = Resource::once(get_user);
    view! {
        <Suspense>
            {move || guard_data.and_then(|_| view! { <Outlet/> })}
        </Suspense>
    }
}

#[component]
pub fn Child() -> impl IntoView {
    let nested_data = Resource::once(data);

    view! {
        <Suspense>
            <pre>{
                move || {
                    format!("{:?}", nested_data.get())
                }
            }</pre>
        </Suspense>
    }
}
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

Successfully merging a pull request may close this issue.

1 participant