Skip to content

refactor(runtime): own commit file-preview state in useDiffHydration (#1237)#1275

Merged
gfargo merged 1 commit into
mainfrom
feat/app-decompose-file-preview-hydration
Jun 15, 2026
Merged

refactor(runtime): own commit file-preview state in useDiffHydration (#1237)#1275
gfargo merged 1 commit into
mainfrom
feat/app-decompose-file-preview-hydration

Conversation

@gfargo

@gfargo gfargo commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Item 2 — app.ts decomposition (#1237)

Follows #1273 (item 1a, merged). Moves the filePreview / filePreviewLoading useState pair out of app.ts into a new useCommitFilePreviewState hook in the useDiffHydration module.

(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 useState slots in app.ts because their setters are shared — setWorktreeDiff / setWorktreeHunks are called by the staging callbacks, and the stash/compare setters by the compare-reset effect. setFilePreview / setFilePreviewLoading are 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 the useState pair at its original slot near the top of app.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: add useCommitFilePreviewState; update module header note.
  • app.ts: bare useState pair → useCommitFilePreviewState(React); drop now-unused GitCommitFilePreview import.
  • useDiffHydration.test.ts: unit test for the new state hook.

Validation

  • jest (workstation): 107 suites / 1854 tests pass, 68 snapshots no diffs
  • tsc --noEmit: clean · eslint: 0 errors · rollup -c: builds dist/

…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.
@gfargo gfargo merged commit b463a02 into main Jun 15, 2026
16 checks passed
@gfargo gfargo deleted the feat/app-decompose-file-preview-hydration branch June 15, 2026 13:57
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