Repository navigation
Keep rendered diff cards during refresh - #3255
Conversation
|
🚨 SLOP COP 🚨 · 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 }); |
There was a problem hiding this comment.
🚨 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 && |
There was a problem hiding this comment.
🚨 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.
There was a problem hiding this comment.
🚨 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+1to+2, while its patch stayed at+1; the card then renderediterateOverDiff: trailing context mismatchinstead 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: truewith a later viewport request carryingforce: 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
initialPatchesare 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.
4f4dbec to
24760d4
Compare
24760d4 to
2521ffc
Compare
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.tsxpnpm exec turbo run typecheck --filter=@bb/apppnpm exec turbo run lint --filter=@bb/appgit diff --checkFixes #