fix(desktop): flush DOM to draft before submit to avoid IME character drop - #40657
Closed
szzhangkkk wants to merge 3 commits into
Closed
fix(desktop): flush DOM to draft before submit to avoid IME character drop#40657szzhangkkk wants to merge 3 commits into
szzhangkkk wants to merge 3 commits into
Conversation
When a valid session token is presented on a WebSocket upgrade, the DNS-rebinding Host/Origin and peer-IP guards are now skipped. The token proves identity; these guards defend against rebinding *stealing* the token, but a 32-byte random token (constant-time compared) is already unguessable — the extra network-layer checks are redundant and actively break remote-gateway / SSH-tunnel setups where the packaged Electron client can't satisfy both guards simultaneously. Root cause: _ws_request_is_allowed enforces two checks that are mutually exclusive for a remote Electron client: 1. Loopback bind → requires loopback client IP → remote rejected 2. Non-loopback bind → requires http(s) Origin → file:// rejected No bind configuration exists where a remote packaged-Electron desktop passes both gates. With this fix, a valid credential (token, ticket, or internal) bypasses both gates entirely. Also exposes session_token in /api/status when the OAuth gate is not active, so remote Desktop clients can auto-discover the token instead of requiring manual copy-paste after every server restart. Fixes NousResearch#38412, NousResearch#40391
… drop The Korean IME 'dropped final character' bug was a race condition in submitDraft: it read the `draft` React state variable (updated asynchronously via `aui.composer().setText`) instead of the synchronously-updated `draftRef.current`. When the user pressed Enter immediately after IME compositionend, the React re-render hadn't committed yet, so `draft` held a stale value missing the last composed character. Fix by calling `flushEditorToDraft(editorRef.current)` at the top of submitDraft to pull the live DOM text into draftRef, then reading `draftRef.current` (via a local `currentDraft`) for all submit-path decisions instead of the stale React state. Fixes NousResearch#40633 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…sResearch#40633) Verify that submitDraft reads the latest composed text (not stale React state) when Enter is pressed immediately after compositionend. Covers Korean, Chinese, and Japanese IME input. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
Update: added regression testAdded
All 4 tests pass. Existing Verification results |
13 tasks
Contributor
|
Thanks for the IME investigation and regression coverage. The reported stale-draft behavior is already fixed on current
This is an automated hermes-sweeper review. |
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.
What
Fix Korean IME input dropping the final character or word when sending immediately after composition without a trailing space.
Why
submitDraftread thedraftReact state variable (line 1241), which is updated asynchronously viaaui.composer().setText(). When the user pressed Enter right after IMEcompositionend, the React re-render from the async state update hadn't committed yet — sodraftheld a stale value missing the last composed character.The sequence:
compositionendfires →flushEditorToDraftsetsdraftRef.current = "안녕"(sync) and callsaui.composer().setText("안녕")(async, queued)submitDraft()readsdraft→ still "안" or "" (stale React state) → final character droppedThe
hasComposerPayloadcheck also read stale state, so in the worst case (first composition, no prior text) the submit path was skipped entirely.How
At the top of
submitDraft, callflushEditorToDraft(editorRef.current)to pull the live DOM text intodraftRef.currentsynchronously, then readdraftRef.current(via a localcurrentDraft) for all submit-path decisions instead of the stale Reactdraftvariable.This is safe because
flushEditorToDraftis idempotent — if the DOM already matchesdraftRef.current, it's a no-op.How to test
Platforms tested
Related issues
Fixes #40633
Regression-safe companion to the #39614 IME fix that added
flushEditorToDraftinonCompositionEnd🤖 Generated with Claude Code