Skip to content

Keep rendered diff cards during refresh - #3255

Merged
ymichael merged 1 commit into
mainfrom
bb/prevent-unnecessary-diff-re-renders-thr_5yrvi4meaa
Sep 8, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/prevent-unnecessary-diff-re-renders-thr_5yrvi4meaa

Conversation

@ymichael

@ymichael ymichael commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Realtime workspace-change invalidation deleted every cached per-file patch before the refreshed diff table of contents could establish whether its contents had changed. Visible cards therefore regressed from rendered content to loading skeletons, including for filesystem changes that produced the same Git diff.

What changed

Retain per-file patch cache across realtime workspace invalidations. When the diff table of contents refreshes, refresh visible cached patches in place while retaining their rendered content; replacement patch content is rendered only after it arrives. Initial patch seeding only notifies React when its patch payload actually changed. No wire or CLI changes.

How you verified

  • pnpm exec turbo run test --filter=@bb/app -- --run src/hooks/realtime-cache-effects.test.ts src/hooks/queries/use-environment-diff-patches.test.tsx
  • pnpm exec turbo run typecheck --filter=@bb/app
  • pnpm exec turbo run lint --filter=@bb/app
  • git diff --check

Fixes #

AGENT GENERATED

@ymichael
ymichael marked this pull request as ready for review September 8, 2026 17:17
@ymichael

ymichael commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

@slopcop

@bb-slop-cop

bb-slop-cop Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I’m reviewing this now. I’ll check security, code quality and architecture, performance, and the rendered-diff refresh behavior end to end before posting a consolidated review.

previousFilesUpdatedAtRef.current !== null &&
previousFilesUpdatedAtRef.current !== filesUpdatedAt;
previousFilesUpdatedAtRef.current = filesUpdatedAt;
requestPaths({ visible: visiblePaths, overscan: overscanPaths, force });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Revalidate retained patches that were offscreen during the refresh

force only reaches the paths in the current virtualized window. A later scroll sends force: false, sees the retained cache entry, and never reloads it. I reproduced this with 80 changed files: after caching file-70, scrolling it offscreen, and editing it again, the card summary refreshed from +1 to +2 but the retained patch stayed at +1, causing iterateOverDiff: trailing context mismatch when the card remounted. Please track freshness in the cache and revalidate stale entries when they become visible (including already-loaded on-demand entries), rather than making freshness a one-shot property of the current viewport.

const toFetch = ordered.filter((path) => {
if (readDiffPatchEntry({ queryClient, identity, path }) !== undefined) {
if (
!pendingPathsRef.current.force &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Do not let an older in-flight request suppress the post-change refresh

force bypasses the cache check, but the next guard still drops the path when a request from the current eviction generation is loading. Realtime invalidation no longer bumps that generation, so an edit can arrive during request A, the newer forced refresh is skipped, and request A can later install its pre-edit patch as the final value. Please advance a freshness generation without deleting rendered data and discard/abort older responses or queue a trailing forced fetch. Add an overlapping-refresh test for this ordering.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain-English summary: this PR keeps already-rendered file diffs on screen while BB refreshes the changed-file list, then replaces visible patches in the background. That avoids loading-card flicker, but the current viewport-only refresh policy can leave retained patches permanently out of sync with their file summaries.

I found two blocking correctness issues and left both inline:

  • Cached patches outside the current virtualized window are never marked stale. In a live 80-file test, I cached and expanded file-70, scrolled it away, edited it again, and returned. Its header refreshed from +1 to +2, while its patch stayed at +1; the card then rendered iterateOverDiff: trailing context mismatch instead of the diff. Already-loaded on-demand patches have the same gap.
  • A workspace change that lands while an older patch request is in flight drops the newer forced refresh, because the loading guard sees the unchanged eviction generation. The older response can then become the final cached value.

There are a few related non-blocking problems worth covering in the same freshness model:

  • The 80 ms debounce can overwrite a pending force: true with a later viewport request carrying force: false.
  • Failed background refreshes are hidden behind cached data, and the stored error blocks every later forced refresh, so the stale card has no visible retry path.
  • Small diffs can do duplicate patch work: refreshed initialPatches are seeded, then the same visible paths are force-fetched again.
  • Removed and renamed paths now accumulate in an infinite-GC cache for as long as the diff panel remains mounted.

Architecturally, I did not find a duplicate implementation to reuse. The clean seam is the existing diff-patch cache owner: give cached entries a freshness generation there, advance it on realtime workspace/ref changes without deleting rendered data, and revalidate stale entries when displayed. That also gives old responses, retries, pruning, and debounce coalescing one shared policy instead of inferring freshness from filesUpdatedAt in the view.

Security review found no actionable issue. Cache keys include environment, target type/key, and path, and target-change guards prevent a retained response from crossing identities.

Verification: the focused app tests passed (72/72), @bb/app typecheck passed, git diff --check passed, and the browser reproduction above ran against a fresh isolated store at the exact head SHA. CI is green. The verification inventory gate was separately blocked by unrelated existing drift for the browser CLI family.

@ymichael
ymichael force-pushed the bb/prevent-unnecessary-diff-re-renders-thr_5yrvi4meaa branch from 4f4dbec to 24760d4 Compare September 8, 2026 18:11
@ymichael
ymichael marked this pull request as draft September 8, 2026 18:11
@ymichael
ymichael force-pushed the bb/prevent-unnecessary-diff-re-renders-thr_5yrvi4meaa branch from 24760d4 to 2521ffc Compare September 8, 2026 18:17
@ymichael
ymichael marked this pull request as ready for review September 8, 2026 18:20
@ymichael
ymichael merged commit aa7d245 into main Sep 8, 2026
16 checks passed
@ymichael
ymichael deleted the bb/prevent-unnecessary-diff-re-renders-thr_5yrvi4meaa branch September 8, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant