Skip to content

refactor(runtime): extract commit-detail hydration from app.ts (#1237)#1273

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

refactor(runtime): extract commit-detail hydration from app.ts (#1237)#1273
gfargo merged 1 commit into
mainfrom
feat/app-decompose-commit-detail-hydration

Conversation

@gfargo

@gfargo gfargo commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Item 1a — app.ts decomposition (#1237)

Lifts the detail / detailLoading hydration cluster out of app.ts into a new useCommitDetailHydration module. This is the one remaining hydration cluster whose loader effect was still inline (the other diff/detail loaders were extracted in the 0.72 series).

Approach — position-preserving two-hook split

The useState pair (top of the hydration-state block) and its loader effect are ~600 lines apart, with selected declared in between. Collapsing them into one call site would reorder hooks. So, mirroring the established useBlameLoadingState + useDetailHydration precedent, the module exports two hooks, each called at the original position:

  • useCommitDetailState(React) — issues the detail / detailLoading useState pair in its original slot; returns values + setters.
  • useCommitDetailHydration(React, { git, selected, setDetail, setDetailLoading }) — issues the loader effect in its original slot.

The effect is reproduced verbatim — same !selected guard, active cancellation flag, safe() wrapper, detailLoading toggles, and [git, selected?.hash] dependency array. Nothing moves, so there is no effect-reordering risk and the render-snapshot suite is fully sufficient to prove behavior preservation.

Changes

  • app.ts: bare useState pair → useCommitDetailState(React); inline loadDetail effect → useCommitDetailHydration(...). Net −8 LOC.
  • New hooks/useCommitDetailHydration.ts.
  • New hooks/useCommitDetailHydration.test.ts — behavioral tests for the guard (no fetch), load (toggle + fetch + store), and cancellation (stale-write suppression) paths.

Validation

  • jest (full): 282 suites / 3512 tests pass, 68 snapshots no diffs
  • new hook test: 4/4
  • tsc --noEmit: clean
  • eslint: 0 errors
  • rollup -c: builds dist/

Item 1a of the app.ts decomposition. Lifts the `detail` / `detailLoading`
cluster into a new `useCommitDetailHydration` module, split into two
position-preserving hooks so React's hook order is preserved exactly:

- `useCommitDetailState` issues the `useState` pair in its original slot
  (top of the hydration-state block), returning values + setters.
- `useCommitDetailHydration` issues the loader effect in its original
  slot (~600 lines below), handed the setters.

The effect is reproduced verbatim — same `!selected` guard, `active`
cancellation flag, `safe()` wrapper, `detailLoading` toggles, and
`[git, selected?.hash]` dependency array. Nothing moves, so there is no
effect-reordering risk and the render-snapshot suite is sufficient.
Mirrors the established `useBlameLoadingState` + `useDetailHydration`
split. Adds behavioral tests for the guard, load, and cancellation paths.
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