Repository navigation
fix(settings): persist the last IME syllable when leaving the display-name field mid-composition - #9517
Conversation
📝 WalkthroughWalkthroughRepositorySettingsDraftInput now flushes unpersisted draft text on blur and unmount, tracks the last persisted value, and forwards blur callbacks. Store synchronization updates persistence tracking when repository or value changes. Tests cover unconfirmed IME persistence on blur and unmount, confirmed-value deduplication, untouched drafts, and controlled unmount behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/settings/RepositorySettingsDraftInput.tsx (1)
48-75: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winExtract ref mutations from the pure state updater function.
State updater functions passed to
setDraftmust be pure. Mutating refs (pendingStoreEchoesRef,skipNextChangeRef, and the newly addedlastPersistedRef) inside the updater violates React's concurrency rules and causes critical bugs in Strict Mode (which invokes updaters twice).During the first invocation,
splicemutates the array; the second invocation then fails theindexOfcheck, falls through to the fallback branch, and incorrectly overwrites the active user draft withstoreValue.Move this synchronization logic out of the state updater by using a ref to read the current draft safely within the effect body.
🐛 Proposed fix to ensure pure state updates
- useEffect(() => { - setDraft((current) => { - if (current.repoId !== repoId) { - pendingStoreEchoesRef.current = [] - composingRef.current = false - skipNextChangeRef.current = null - lastPersistedRef.current = storeValue - return { repoId, text: storeValue } - } - if (storeValue === current.text) { - pendingStoreEchoesRef.current = [] - skipNextChangeRef.current = null - lastPersistedRef.current = storeValue - return current - } - const pendingEchoIndex = pendingStoreEchoesRef.current.indexOf(storeValue) - if (pendingEchoIndex !== -1) { - // Why: queued updateRepo calls can echo older input text after newer - // keystrokes; accepting that echo re-cancels active IME composition. - pendingStoreEchoesRef.current.splice(0, pendingEchoIndex + 1) - return current - } - pendingStoreEchoesRef.current = [] - skipNextChangeRef.current = null - lastPersistedRef.current = storeValue - return { repoId, text: storeValue } - }) - }, [repoId, storeValue]) + const draftRef = useRef(draft) + useEffect(() => { + draftRef.current = draft + }, [draft]) + + useEffect(() => { + const current = draftRef.current + if (current.repoId !== repoId) { + pendingStoreEchoesRef.current = [] + composingRef.current = false + skipNextChangeRef.current = null + lastPersistedRef.current = storeValue + setDraft({ repoId, text: storeValue }) + return + } + if (storeValue === current.text) { + pendingStoreEchoesRef.current = [] + skipNextChangeRef.current = null + lastPersistedRef.current = storeValue + return + } + const pendingEchoIndex = pendingStoreEchoesRef.current.indexOf(storeValue) + if (pendingEchoIndex !== -1) { + // Why: queued updateRepo calls can echo older input text after newer + // keystrokes; accepting that echo re-cancels active IME composition. + pendingStoreEchoesRef.current.splice(0, pendingEchoIndex + 1) + return + } + pendingStoreEchoesRef.current = [] + skipNextChangeRef.current = null + lastPersistedRef.current = storeValue + setDraft({ repoId, text: storeValue }) + }, [repoId, storeValue])
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 508915b2-f54b-4a29-be7c-f54a305ffcd8
📥 Commits
Reviewing files that changed from the base of the PR and between a02389c and 848c10df1b227641da249bb9aac392ab6c8be1c4.
📒 Files selected for processing (2)
src/renderer/src/components/settings/RepositoryPaneDraftInput.test.tsxsrc/renderer/src/components/settings/RepositorySettingsDraftInput.tsx
…-name field mid-composition RepoSettingsDraftInput holds unconfirmed IME text in local draft state and only persists on compositionend (so the async store echo cannot cancel the composition). If the user types a Hangul syllable and immediately navigates back out of project settings while it is still composing, no compositionend fires — the last syllable stays in the draft and never reaches the store, so the project's display name loses its final character. Users have to click back into the field or press Enter (both force compositionend) to make it stick. Flush the visible draft on blur and on unmount, guarded by lastPersistedRef so it is a no-op when a keystroke or compositionend already persisted that value. The flush closure is published from an effect (post-commit) so a discarded concurrent render cannot leave the cleanup pointing at uncommitted draft state. Adds blur / unmount / no-double-persist / no-op regression tests to the component's existing suite. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
848c10d to
b60f346
Compare
|
Thanks so much for this, @KimYoungHwan8750 — persist the last IME syllable when leaving the display-name field mid-composition. Verified (fail-on-main/pass-on-branch), rebased on latest |
…-name field mid-composition (stablyai#9517) RepoSettingsDraftInput holds unconfirmed IME text in local draft state and only persists on compositionend (so the async store echo cannot cancel the composition). If the user types a Hangul syllable and immediately navigates back out of project settings while it is still composing, no compositionend fires — the last syllable stays in the draft and never reaches the store, so the project's display name loses its final character. Users have to click back into the field or press Enter (both force compositionend) to make it stick. Flush the visible draft on blur and on unmount, guarded by lastPersistedRef so it is a no-op when a keystroke or compositionend already persisted that value. The flush closure is published from an effect (post-commit) so a discarded concurrent render cannot leave the cleanup pointing at uncommitted draft state. Adds blur / unmount / no-double-persist / no-op regression tests to the component's existing suite. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Fixes a data-loss bug where the last unconfirmed IME (e.g. Hangul) character of a project's Display Name was dropped if you navigated away from Settings mid-composition.
ELI5
If you were typing a Korean name and left the settings screen before the last letter was "locked in," that last letter silently disappeared from the saved name. Now it's kept.
Root cause & fix
RepoSettingsDraftInputintentionally holds keystrokes in localdraftstate and defers persistence untilcompositionend, because writing pre-confirmation text mid-composition cancels the IME session. But if the field blurs or unmounts beforecompositionendfires (navigating out of settings), that last syllable lived only indraftand never reached the store. The fix adds a guarded blur/unmount flush (flushRef+lastPersistedRef) that persists the visible draft, staying a no-op when the value was already committed.Evidence
Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.
RepositoryPaneDraftInput.test.tsxpasses on the branch: Tests 14 passed (14).origin/main(keeping the test) makes 2 tests fail, proving the tests capture the bug: Tests 2 failed | 12 passed (14).oxlinton the changed component exits 0 with no warnings/errors.Trade-offs
None — pure fix.
Regression risk
Zero-regression: only the abandoned-composition branch changes behavior. The flush is guarded by
lastPersistedRefand arepoIdcheck, so already-committed values are not re-persisted — covered by the "does not re-persist a confirmed value on blur or unmount" and "does not persist on blur or unmount when nothing was edited" tests. Non-affected paths (normalcompositionend, echo, repo-switch) are byte-identical and remain passing.Credit to original author @KimYoungHwan8750. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.