Skip to content

refactor(review): give App.tsx one copy of each duplicated submit helper - #352

Merged
nownabe merged 1 commit into
mainfrom
refactor/300-app-dedup
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
refactor/300-app-dedup

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

App.tsx held the same logic two or three times, so a rule change (a baseSha
fallback, a parentLocalId lookup) had to be made in every copy. This gives each
one a single home.

Folding the FileEdit sync into one helper also removed a latent race, see
"Behaviour change" below.

What

Re-audited issue #300's six items against current main; three were already
resolved by earlier PRs and are untouched here:

# Item Status
1 "drafts → Repository" loop in submitReview vs submitAuthor already resolved — #351 (issue #282) deleted submitAuthor's loop; only submitReview still has one
2 FileEdits sync (mirror effect vs submitAuthor) done — #341 (issue #278) had unified the building via fileEditsFromEdits; the upsert/discard loop was still duplicated, now syncFileEditsToRepository()
3 parentLocalId resolution (addReply, submitReview) done — one parentLocalIdFor(thread)
4 "Drop accepted decisions" (two in-memory copies + clearAcceptedDecisions) done — useDismissedSuggestions.clearAccepted(ids); the setDismissed escape hatch it existed for is gone from the hook's API
5 resetSuggestionEdits(); saveSuggestionEdits(ref, {}) in discardAllPending done — await discardAllPersistedEdits(); saveSuggestionEdits is no longer imported by App.tsx
6 jumpTo vs jumpToOffsets already resolved — #348 (issue #283) folded jumpTo into jumpToCid → jumpToOffsets

Net line change: −30 lines in App.tsx (49 added / 79 removed); −15 lines
of production code overall
(App.tsx + the two hook files), +37 lines of test.

Behaviour change (one, deliberate)

syncFileEditsToRepository skips a FileEdit whose current state is past
"draft". submitAuthor used to upsert unconditionally, and that redundant
write was the only thing keeping the mirror effect from re-running during
submitDrafts(), seeing the FileEdit as "syncing" and writing it back as a
"draft" — cancelling the commit it belonged to. Without the guard, both
tests/AppSubmitFailure.test.tsx author-submit tests fail (no commit call at
all, so the accepted thread is never resolved); with it they pass. Everything
else is pure extraction.

Red-test evidence

New hook test, tests/useDismissedSuggestions.test.tsx →
useDismissedSuggestions — clearAccepted, written before the implementation:

TypeError: result.current.clearAccepted is not a function.
  (In 'result.current.clearAccepted([1])', 'result.current.clearAccepted' is undefined)
(fail) useDismissedSuggestions — clearAccepted > drops only the named ids and purges them from storage
(fail) useDismissedSuggestions — clearAccepted > without a ref: updates state, does NOT touch storage
 5 pass  2 fail

The existing App-level suites (AppSubmitFailure, AppEditedCoordinates,
AppPrRef, AppRejectSuggestion) are the safety net for the extraction itself
and stay green.

Checks

bun run test 818 pass / 0 fail (64 files) · check:lint · check:format ·
typecheck · build — all clean.

Closes #300

The FileEdit mirror, the parentLocalId resolution and the accepted-decision purge each existed two or three times, so a rule change had to be made in every copy. Folding them into one helper each also removed a latent race: the mirror effect used to rewrite a FileEdit already flipped to syncing back into a draft, cancelling the commit it belonged to.
@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe merged commit 852c57a into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the refactor/300-app-dedup branch September 20, 2026 10:34
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.

[Refactor] De-duplicate App.tsx submit, FileEdit sync, accepted-purge and jump helpers

1 participant