fix(hub): keep the diff scroll and the typed answer across stream redraws

The stream rebuilt its list every few seconds, so a scrolled diff
jumped back to the top and the Other field lost focus and caret.
drawStream now runs inside keepTyping and keepScroll; keepScroll finds
the scrolled element again as the same nth element of its tag and
class in the same data-item row, so the stars Panels.decorate adds
after the draw do not shift it.

🎯 Fix: 95 %
💥 Break: 3 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 92
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-25 00:18:18 +00:00
1 parent dbc10536a4
commit 3d691b3706
3 files changed
+105 -2

No files matched your search

+21
View File
@@ -20,6 +20,27 @@
}
}
/**
* @param {HTMLElement} root the element draw() rebuilds.
* @param {Function} draw replaces root's children; an element scrolled inside a row with data-item gets its offsets back when draw() rebuilds it in the same row as the same nth element of its tag and class, so stars that Panels.decorate adds later do not shift it.
*/
function keepScroll(root, draw) {
const twins = (row, tag, name) => [...row.getElementsByTagName(tag)].filter((node) => node.className === name);
const held = [...root.querySelectorAll("[data-item] *")].filter((node) => node.scrollTop || node.scrollLeft).map((node) => {
const row = node.closest("[data-item]");
return [row.dataset.item, node.tagName, node.className, twins(row, node.tagName, node.className).indexOf(node), node.scrollTop, node.scrollLeft];
});
draw();
held.forEach(([item, tag, name, index, top, left]) => {
const row = root.querySelector(`[data-item="${CSS.escape(item)}"]`);
const node = row ? twins(row, tag, name)[index] : null;
if (node) {
node.scrollTop = top;
node.scrollLeft = left;
}
});
}
/**
* @param {Object} item a decision, a decision row, a decision card or a permission ask: id, options [{label, description, preview}], recommended (labels joined by PICKED), multi.
* @param {Object} how pick: called with the answer, one label, the toggled labels in option order joined by PICKED, or the trimmed Other text, and true for the Other text only; other: the Other field's placeholder; toggled: the Set of toggled labels of a multi decision, kept by the caller across redraws; chosen: the answer given so far, "" for none; locked: whether the dialog takes no answer; hint: what an answer does, shown in the titles; group: an extra class of the option list.
+2 -2
View File
@@ -164,10 +164,10 @@
stream.dom.list.replaceChildren(emptyState("Stream not readable", stream.error));
return;
}
stream.dom.list.replaceChildren(rows.length
keepTyping(stream.dom.list, () => keepScroll(stream.dom.list, () => stream.dom.list.replaceChildren(rows.length
? h("div", {class: "card flush"}, h("ol", {class: "feed"}, shown.map(eventRow)),
rows.length > shown.length ? h("p", {class: "footnote"}, `${rows.length - shown.length} older entries hidden; narrow down with a filter or the time range.`) : null)
: emptyState(stream.busy ? "Loading …" : "No entries", activeWaiting() ? "Nothing is waiting for you right now." : "Nothing in the chosen time range and filter."));
: emptyState(stream.busy ? "Loading …" : "No entries", activeWaiting() ? "Nothing is waiting for you right now." : "Nothing in the chosen time range and filter."))));
}
function streamScreen() {