forge
Explore
Log in

Don't you dare go Hollow

Feed rows wear the log row; a deploy reloads a stale tab once

Browse files at this commit

e7bf52a40a62f7bdd8d3a709723fc76012455b7fAhmet Kaan GümüşParent: 9303e20
The feed renders the logs page's own row markup — stamp, actor, sentence,
subject — instead of its dense line.

Every answer through the layout carries the stylesheet's content hash as
the build stamp; a soft navigation or live refresh whose stamp differs
reloads the page instead of swapping new markup under old CSS. A dirty
form defers the reload to the next tick, and a persistent mismatch is
adopted once rather than looping.
crates/izlek-web/src/feed.rsmodified+25 -23
@@ -20,7 +20,6 @@ use topcoat::context::Cx;
20 use topcoat::router::{error::not_found, page};20 use topcoat::router::{error::not_found, page};
21 use topcoat::view::view;21 use topcoat::view::view;
22 22
23-
24 use crate::i18n::{Key, Lang, t};23 use crate::i18n::{Key, Lang, t};
25 use crate::server::{accounts, require_user};24 use crate::server::{accounts, require_user};
26 25
@@ -29,10 +28,13 @@ use crate::server::{accounts, require_user};
29 /// growing past the viewport.28 /// growing past the viewport.
30 const LIMIT: u32 = 50;29 const LIMIT: u32 = 50;
31 30
32-/// One rendered feed line: the strings the view stamps in, decided here so31+/// One rendered feed line — the same anatomy as the Logs page's activity
33-/// the template stays a list of facts rather than a chain of lookups.32+/// rows (`log-row`: stamp · actor · sentence · subject), with the subject
33+/// as the one link. The strings are decided here so the template stays a
34+/// list of facts rather than a chain of lookups.
34 struct FeedRow {35 struct FeedRow {
35- task_label: String,36+ key: String,
37+ title: String,
36 href: String,38 href: String,
37 actor: String,39 actor: String,
38 sentence: String,40 sentence: String,
@@ -57,14 +59,12 @@ async fn feed_page(cx: &Cx) -> Result {
57 .await?;59 .await?;
58 let zone = izlek_core::detail::parse_zone(&user.timezone);60 let zone = izlek_core::detail::parse_zone(&user.timezone);
59 61
62+ let empty = lines.is_empty();
60 let rows: Vec<FeedRow> = lines63 let rows: Vec<FeedRow> = lines
61 .iter()64 .iter()
62 .map(|line| FeedRow {65 .map(|line| FeedRow {
63- task_label: match (&line.task_key, &line.title) {66+ key: line.task_key.clone().unwrap_or_default(),
64- (Some(key), Some(title)) => format!("{key} · {title}"),67+ title: line.title.clone().unwrap_or_default(),
65- (Some(key), None) => key.clone(),
66- _ => line.title.clone().unwrap_or_default(),
67- },
68 href: format!("/?task={}", line.task_id.as_deref().unwrap_or_default()),68 href: format!("/?task={}", line.task_id.as_deref().unwrap_or_default()),
69 actor: line69 actor: line
70 .actor_name70 .actor_name
@@ -89,22 +89,24 @@ async fn feed_page(cx: &Cx) -> Result {
89 <div class="panel-head">89 <div class="panel-head">
90 <h2 class="panel-title">(t(lang, Key::NavFeed))</h2>90 <h2 class="panel-title">(t(lang, Key::NavFeed))</h2>
91 </div>91 </div>
92- if rows.is_empty() {92+ <div class="panel-body">
93- <p class="feed-empty">(t(lang, Key::FeedEmpty))</p>93+ <div class="log-list">
94- } else {
95- <ol class="feed-list">
96 for row in rows {94 for row in rows {
97- <li class="feed-row">95+ <div class="log-row">
98- <a class="feed-task" href=(row.href)>(row.task_label)</a>96+ <span class="log-stamp">(row.when)</span>
99- <span class="feed-line">97+ <span class="log-actor">(row.actor)</span>
100- <span class="feed-actor">(row.actor)</span>98+ <span class="log-line">(row.sentence)</span>
101- <span class="feed-sentence">(row.sentence)</span>99+ <a class="log-task" href=(row.href)>
102- </span>100+ <span class="log-key">(format!("({})", row.key))</span>
103- <span class="feed-when">(row.when)</span>101+ <span class="log-title">(row.title)</span>
104- </li>102+ </a>
103+ </div>
105 }104 }
106- </ol>105+ </div>
107- }106+ if empty {
107+ <p class="rules-quiet">(t(lang, Key::FeedEmpty))</p>
108+ }
109+ </div>
108 </section>110 </section>
109 </main>111 </main>
110 }112 }
crates/izlek-web/src/layout.rsmodified+25 -2
@@ -283,6 +283,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result {
283 (function () { \283 (function () { \
284 if (window.__izlekSoft) { return; } \284 if (window.__izlekSoft) { return; } \
285 window.__izlekSoft = true; \285 window.__izlekSoft = true; \
286+ window.__izlekBuild = document.documentElement.getAttribute('data-build') || ''; \
286 window.__izlekOwn = function (node, classes, attrs) { \287 window.__izlekOwn = function (node, classes, attrs) { \
287 var own = node.__izlekMine; \288 var own = node.__izlekMine; \
288 if (!own) { own = node.__izlekMine = { c: [], a: [] }; } \289 if (!own) { own = node.__izlekMine = { c: [], a: [] }; } \
@@ -416,9 +417,24 @@ pub async fn soft_nav_script(cx: &Cx) -> Result {
416 function navStep() { return ++window.__izlekNav; } \417 function navStep() { return ++window.__izlekNav; } \
417 function stillCurrent(n) { return window.__izlekNav === n; } \418 function stillCurrent(n) { return window.__izlekNav === n; } \
418 function swap(html, url, fresh, push, morphing) { \419 function swap(html, url, fresh, push, morphing) { \
420+ var doc = new DOMParser().parseFromString(html, 'text/html'); \
421+ var build = doc.documentElement.getAttribute('data-build') || ''; \
422+ if (build && window.__izlekBuild && build !== window.__izlekBuild) { \
423+ var dirty = captureFields().length > 0; \
424+ var reloaded = null; \
425+ try { reloaded = sessionStorage.getItem('izlekSkewFor'); } catch (err) { } \
426+ if (!dirty && reloaded !== build) { \
427+ try { sessionStorage.setItem('izlekSkewFor', build); } catch (err) { } \
428+ location.reload(); \
429+ return; \
430+ } \
431+ if (!dirty) { \
432+ window.__izlekBuild = build; \
433+ document.documentElement.setAttribute('data-build', build); \
434+ } \
435+ } \
419 var keep = window.__izlekKeep ? captureFields() : null; \436 var keep = window.__izlekKeep ? captureFields() : null; \
420 window.__izlekKeep = false; \437 window.__izlekKeep = false; \
421- var doc = new DOMParser().parseFromString(html, 'text/html'); \
422 var x = window.scrollX, y = window.scrollY; \438 var x = window.scrollX, y = window.scrollY; \
423 var root = doc.documentElement; \439 var root = doc.documentElement; \
424 if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \440 if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \
@@ -815,9 +831,16 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result {
815 content => content,831 content => content,
816 }?;832 }?;
817 833
834+ // The build stamp rides the html element on every render — page load,
835+ // soft navigation and live refresh all answer through this layout, and
836+ // the swap path reads it off the fetched document before it touches the
837+ // page. A tab left open across a deploy keeps the old stylesheet link
838+ // (the morph swaps body children, never the head), so a mismatch is
839+ // the client's cue to hard-reload rather than wear the old css.
840+ let build = STYLE.id().as_u64().to_string();
818 view! {841 view! {
819 <!DOCTYPE html>842 <!DOCTYPE html>
820- <html lang=(lang.code()) data-theme=(dark.then_some("dark")) data-ui=(ui)>843+ <html lang=(lang.code()) data-theme=(dark.then_some("dark")) data-ui=(ui) data-build=(build)>
821 <head>844 <head>
822 <meta charset="utf-8">845 <meta charset="utf-8">
823 <meta name="viewport" content="width=device-width, initial-scale=1">846 <meta name="viewport" content="width=device-width, initial-scale=1">
crates/izlek-web/tests/http.rsmodified+28 -0
@@ -9903,3 +9903,31 @@ async fn the_feed_shows_each_person_their_stake() {
9903 let feed_html = String::from_utf8_lossy(&feed.bytes);9903 let feed_html = String::from_utf8_lossy(&feed.bytes);
9904 assert!(feed_html.contains("Nothing yet."), "{feed_html}");9904 assert!(feed_html.contains("Nothing yet."), "{feed_html}");
9905 }9905 }
9906+
9907+// The build stamp rides the html element of every render — the page a tab
9908+// loaded and every response a soft navigation or live refresh will fetch —
9909+// so a tab open across a deploy can tell stale css from current and reload
9910+// itself rather than paint new markup with old styles.
9911+#[tokio::test]
9912+async fn the_build_stamp_matches_across_page_and_refetch() {
9913+ let app = App::open().await;
9914+ let admin_cookie = admin(&app).await;
9915+
9916+ let mut stamps = Vec::new();
9917+ for path in ["/", "/settings", "/"] {
9918+ let page = app.get(path, Some(&admin_cookie)).await;
9919+ assert_eq!(page.status, StatusCode::OK);
9920+ let html = String::from_utf8_lossy(&page.bytes);
9921+ let stamp = html
9922+ .split("data-build=\"")
9923+ .nth(1)
9924+ .map(|rest| rest.split('"').next().unwrap_or("").to_string())
9925+ .unwrap_or_default();
9926+ assert!(!stamp.is_empty(), "no data-build stamp on {path}");
9927+ stamps.push(stamp);
9928+ }
9929+ assert!(
9930+ stamps.windows(2).all(|pair| pair[0] == pair[1]),
9931+ "the build stamp drifted between renders: {stamps:?}"
9932+ );
9933+}