Repository navigation
refactor(review): give App.tsx one copy of each duplicated submit helper - #352
Merged
Merged
Conversation
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.
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.
Why
App.tsxheld the same logic two or three times, so a rule change (abaseShafallback, a
parentLocalIdlookup) had to be made in every copy. This gives eachone 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 alreadyresolved by earlier PRs and are untouched here:
submitReviewvssubmitAuthorsubmitAuthor's loop; onlysubmitReviewstill has onesubmitAuthor)fileEditsFromEdits; the upsert/discard loop was still duplicated, nowsyncFileEditsToRepository()parentLocalIdresolution (addReply,submitReview)parentLocalIdFor(thread)clearAcceptedDecisions)useDismissedSuggestions.clearAccepted(ids); thesetDismissedescape hatch it existed for is gone from the hook's APIresetSuggestionEdits(); saveSuggestionEdits(ref, {})indiscardAllPendingawait discardAllPersistedEdits();saveSuggestionEditsis no longer imported byApp.tsxjumpTovsjumpToOffsetsjumpTointojumpToCid→jumpToOffsetsNet line change: −30 lines in
App.tsx(49 added / 79 removed); −15 linesof production code overall (
App.tsx+ the two hook files), +37 lines of test.Behaviour change (one, deliberate)
syncFileEditsToRepositoryskips a FileEdit whose current state is past"draft".submitAuthorused to upsert unconditionally, and that redundantwrite 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, bothtests/AppSubmitFailure.test.tsxauthor-submit tests fail (nocommitcall atall, 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:The existing App-level suites (
AppSubmitFailure,AppEditedCoordinates,AppPrRef,AppRejectSuggestion) are the safety net for the extraction itselfand stay green.
Checks
bun run test818 pass / 0 fail (64 files) ·check:lint·check:format·typecheck·build— all clean.Closes #300