Close Servo live sessions for removed tabs

This commit is contained in:
2026-05-13 02:41:54 -04:00
parent 74731d4faa
commit ac84a80d9e
11 changed files with 133 additions and 5 deletions
@@ -177,6 +177,13 @@ fn handle_request(
);
Ok(outcome)
}
LiveRequest::Close { tab_id } => {
if let Some(session) = sessions.remove(&tab_id) {
host.close_webview(&session.webview_id);
}
published_surface_ids.remove(&tab_id);
Ok(LiveOutcome::empty())
}
}
}
@@ -45,6 +45,9 @@ pub(super) enum LiveRequest {
Poll {
tab_id: String,
},
Close {
tab_id: String,
},
}
fn default_device_pixel_ratio() -> f32 {
@@ -240,3 +243,20 @@ pub(super) enum LiveSidecarError {
#[error(transparent)]
Json(#[from] serde_json::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn close_request_deserializes_from_wire() -> Result<(), serde_json::Error> {
let request =
serde_json::from_str::<LiveRequest>(r#"{"type":"close","tab_id":"tab-live-close"}"#)?;
assert!(matches!(
request,
LiveRequest::Close { tab_id } if tab_id == "tab-live-close"
));
Ok(())
}
}