Merge pull request #4427 from zakstucke/zak/root-owner-cleanup

Force cleanup even if there are other references to the root owner
This commit is contained in:
Greg Johnston
2025-11-02 14:49:29 -05:00
committed by GitHub
5 changed files with 31 additions and 23 deletions

View File

@@ -121,7 +121,7 @@ pub trait ExtendResponse: Sized {
// drop the owner, cleaning up the reactive runtime, // drop the owner, cleaning up the reactive runtime,
// once the stream is over // once the stream is over
.chain(once(async move { .chain(once(async move {
owner.unset(); owner.unset_with_forced_cleanup();
Default::default() Default::default()
})), })),
)); ));

View File

@@ -221,18 +221,15 @@ fn env_w_default(
/// An enum that can be used to define the environment Leptos is running in. /// An enum that can be used to define the environment Leptos is running in.
/// Setting this to the `PROD` variant will not include the WebSocket code for `cargo-leptos` watch mode. /// Setting this to the `PROD` variant will not include the WebSocket code for `cargo-leptos` watch mode.
/// Defaults to `DEV`. /// Defaults to `DEV`.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)] #[derive(
Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Default,
)]
pub enum Env { pub enum Env {
PROD, PROD,
#[default]
DEV, DEV,
} }
impl Default for Env {
fn default() -> Self {
Self::DEV
}
}
fn env_from_str(input: &str) -> Result<Env, LeptosConfigError> { fn env_from_str(input: &str) -> Result<Env, LeptosConfigError> {
let sanitized = input.to_lowercase(); let sanitized = input.to_lowercase();
match sanitized.as_ref() { match sanitized.as_ref() {
@@ -279,18 +276,15 @@ impl TryFrom<String> for Env {
/// An enum that can be used to define the websocket protocol Leptos uses for hotreloading /// An enum that can be used to define the websocket protocol Leptos uses for hotreloading
/// Defaults to `ws`. /// Defaults to `ws`.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)] #[derive(
Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Default,
)]
pub enum ReloadWSProtocol { pub enum ReloadWSProtocol {
#[default]
WS, WS,
WSS, WSS,
} }
impl Default for ReloadWSProtocol {
fn default() -> Self {
Self::WS
}
}
fn ws_from_str(input: &str) -> Result<ReloadWSProtocol, LeptosConfigError> { fn ws_from_str(input: &str) -> Result<ReloadWSProtocol, LeptosConfigError> {
let sanitized = input.to_lowercase(); let sanitized = input.to_lowercase();
match sanitized.as_ref() { match sanitized.as_ref() {

View File

@@ -340,6 +340,8 @@ impl Owner {
} }
/// Removes this from its state as the thread-local owner and drops it. /// Removes this from its state as the thread-local owner and drops it.
/// If there are other holders of this owner, it may not cleanup, if always cleaning up is required,
/// see [`Owner::unset_with_forced_cleanup`].
pub fn unset(self) { pub fn unset(self) {
OWNER.with_borrow_mut(|owner| { OWNER.with_borrow_mut(|owner| {
if owner.as_ref().and_then(|n| n.upgrade()) == Some(self) { if owner.as_ref().and_then(|n| n.upgrade()) == Some(self) {
@@ -348,6 +350,23 @@ impl Owner {
}) })
} }
/// Removes this from its state as the thread-local owner and drops it.
/// Unlike [`Owner::unset`], this will always run cleanup on this owner,
/// even if there are other holders of this owner.
pub fn unset_with_forced_cleanup(self) {
OWNER.with_borrow_mut(|owner| {
if owner
.as_ref()
.and_then(|n| n.upgrade())
.map(|o| o == self)
.unwrap_or(false)
{
mem::take(owner);
}
});
self.cleanup();
}
/// Returns the current [`SharedContext`], if any. /// Returns the current [`SharedContext`], if any.
#[cfg(feature = "hydration")] #[cfg(feature = "hydration")]
pub fn current_shared_context( pub fn current_shared_context(

View File

@@ -369,7 +369,7 @@ impl ResolvedStaticPath {
eprintln!("{e}"); eprintln!("{e}");
} }
} }
owner.unset(); owner.unset_with_forced_cleanup();
} }
} }
}); });

View File

@@ -642,18 +642,13 @@ struct DiffOpRemove {
at: usize, at: usize,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
enum DiffOpAddMode { enum DiffOpAddMode {
#[default]
Normal, Normal,
Append, Append,
} }
impl Default for DiffOpAddMode {
fn default() -> Self {
Self::Normal
}
}
fn apply_diff<T, VFS, V>( fn apply_diff<T, VFS, V>(
parent: Option<&crate::renderer::types::Element>, parent: Option<&crate::renderer::types::Element>,
marker: &crate::renderer::types::Placeholder, marker: &crate::renderer::types::Placeholder,