Keep the view steady when reacting or commenting

Bind each cached loader to a `{@const}` so the `{#await}` blocks keep
the same promise across patch reloads instead of re-running and
flashing their pending branch.
This commit is contained in:
Brandon Oxendine
2026-09-14 10:00:13 +02:00
committed by Rūdolfs Ošiņš
parent 7cea431306
commit ba5e571337
4 changed files with 35 additions and 6 deletions
+7 -1
View File
@@ -768,7 +768,13 @@
disabled={isTeaserDisabled(commit.id)}
{commit}>
{#if commit.parents.length > 0}
{#await cachedDiffStats(rid, commit.parents[0], commit.id) then commitStats}
<!-- Bound outside the `{#await}`; see `ReviewCodeThread`. -->
{@const statsPromise = cachedDiffStats(
rid,
commit.parents[0],
commit.id,
)}
{#await statsPromise then commitStats}
<span class="commit-stats">
<Icon name="document" />
{commitStats.filesChanged}
+5 -1
View File
@@ -176,6 +176,10 @@
return host.split(".").includes(a);
}
// Held in a `$derived`; see `ReviewCodeThread`. The TTL here means a re-run
// would refetch and blank the chip.
const jobsPromise = $derived(cachedListJobs(rid, commit));
function toggleNode(key: string) {
if (collapsed.has(key)) {
collapsed.delete(key);
@@ -289,7 +293,7 @@
}
</style>
{#await cachedListJobs(rid, commit) then jobs}
{#await jobsPromise then jobs}
{#if jobs.length > 0}
{@const groups = groupJobs(jobs)}
{@const overallCounts = totalCounts(groups)}
+9 -2
View File
@@ -136,8 +136,15 @@
{#if path}
<!-- The file's own patch text, which is all the renderer needs; the structured
diff is not fetched here at all. -->
{#await cachedGetDiffText(rid, base, head, 3, path)}
diff is not fetched here at all.
Bound to a `{@const}` (a derived) rather than called inside the
`{#await}`: a patch reload replaces the props this reads, and an inline
call would re-run the block, flashing the pending branch and jumping the
scroll position. The derived returns the same cached promise, so it
does not. -->
{@const filePatchPromise = cachedGetDiffText(rid, base, head, 3, path)}
{#await filePatchPromise}
<div class="fallback">Loading code…</div>
{:then filePatch}
<div class="wrapper">
+14 -2
View File
@@ -1674,11 +1674,16 @@
</div>
{/if}
{#if targetRev && targetRev.base !== targetRev.head}
<!-- Bound outside the `{#await}`; see `ReviewCodeThread`. -->
{@const revisionDiff = cachedGetDiff(rid, {
base: targetRev.base,
head: targetRev.head,
})}
{#if hasBody || hasCommits}
<div class="revision-card-divider"></div>
{/if}
<div class="revision-diff-tease">
{#await cachedGetDiff( rid, { base: targetRev.base, head: targetRev.head } )}
{#await revisionDiff}
<div class="revision-diff-loading txt-body-m-regular">
Loading diff…
</div>
@@ -1737,7 +1742,14 @@
</span>
{/if}
{/snippet}
{#await cachedGetDiffText(rid, targetRev.base, targetRev.head, 3, path)}
{@const filePatchPromise = cachedGetDiffText(
rid,
targetRev.base,
targetRev.head,
3,
path,
)}
{#await filePatchPromise}
<div></div>
{:then filePatch}
<PierreSnippet