Repository navigation
fix(ui): stop reloads from retaining every previous review - #1201
Merged
Merged
Conversation
currentReviewVerticalStop was rebuilt whenever the measured stops changed, which happens one render after a reload swaps the files. That render's scope still held the resolveCommentRequest built for the new files, whose scope held the previous currentReviewVerticalStop, and so on back to the first load. In --watch every reload kept the old DiffFiles and row plans alive. Read the stops through a ref so the callback stays stable and the chain never forms.
|
@rnihesh is attempting to deploy a commit to the Modem Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
PR author is not in the allowed authors list. |
Contributor
Author
|
@benvinegar would you mind taking a look when you get a chance? Ran into this with a couple of |
Member
|
@rnihesh Which version were you running? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running
hunk diff --watchfor a while, memory keeps climbing and never comes back down. I had two instances open on this repo and noticed it.What's happening
On a reload,
useTerminalReviewrebuildsresolveCommentRequestin the render where the files change, then rebuildscurrentReviewVerticalStopone render later when the measured stops catch up. Closures from one render share its scope, so each of these keeps the previous render alive through the other one. The chain goes all the way back to the first load, so every reload'sDiffFiles, row plans and section geometry stick around.I found it by toggling one file between two states under
--watchand diffing heap snapshots (Bun.generateHeapSnapshot) after a forced GC. With 120 reloads there were 284 liveuseTerminalReviewrender scopes and ~880DiffFiles for a 6-file diff.Fix
currentReviewVerticalStopreads the stops from a ref (same pattern the hook already uses forlineCursorsRef/visibleFilesRef), so it no longer depends onreviewVerticalStopsand the chain never forms.Same watch run before/after, compiled binary, forced GC every 10s:
RSS still goes up and down with the allocator, but it drops back now instead of only going up.
Tests
Added a test to
useTerminalReview.test.tsxthat does 12 reloads, holds aWeakRefto each reload's file, and checks the early ones are collected afterBun.gc(true). It fails on main (8/8 retained) and passes with the fix.bun test packages/hunk/src/ui/hooks/useTerminalReview.test.tsx(64 pass)bun run typecheck,bun run lint,oxfmt --checkbun run test: 5093 pass, 8 fail. The same 8 fail on main for me too:bun test packages/hunk/src/ui/AppHost.reload.test.tsx packages/hunk/src/extensions/hostRuntimeModules.test.ts packages/hunk/src/extensions/installedPackageResolution.test.tsgives 28 pass / 8 fail with and without this change.Tested on macOS (arm64), Bun 1.4.3.
Related
No existing issue for this one that I could find. #521 trimmed what each section geometry holds; this is about old geometries not being released at all.
Not in this PR
Other
useCallbacks in this hook could form the same kind of chain if their deps change in staggered renders. After this fix the snapshots showed nothing else growing on reload, so I left them alone.