fix: correctly reset hydration status in islands mode Suspense (closes #2332) (#2393)

This commit is contained in:
Greg Johnston 2024-03-02 11:57:35 -05:00 committed by GitHub
parent 7996f835d0
commit 9fd2987447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 4 deletions

View file

@ -173,6 +173,9 @@ where
runtime,
);
#[cfg(feature = "experimental-islands")]
let prev_no_hydrate =
SharedContext::no_hydrate();
#[cfg(feature = "experimental-islands")]
{
SharedContext::set_no_hydrate(
@ -180,7 +183,7 @@ where
);
}
with_owner(owner, {
let rendered = with_owner(owner, {
move || {
HydrationCtx::continue_from(
current_id,
@ -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
@ -205,6 +216,9 @@ where
runtime,
);
#[cfg(feature = "experimental-islands")]
let prev_no_hydrate =
SharedContext::no_hydrate();
#[cfg(feature = "experimental-islands")]
{
SharedContext::set_no_hydrate(
@ -212,7 +226,7 @@ where
);
}
with_owner(owner, {
let rendered = with_owner(owner, {
move || {
HydrationCtx::continue_from(
current_id,
@ -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
}
},
);

View file

@ -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));
}