Closes #4253
What Changed#
- Let trusted
insertReplacementText edits run through the browser's native editing path so accepted spelling corrections remain synchronized with Lexical.
- Patch Lexical 0.41's development and production bundles to reconcile text with minimal DOM mutations, preserving Blink spelling markers on untouched text.
- Enable spellcheck explicitly on the composer.
- On macOS desktop, fall back to
NSSpellChecker when Electron reports a misspelled word with no dictionary suggestions. Existing Electron suggestions remain the first choice on every platform.
- Refocus the editor after accepting a desktop spelling suggestion.
Why#
Lexical normally converts spelling corrections into controlled replacements and can rewrite the complete text node during reconciliation. Blink treats those script mutations differently from native editing: existing spelling markers can disappear, and the remaining text is not rechecked until another real keystroke.
Electron can also emit a context-menu event with a misspelledWord but an empty dictionarySuggestions array on macOS, even when the system spellchecker has useful candidates. For example, NSSpellChecker suggests texting, testing, toting, teeing, and tenting for teting.
This keeps native spelling state attached to the composer and recovers the operating system's suggestions when Chromium omits them.
UI Changes#
There is no layout or styling change. The interaction changes are:
- Before: accepting one correction could clear the other spelling underlines until the next keystroke.
- After: remaining underlines stay active and the edited text is rechecked immediately.
- Before: the macOS desktop context menu could show
No suggestions for a word the system checker can correct.
- After: the menu uses the system suggestions as a fallback.
TODO before marking ready for review: attach a short before/after recording of the native context-menu interaction.
Validation#
vp fmt --check on all changed source/config files
vp lint on all changed TypeScript/TSX files
vp run --filter @t3tools/web --filter @t3tools/desktop typecheck
vp test run src/components/ComposerPromptEditor.test.ts in apps/web
vp test run src/electron/ElectronSpelling.test.ts src/window/DesktopWindow.test.ts in apps/desktop (27 tests)
- Production web build
- Isolated web composer verification for spellcheck attributes, native replacement synchronization, and editor stability
- Electron desktop development build and startup on macOS
- Direct macOS
NSSpellChecker verification for the teting suggestion case
Checklist#
Note
Fix native spellcheck in the composer by recovering macOS suggestions and intercepting replacement events#
- Adds a
ComposerNativeSpellcheckReplacementPlugin in ComposerPromptEditor.tsx that intercepts beforeinput events of type insertReplacementText at capture phase and stops propagation, letting Blink handle replacements natively so spelling underlines are maintained.
- Introduces an
ElectronSpelling service in ElectronSpelling.ts that spawns osascript (JXA) to query NSSpellChecker on macOS, with a 250ms timeout and a cap of 10 unique suggestions.
- Reworks the
context-menu handler in DesktopWindow.ts to fetch platform suggestions asynchronously when Chromium provides none, shows only the most recent menu when requests overlap, and focuses webContents after accepting a suggestion.
- Patches
lexical@0.41.0 to always use diffComposedText in setTextContent, fixing spelling underline rescheduling in Blink.
- Risk: the
osascript subprocess adds up to 250ms latency to context-menu display on macOS when Chromium has no suggestions.
Macroscope summarized ada34a4.
Note
Medium Risk
Changes composer input event handling and desktop context-menu async behavior; macOS spawns short-lived osascript processes for spell lookups.
Overview
Fixes native spellcheck in the composer and on macOS desktop when Chromium omits suggestions.
Web composer: Adds ComposerNativeSpellcheckReplacementPlugin, which captures trusted insertReplacementText on the editor host so spelling corrections use the browser’s native editing path instead of Lexical’s controlled beforeinput handling—keeping Blink spell markers and immediate re-check. Enables spellCheck on the composer ContentEditable.
macOS desktop: Introduces ElectronSpelling, which queries NSSpellChecker via osascript (250ms timeout, capped suggestions) when Electron reports a misspelled word with empty dictionarySuggestions. The context menu is built asynchronously with request versioning so only the latest spelling menu opens; accepting a suggestion calls replaceMisspelling and refocuses the editor.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ada34a4df96d30bac576cebb7421f33b58501b32. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
959a856e-1dfc-40ac-93bf-a37338f2155dYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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