refactor(runtime): own commit file-preview state in useDiffHydration (#1237)#1275
Merged
Merged
Conversation
…1237) Item 2 of the app.ts decomposition. Moves the `filePreview` / `filePreviewLoading` `useState` pair out of app.ts into a new `useCommitFilePreviewState` hook in the useDiffHydration module. Unlike the worktree / stash / compare diff slots — whose setters are shared with staging callbacks and the compare-reset effect, so they must stay in app.ts — `setFilePreview` / `setFilePreviewLoading` are written only by the file-preview loader. That makes the pair safe to own in the hook module via a position-preserving split: the state hook is called at the original `useState` slot, and `useCommitFilePreviewHydration` (the effect) stays at its original slot far below, still handed the setters. Nothing moves, so hook order is preserved and the render-snapshot suite is sufficient. Mirrors the item-1a `useCommitDetailState` split. Also drops the now-unused `GitCommitFilePreview` import from app.ts and adds a unit test for the new state hook.
This was referenced Jun 15, 2026
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.
Item 2 —
app.tsdecomposition (#1237)Follows #1273 (item 1a, merged). Moves the
filePreview/filePreviewLoadinguseStatepair out ofapp.tsinto a newuseCommitFilePreviewStatehook in theuseDiffHydrationmodule.(Supersedes #1274, which was auto-closed when its stacked base branch was deleted on merge of #1273. Rebased onto
main; content unchanged.)Why this pair (and not the others) can move
The module previously kept all diff
useStateslots inapp.tsbecause their setters are shared —setWorktreeDiff/setWorktreeHunksare called by the staging callbacks, and the stash/compare setters by the compare-reset effect.setFilePreview/setFilePreviewLoadingare the exception: only the file-preview loader writes them, so the pair can be owned in the hook module.Position-preserving split (same template as item 1a)
useCommitFilePreviewState(React)— issues theuseStatepair at its original slot near the top ofapp.ts; returns values + setters.useCommitFilePreviewHydration(...)— the existing loader effect, unchanged, still at its original slot ~900 lines below, still handed the setters.Nothing moves → hook order preserved → render-snapshot suite is sufficient.
Changes
useDiffHydration.ts: adduseCommitFilePreviewState; update module header note.app.ts: bareuseStatepair →useCommitFilePreviewState(React); drop now-unusedGitCommitFilePreviewimport.useDiffHydration.test.ts: unit test for the new state hook.Validation
jest(workstation): 107 suites / 1854 tests pass, 68 snapshots no diffstsc --noEmit: clean ·eslint: 0 errors ·rollup -c: buildsdist/