fix: make proxy subscribe() synchronous to fix IME composition#56
Merged
Conversation
Proxy notifications batched via microtask (Promise.resolve().then()) arrive after React re-renders, causing IME composition (Korean, Japanese, Chinese) to break in controlled inputs bound to comwit state. useModelInput() maintains a local state buffer that updates synchronously on onChange, while pausing proxy→local sync during IME composition (compositionstart/compositionend). This preserves the microtask batching optimization for all other subscribers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Replace the useModelInput() workaround with a proper fix at the proxy level. The subscribe() function now accepts a notifyInSync flag that skips microtask batching and fires callbacks synchronously. StoreEntry.subscribe (the React/useSyncExternalStore path) uses sync mode so React sees state changes immediately in the same event loop tick. React 18 already batches state updates, making the microtask batching redundant for React subscribers. This matches how zustand (always sync) and valtio (sync opt-in) handle the same problem. Vanilla subscribers still use the default microtask batching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
No need for a conditional — just make subscribe() always synchronous like zustand does. React 18 batches renders itself, and persist.ts already wraps its callback with debounce(). The microtask layer was redundant for all current subscribers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
subscribe()에서 microtask 배칭(Promise.resolve().then()) 제거, 동기 콜백으로 변경useModel을 그대로 쓰면 한글/일본어/중국어 IME가 정상 동작변경 전
변경 후
변경 파일
proxy.ts:subscribe()— microtask 배칭 제거, 동기 콜백model.ts: 3번째 인자 제거 (불필요)proxy.test.ts: 배칭 테스트 → 동기 호출 테스트로 변경Test plan
🤖 Generated with Claude Code