diff --git a/crates/izlek-web/src/feed.rs b/crates/izlek-web/src/feed.rs index 009e838..0cf19ba 100644 --- a/crates/izlek-web/src/feed.rs +++ b/crates/izlek-web/src/feed.rs @@ -20,7 +20,6 @@ use topcoat::context::Cx; use topcoat::router::{error::not_found, page}; use topcoat::view::view; - use crate::i18n::{Key, Lang, t}; use crate::server::{accounts, require_user}; @@ -29,10 +28,13 @@ use crate::server::{accounts, require_user}; /// growing past the viewport. const LIMIT: u32 = 50; -/// One rendered feed line: the strings the view stamps in, decided here so -/// the template stays a list of facts rather than a chain of lookups. +/// One rendered feed line — the same anatomy as the Logs page's activity +/// rows (`log-row`: stamp · actor · sentence · subject), with the subject +/// as the one link. The strings are decided here so the template stays a +/// list of facts rather than a chain of lookups. struct FeedRow { - task_label: String, + key: String, + title: String, href: String, actor: String, sentence: String, @@ -57,14 +59,12 @@ async fn feed_page(cx: &Cx) -> Result { .await?; let zone = izlek_core::detail::parse_zone(&user.timezone); + let empty = lines.is_empty(); let rows: Vec = lines .iter() .map(|line| FeedRow { - task_label: match (&line.task_key, &line.title) { - (Some(key), Some(title)) => format!("{key} · {title}"), - (Some(key), None) => key.clone(), - _ => line.title.clone().unwrap_or_default(), - }, + key: line.task_key.clone().unwrap_or_default(), + title: line.title.clone().unwrap_or_default(), href: format!("/?task={}", line.task_id.as_deref().unwrap_or_default()), actor: line .actor_name @@ -89,22 +89,24 @@ async fn feed_page(cx: &Cx) -> Result {

(t(lang, Key::NavFeed))

- if rows.is_empty() { -

(t(lang, Key::FeedEmpty))

- } else { -
    +
    +
    for row in rows { -
  1. - (row.task_label) - - (row.actor) - (row.sentence) - - (row.when) -
  2. +
    + (row.when) + (row.actor) + (row.sentence) + + (format!("({})", row.key)) + (row.title) + +
    } -
- } + + if empty { +

(t(lang, Key::FeedEmpty))

+ } + } diff --git a/crates/izlek-web/src/layout.rs b/crates/izlek-web/src/layout.rs index cc63df9..3443bfb 100644 --- a/crates/izlek-web/src/layout.rs +++ b/crates/izlek-web/src/layout.rs @@ -283,6 +283,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { (function () { \ if (window.__izlekSoft) { return; } \ window.__izlekSoft = true; \ + window.__izlekBuild = document.documentElement.getAttribute('data-build') || ''; \ window.__izlekOwn = function (node, classes, attrs) { \ var own = node.__izlekMine; \ if (!own) { own = node.__izlekMine = { c: [], a: [] }; } \ @@ -416,9 +417,24 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { function navStep() { return ++window.__izlekNav; } \ function stillCurrent(n) { return window.__izlekNav === n; } \ function swap(html, url, fresh, push, morphing) { \ + var doc = new DOMParser().parseFromString(html, 'text/html'); \ + var build = doc.documentElement.getAttribute('data-build') || ''; \ + if (build && window.__izlekBuild && build !== window.__izlekBuild) { \ + var dirty = captureFields().length > 0; \ + var reloaded = null; \ + try { reloaded = sessionStorage.getItem('izlekSkewFor'); } catch (err) { } \ + if (!dirty && reloaded !== build) { \ + try { sessionStorage.setItem('izlekSkewFor', build); } catch (err) { } \ + location.reload(); \ + return; \ + } \ + if (!dirty) { \ + window.__izlekBuild = build; \ + document.documentElement.setAttribute('data-build', build); \ + } \ + } \ var keep = window.__izlekKeep ? captureFields() : null; \ window.__izlekKeep = false; \ - var doc = new DOMParser().parseFromString(html, 'text/html'); \ var x = window.scrollX, y = window.scrollY; \ var root = doc.documentElement; \ if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \ @@ -815,9 +831,16 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result { content => content, }?; + // The build stamp rides the html element on every render — page load, + // soft navigation and live refresh all answer through this layout, and + // the swap path reads it off the fetched document before it touches the + // page. A tab left open across a deploy keeps the old stylesheet link + // (the morph swaps body children, never the head), so a mismatch is + // the client's cue to hard-reload rather than wear the old css. + let build = STYLE.id().as_u64().to_string(); view! { - + diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 4a80b9e..ef521fa 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -9903,3 +9903,31 @@ async fn the_feed_shows_each_person_their_stake() { let feed_html = String::from_utf8_lossy(&feed.bytes); assert!(feed_html.contains("Nothing yet."), "{feed_html}"); } + +// The build stamp rides the html element of every render — the page a tab +// loaded and every response a soft navigation or live refresh will fetch — +// so a tab open across a deploy can tell stale css from current and reload +// itself rather than paint new markup with old styles. +#[tokio::test] +async fn the_build_stamp_matches_across_page_and_refetch() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + + let mut stamps = Vec::new(); + for path in ["/", "/settings", "/"] { + let page = app.get(path, Some(&admin_cookie)).await; + assert_eq!(page.status, StatusCode::OK); + let html = String::from_utf8_lossy(&page.bytes); + let stamp = html + .split("data-build=\"") + .nth(1) + .map(|rest| rest.split('"').next().unwrap_or("").to_string()) + .unwrap_or_default(); + assert!(!stamp.is_empty(), "no data-build stamp on {path}"); + stamps.push(stamp); + } + assert!( + stamps.windows(2).all(|pair| pair[0] == pair[1]), + "the build stamp drifted between renders: {stamps:?}" + ); +}