Skip to content

Commit

Permalink
fix: correctly reset hydration status in islands mode Suspense (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj authored Mar 2, 2024
1 parent 7996f83 commit 9fd2987
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 26 additions & 4 deletions leptos/src/suspense_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ where
runtime,
);

#[cfg(feature = "experimental-islands")]
let prev_no_hydrate =
SharedContext::no_hydrate();
#[cfg(feature = "experimental-islands")]
{
SharedContext::set_no_hydrate(
no_hydrate,
);
}

with_owner(owner, {
let rendered = with_owner(owner, {
move || {
HydrationCtx::continue_from(
current_id,
Expand All @@ -194,7 +197,15 @@ where
.render_to_string()
.to_string()
}
})
});

#[cfg(feature = "experimental-islands")]
SharedContext::set_no_hydrate(
prev_no_hydrate,
);

#[allow(clippy::let_and_return)]
rendered
}
},
// in-order streaming
Expand All @@ -205,14 +216,17 @@ where
runtime,
);

#[cfg(feature = "experimental-islands")]
let prev_no_hydrate =
SharedContext::no_hydrate();
#[cfg(feature = "experimental-islands")]
{
SharedContext::set_no_hydrate(
no_hydrate,
);
}

with_owner(owner, {
let rendered = with_owner(owner, {
move || {
HydrationCtx::continue_from(
current_id,
Expand All @@ -225,7 +239,15 @@ where
.into_view()
.into_stream_chunks()
}
})
});

#[cfg(feature = "experimental-islands")]
SharedContext::set_no_hydrate(
prev_no_hydrate,
);

#[allow(clippy::let_and_return)]
rendered
}
},
);
Expand Down
2 changes: 2 additions & 0 deletions leptos_reactive/src/hydration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,13 @@ thread_local! {
impl SharedContext {
/// Whether the renderer should currently add hydration IDs.
pub fn no_hydrate() -> bool {
println!("no_hydrate == {}", NO_HYDRATE.with(Cell::get));
NO_HYDRATE.with(Cell::get)
}

/// Sets whether the renderer should not add hydration IDs.
pub fn set_no_hydrate(hydrate: bool) {
println!("set_no_hydrate == {}", hydrate);
NO_HYDRATE.with(|cell| cell.set(hydrate));
}

Expand Down

0 comments on commit 9fd2987

Please sign in to comment.