Skip to content

refactor(repl): extract composedOnScroll routing (audit §1.1.1 slice #15) - #185

Merged
dahai80 merged 1 commit into
mainfrom
audit/repl-split-slice15-composedonscroll
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit/repl-split-slice15-composedonscroll

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Audit §1.1.1 god-module split — slice #15

Extract the composedOnScroll scroll-routing logic from src/screens/REPL.tsx into a pure helper.

What

  • NEW src/utils/composedOnScroll.ts — applyComposedOnScroll(sticky, handle, setters): no React hooks, no JSX, no await. Only side effects: mutate lastUserScrollTsRef.current + dispatch to 4 callbacks/setters (onRepin/onScrollAway/maybeLoadOlder/setAppState). Byte-identical to the inlined useCallback body.
  • MOD src/screens/REPL.tsx — composedOnScroll useCallback replaced with thin wrapper; deps array [onRepin, onScrollAway, maybeLoadOlder, setAppState] unchanged verbatim (feature() is a bun:bundle build-time DCE macro, not a runtime dep). Downstream reads same const name.
  • NEW src/__tests__/utils/composedOnScroll.test.ts — 5 cases: timestamp write, sticky→onRepin, non-sticky→onScrollAway(handle), every-scroll timestamp invariant, KAIROS/BUDDY arms DCE-off asserted.

feature() DCE constraint

feature("KAIROS")/feature("BUDDY") are bun:bundle compile-time macros. Under bun test (no build flag) they DCE to false → the maybeLoadOlder + setAppState (clear companionReaction) arms are unreachable in unit tests (same pattern as focusedDialogSelector.test.ts). Tests assert those arms not-invoked; production build:dev:full (flags on) covers them.

Gates (all pass)

Gate Result
bun run typecheck 0 errors
bun test src/__tests__/ 865 pass / 0 fail
bunx biome check (new files) clean
bun run build:dev pass

LOC

REPL 6468 → 6455 (−13). Cumulative across 15 slices: −641.

byte-identical

  • useCallback deps array unchanged verbatim → closure identity preserved.
  • Helper body is the inlined body lifted verbatim → behavior identical.
  • feature() branches untouched → same DCE behavior per build config.

Co-Authored-By: Claude Fable 5 [email protected]

)

Extract the composedOnScroll scroll-routing logic from REPL.tsx into a
pure helper src/utils/composedOnScroll.ts (applyComposedOnScroll). No
React hooks, no JSX, no await — only side effects are mutating
lastUserScrollTsRef.current and dispatching to 4 callbacks/setters,
byte-identical to the inlined useCallback body.

REPL keeps a thin useCallback wrapper whose deps array
[onRepin, onScrollAway, maybeLoadOlder, setAppState] is unchanged
verbatim (feature() is a bun:bundle build-time DCE macro, not a runtime
dep). Downstream reads the same const name.

Tests (src/__tests__/utils/composedOnScroll.test.ts, 5 cases) cover the
non-feature paths: timestamp write, sticky->onRepin, non-sticky->
onScrollAway(handle). KAIROS/BUDDY arms are DCE-off under bun test (no
flag) and asserted not-invoked; production build:dev:full covers them.

Gates: typecheck 0 / 865 tests / biome clean / build:dev pass.
REPL 6468 -> 6455 (-13). Cumulative across 15 slices: -641.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 05dcd3b into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit/repl-split-slice15-composedonscroll branch August 28, 2026 14:10
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