Repository navigation
fix(terminal): detach the Korean input-source probe when its setting goes off - #13283
Conversation
…goes off Gating the prefetch call site stopped the probe from ever attaching, but not from surviving. prefetchKoreanInputSource installs global focus/keydown/keyup listeners behind an idempotent listenerAttached guard, and the only teardown was test-only — so disabling the setting mid-session left the listeners live and still spawning defaults export | plutil | plutil on keyboard activity. Syncs in the effect body rather than its cleanup: cleanup also runs on tab switches and on any dep-identity change, so disposing there would detach and re-probe constantly. Also replaces the initial-probe abort guard with an epoch. It compared window identity, which is dead code in production where window is a singleton, so a stop/start could let a sleeping probe loop wake and race the new one. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughKorean input-source prefetching now has an explicit stop function. A prefetch epoch invalidates stale initial-probe loops and refreshes. The keyboard handler stops prefetching when the Korean Won conversion setting is disabled. Tests mock the stop function, reset it between cases, and verify that disabled settings dispose the probe without starting prefetch. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsx (1)
78-85: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winTest the setting transition, not only the initial disabled state.
deps(false)mounts withisActive: trueat Line 27 and the setting already disabled. It does not attach a probe before calling the disposer, so it cannot verify teardown when the setting changes or when the hook becomes inactive.Parameterize
isActive, render with the setting enabled first, then rerender with the setting disabled. Assert the disposer call and the absence of a new prefetch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7a2f30e4-2401-42ab-b3e8-696dcd8bd0ef
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/keyboard-handlers-korean-prefetch-gate.test.tsxsrc/renderer/src/components/terminal-pane/keyboard-handlers.tssrc/renderer/src/lib/keyboard-layout/korean-input-source.ts
| // Synced in the effect body, not its cleanup: cleanup also runs on tab switches and on any | ||
| // dep-identity change, so disposing there would reattach and re-probe constantly. | ||
| if (koreanWonToBackquoteEnabled) { | ||
| prefetchKoreanInputSource() | ||
| } else { | ||
| stopKoreanInputSourcePrefetch() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Handle the disabled-setting transition when the hook is inactive.
useEffect returns at Lines 274-276 before it reaches this disposer branch. If this hook starts the module-global probe and then becomes inactive before koreanWonToBackquoteEnabled changes to false, the disposer is never called. The global listeners and pending probe can continue after the setting is disabled.
Move disabled-state synchronization into an effect that is not gated by isActive, or guarantee that another active hook always observes the transition.
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (#13283)" This reverts commit 5a84dbb. * Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (#13182)" This reverts commit 4349599. * Revert "perf(terminal): gate the Korean input-source probe on its setting (#13181)" This reverts commit 42fc537. * Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (#13104)" This reverts commit 2400393.
…goes off (stablyai#13283) Gating the prefetch call site stopped the probe from ever attaching, but not from surviving. prefetchKoreanInputSource installs global focus/keydown/keyup listeners behind an idempotent listenerAttached guard, and the only teardown was test-only — so disabling the setting mid-session left the listeners live and still spawning defaults export | plutil | plutil on keyboard activity. Syncs in the effect body rather than its cleanup: cleanup also runs on tab switches and on any dep-identity change, so disposing there would detach and re-probe constantly. Also replaces the initial-probe abort guard with an epoch. It compared window identity, which is dead code in production where window is a singleton, so a stop/start could let a sleeping probe loop wake and race the new one. Co-authored-by: Orca <[email protected]>
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (stablyai#13283)" This reverts commit 4b8d3e9. * Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (stablyai#13182)" This reverts commit d7061e0. * Revert "perf(terminal): gate the Korean input-source probe on its setting (stablyai#13181)" This reverts commit 0712e9a. * Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (stablyai#13104)" This reverts commit eee48f8.
Two defects in the Korean input-source probe, both found by review of my own earlier changes. Independent of the IME revert (#13282) — this touches only the Won-key feature's probe, which stayed on main.
1. The probe outlived its setting. #13181 gated the call site so the probe never attaches when
terminalKoreanWonToBackquoteis off. ButprefetchKoreanInputSourceinstalls globalfocus/keydown/keyuplisteners behind an idempotentlistenerAttachedguard, and its only teardown was test-only. So switching the setting off mid-session left the listeners live and still spawningdefaults export | plutil | plutil— four processes — on keyboard activity. Confirmed empirically rather than by reading: a test that enables, disables, then dispatches aLang1keydown saw the reader called again after the setting was off.Adds a real disposer and calls it from the effect body, not its cleanup. Cleanup also runs on tab switches and on any dep-identity change, so disposing there would detach and re-probe constantly — a worse regression than the leak. Body-side sync is naturally idempotent.
No reference counting: only the active tab's effect ever prefetches, so a refcount would be machinery with no second owner to count.
2. The initial-probe abort guard was dead code in production. It compared
focusTarget !== target, but production always passes the samewindowsingleton, so the check could never fire. Harmless until a disposer exists — with one, a stop/start sequence lets the old sleeping probe loop wake, pass the guard, and race the new one, each bumpingrefreshGenerationand discarding the other's read. Replaced with an epoch counter.The existing tests missed this because
makeMockWindow()returns a fresh object per call, so the identity check is meaningful in tests and dead in the app.Verified: keyboard-layout + the gate test 6 files / 68 tests pass, typecheck clean across all three configs with
config/*.tsbuildinfocleared first. Rebased onto post-revert main.Made with Orca 🐋