From b9be1c89a9c5480f7bb8a12a080bd199c3442566 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sat, 7 Nov 2026 20:12:09 -0600 Subject: [PATCH] fix(id): peers partial returns inner content only (#6956) --- pkgs/id/src/web/routes.rs | 7 ++++-- pkgs/id/src/web/templates.rs | 41 +++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/pkgs/id/src/web/routes.rs b/pkgs/id/src/web/routes.rs index b253c769e6..bb9e33e1af 100644 --- a/pkgs/id/src/web/routes.rs +++ b/pkgs/id/src/web/routes.rs @@ -20,7 +20,7 @@ use super::markdown::prosemirror_to_markdown; use super::templates::{ render_binary_viewer, render_editor, render_editor_page, render_file_list, render_file_list_content, render_main_page_wrapper, render_media_viewer, render_page, - render_peers, render_settings, + render_peers, render_peers_content, render_settings, }; use crate::fileops::{FileOpError, FileOps, claim_archive_name, snapshot_provenance_tags}; use crate::tags::TagStore; @@ -1055,7 +1055,10 @@ async fn peers_partial_handler(State(state): State) -> impl IntoRespon Vec::new() }; - Html(render_peers(&peers_data)) + // Return only the inner content: fetchPartial assigns this as + // innerHTML of #peers-content, so the wrapper must not be included + // (issue #6956). + Html(render_peers_content(&peers_data)) } /// Static assets handler. diff --git a/pkgs/id/src/web/templates.rs b/pkgs/id/src/web/templates.rs index 1b0d5bfeb1..bf6d5ff9b9 100644 --- a/pkgs/id/src/web/templates.rs +++ b/pkgs/id/src/web/templates.rs @@ -1101,6 +1101,19 @@ fn render_program_shell(title: &str, content: &str, assets: &AssetUrls) -> Strin pub fn render_peers(peers: &[(String, String, u64, u64)]) -> String { let mut html = String::with_capacity(2048); html.push_str("
\n"); + html.push_str(&render_peers_content(peers)); + html.push_str("
"); + html +} + +/// Render just the peers content (card) without the `#peers-content` wrapper. +/// +/// This is the replaceable inner content of the peers page. +/// Used by `/api/peers` for auto-refresh partial updates: the client's +/// `fetchPartial` assigns the response as `innerHTML` of `#peers-content`, +/// so the partial must not carry the wrapper itself (issue #6956). +pub fn render_peers_content(peers: &[(String, String, u64, u64)]) -> String { + let mut html = String::with_capacity(2048); html.push_str("
\n"); html.push_str("
Discovered Peers
\n"); html.push_str("
\n"); @@ -1134,7 +1147,6 @@ pub fn render_peers(peers: &[(String, String, u64, u64)]) -> String { html.push_str("
\n"); html.push_str("
\n"); - html.push_str(""); html } @@ -1539,6 +1551,33 @@ mod tests { assert!(html.contains("30s ago")); } + #[test] + fn test_render_peers_content_has_no_wrapper() { + // Regression for #6956: the /api/peers partial is assigned as + // innerHTML of #peers-content, so the inner renderer must not + // carry the wrapper (duplicate id + data-auto-refresh nesting). + let peers = vec![( + "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".to_owned(), + "test-node".to_owned(), + 42, + 30, + )]; + for html in [render_peers_content(&[]), render_peers_content(&peers)] { + assert!(!html.contains("peers-content"), "inner partial must not contain #peers-content wrapper: {html}"); + assert!(!html.contains("data-auto-refresh"), "inner partial must not contain data-auto-refresh: {html}"); + assert!(html.contains("Discovered Peers")); + } + assert!(render_peers_content(&peers).contains("test-node")); + assert!(render_peers_content(&[]).contains("No peers discovered yet")); + } + + #[test] + fn test_render_peers_wrapper_exactly_once() { + let html = render_peers(&[]); + assert_eq!(html.matches("id=\"peers-content\"").count(), 1); + assert_eq!(html.matches("data-auto-refresh").count(), 1); + } + #[test] fn test_format_age() { assert_eq!(format_age(5), "5s ago");