Skip to content

fix(settings): persist the last IME syllable when leaving the display-name field mid-composition - #9517

Merged
nwparker merged 1 commit into
stablyai:mainfrom
dogfooter8750:fix/settings-display-name-ime-last-char
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
dogfooter8750:fix/settings-display-name-ime-last-char

Conversation

@dogfooter8750

@dogfooter8750 dogfooter8750 commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

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

RepoSettingsDraftInput intentionally holds keystrokes in local draft state and defers persistence until compositionend, because writing pre-confirmation text mid-composition cancels the IME session. But if the field blurs or unmounts before compositionend fires (navigating out of settings), that last syllable lived only in draft and 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.

  • Test file RepositoryPaneDraftInput.test.tsx passes on the branch: Tests 14 passed (14).
  • Reverting only the fix file to origin/main (keeping the test) makes 2 tests fail, proving the tests capture the bug: Tests 2 failed | 12 passed (14).
  • Failing assertions when fix reverted:
 "flushes an abandoned IME composition on blur"
   AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times (line 245)
 "flushes an abandoned IME composition when the field unmounts"
   AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times (line 261)
  • Lint clean: oxlint on 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 lastPersistedRef and a repoId check, 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 (normal compositionend, 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.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

RepositorySettingsDraftInput 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, root cause, evidence, and risks, but it omits required template sections like Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections, especially explicit Testing checkboxes, a cross-platform AI review report, a security audit, screenshots or a no-visual-change note, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the bug fix for IME text persistence on blur/unmount mid-composition.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Extract ref mutations from the pure state updater function.

State updater functions passed to setDraft must be pure. Mutating refs (pendingStoreEchoesRef, skipNextChangeRef, and the newly added lastPersistedRef) inside the updater violates React's concurrency rules and causes critical bugs in Strict Mode (which invokes updaters twice).

During the first invocation, splice mutates the array; the second invocation then fails the indexOf check, falls through to the fallback branch, and incorrectly overwrites the active user draft with storeValue.

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.tsx
  • src/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]>
@nwparker
nwparker force-pushed the fix/settings-display-name-ime-last-char branch from 848c10d to b60f346 Compare July 23, 2026 11:49
@nwparker
nwparker merged commit a90ec54 into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

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 main, reviewed, and merged. Really appreciate it! 🙏

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…-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]>
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.

3 participants