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 when multiple islands are nested inside a Transition #3419

Closed
spencewenski opened this issue Dec 28, 2024 · 2 comments
Closed

Comments

@spencewenski
Copy link
Contributor

spencewenski commented Dec 28, 2024

Describe the bug
I'm getting a hydration error, but only in a very specific configuration of island/Transition/Suspend. See the code in the folded section below for more details.

Code pasted here:
/// Minimal reproduction of a hydration error.
///
/// Error:
///
/// ```plaintext
/// A hydration error occurred while trying to hydrate an element defined at src/lib.rs:79:10.
///
/// The framework expected an HTML <div> element, but found this instead:  
/// #text "Bar"
///     ...
///     parentElement: <div>
///     ...
///
/// The hydration mismatch may have occurred slightly earlier, but this is the first time the framework found a node of an unexpected type.
/// ```
///
/// Note the following:
/// - Parent (`Foo`) is an island
///     - Issue does not repro if `Foo` is a component
/// - Parent contains a `Transition` with a view rendered in a `Suspend`
///     - Issue does not repro if `Bar` and `Baz` are not in a `Transition` + `Suspend`
/// - `Suspend`'s view contains two islands
///     - Issue does not repro if only `Bar` is present
///     - Issue does not repro if either or both of `Bar`/`Baz` are components
///
/// Interestingly, and possibly related, the error is different if `Bar`/`Baz` are replaced with `Bar2`/`Baz2`:
///
/// ```plaintext
/// panicked at /home/spencer/code/leptos/tachys/src/html/mod.rs:188:14:
/// called `Option::unwrap()` on a `None` value
/// ```
#[island]
fn Foo() -> impl IntoView {
    view! {
        <Transition>
            {move || Suspend::new(async move {
                    view! {
                        <Bar/>
                        <Baz/>
                        // <Bar2/>
                        // <Baz2/>
                    }
            })}
        </Transition>
    }
}

#[island]
fn Bar() -> impl IntoView {
    view! {
        <div>"Bar"</div>
    }
}

#[island]
fn Baz() -> impl IntoView {
    view! {
        <div>"Baz"</div>
    }
}

#[island]
fn Bar2() -> impl IntoView {
    view! {
        <div><p>"Bar2"</p></div>
    }
}

#[island]
fn Baz2() -> impl IntoView {
    view! {
        <div><p>"Baz2"</p></div>
    }
}

The repro code is also available here in the hackernews_islands_axum example: spencewenski@b40a8b6

To Reproduce
Steps to reproduce the behavior:

  1. Run the hackernews_islands_axum example from spencewenski@b40a8b6
  2. Open the devtools and observe the hydration error log

Expected behavior
No hydration error should occur

Screenshots
2024-12-28-125115_1021x357_scrot

@spencewenski spencewenski changed the title Hydration bug when multiple islands are nested inside a Transition Hydration error when multiple islands are nested inside a Transition Dec 28, 2024
@gbj
Copy link
Collaborator

gbj commented Dec 31, 2024

#3424 should fix this -- let me know if it works for your actual use case. The root cause was issues with any islands that were created inside a closure, inside another island.

@spencewenski
Copy link
Contributor Author

Awesome! I pulled down the branch for #3424 and the hydration error does not occur anymore. Thanks, @gbj! 🎉

@gbj gbj closed this as completed in 9c54da3 Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants