Reload only the rows that changed
CI / Tests (push) Successful in 11s
CI / Generated images (push) Successful in 41s

Refreshing rebuilt the whole tree, and TreeView.reload() with no
argument drops the scroll position. Watching a job meant the view jumped
every fifteen seconds.

The provider now reconciles instead of replacing. update() rebuilds from
the store, matches rows to the existing nodes by identifier, copies the
rendered fields onto them, and reports the topmost rows that actually
changed; main.js reloads just those. Node identity survives the merge,
which is what makes a targeted reload possible. An open row that fetches
its own children has that cache dropped so it refetches — the running-job
path. A job finishing now reloads one run's row and nothing else.

Sections also each describe what they draw, so a section only rebuilds
when its own content moved: run activity no longer disturbs the pull
request list, and an idle tree is left alone entirely. This does not slow
anything down — a section showing a run in progress still updates on
every poll, and contributes a time bucket so its elapsed clock keeps
moving.

A row set changing at the root still needs a whole-tree reload; there the
selected row is re-revealed afterwards, which is the closest thing to a
scroll anchor Nova exposes.

Adds seventeen checks: no-op updates reporting nothing, a finishing job
naming only its own row, node identity surviving, a new run reloading
just its workflow group, and a new workflow escalating to a full reload.
168 checks total.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
This commit is contained in:
2026-08-28 20:30:17 -03:00
co-authored by Claude Opus 5
parent 4bc81b59e7
commit cf97f0dc2a
11 changed files with 496 additions and 97 deletions
+66 -17
View File
@@ -59,11 +59,60 @@ function buildSections(store) {
});
}
/** Rebuilds every section from current store state. */
function reloadSections(sections) {
for (const section of sections) {
section.provider.invalidate();
section.view.reload().catch((error) => log.debug("reload failed", String(error)));
/**
* Applies a section's changes to the view. Only the rows that actually changed
* are reloaded, which is what keeps the scroll position while a job is being
* watched. A shape change that cannot be patched falls back to a full reload,
* and there the selected row is used to put the view back roughly where it was
* — Nova exposes no way to read or set a tree's scroll offset directly.
*/
async function reloadSection(section) {
let update;
try {
update = await section.provider.update();
} catch (error) {
log.debug("could not rebuild the section", String(error));
return;
}
if (!update) return;
if (!update.full) {
for (const node of update.nodes) {
try {
await section.view.reload(node);
} catch (error) {
// Nova may not know this row; redraw everything instead.
log.debug("row reload failed, falling back to a full reload", String(error));
await fullReload(section);
return;
}
}
return;
}
await fullReload(section);
}
async function fullReload(section) {
const anchor = (section.view.selection || [])[0];
const identifier = anchor ? anchor.identifier : null;
try {
await section.view.reload();
} catch (error) {
log.debug("reload failed", String(error));
return;
}
if (!identifier) return;
try {
const restored = await section.provider.findByIdentifier(identifier);
if (restored) await section.view.reveal(restored, { select: true, focus: false });
} catch (error) {
// The row may simply be gone now; losing the anchor is not an error.
log.debug("could not restore the selection", String(error));
}
}
@@ -153,11 +202,12 @@ exports.activate = function () {
);
let timer = null;
let lastSignature = null;
const signatures = new Map();
/** Drops the memo so the next change redraws unconditionally. */
/** Forces the next change to rebuild every section from scratch. */
const redraw = () => {
lastSignature = null;
signatures.clear();
for (const section of sections) section.provider.invalidate();
};
const scheduleReload = () => {
@@ -165,16 +215,15 @@ exports.activate = function () {
timer = setTimeout(() => {
timer = null;
// Reloading rebuilds every row, which is disruptive even with
// expansion preserved, so a poll that changed nothing does nothing.
const signature = store.signature();
if (signature === lastSignature) {
log.debug("nothing changed; leaving the sidebar alone");
return;
}
lastSignature = signature;
// Each section decides for itself. Run activity must not redraw the
// pull request list, and an idle poll must redraw nothing at all.
for (const section of sections) {
const signature = section.provider.signature();
if (signature !== null && signature === signatures.get(section.id)) continue;
reloadSections(sections);
signatures.set(section.id, signature);
reloadSection(section);
}
}, RELOAD_DEBOUNCE_MS);
};