Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(react): prevent Enter from sending message during IME composition#3322

Open
zhangxinping666 wants to merge 1 commit intoCopilotKit:mainfrom
zhangxinping666:fix/3318-ime-composition-enter
Open

fix(react): prevent Enter from sending message during IME composition#3322
zhangxinping666 wants to merge 1 commit intoCopilotKit:mainfrom
zhangxinping666:fix/3318-ime-composition-enter

Conversation

@zhangxinping666
Copy link

Summary

Fixes #3318

CopilotChatInput (v2) does not handle IME composition events. When typing Chinese/Japanese/Korean characters, pressing Enter to commit the composition sends the message prematurely instead of finalizing the characters.

Changes

  • Added isComposingRef to track IME composition state
  • Added onCompositionStart/onCompositionEnd handlers on the textarea
  • Guarded both the slash command Enter and message send Enter with composition checks
  • Handles Firefox timing edge case (compositionend fires before keydown) via setTimeout(0)
  • Added e.nativeEvent.isComposing as defense-in-depth browser fallback

Prior Art

  • v1 React implementation already handles this correctly (packages/v1/react-ui/src/components/chat/Input.tsx)
  • Angular v2 example also handles this (examples/v2/angular/demo/.../custom-chat-input.component.ts)

Test Plan

  • Added unit tests for IME composition scenarios (5 new tests)
  • Verified Enter during composition does NOT send message
  • Verified Enter after composition ends sends message normally
  • Verified slash command not triggered during composition
  • Verified send button still works during composition
  • Verified Firefox compositionend-before-keydown timing handled correctly
  • All 43 tests passing

@changeset-bot
Copy link

changeset-bot bot commented Mar 1, 2026

🦋 Changeset detected

Latest commit: 466f94d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@copilotkitnext/react Patch
@copilotkit/react-core Patch
@copilotkitnext/next-pages-router Patch
@copilotkit/a2ui-renderer Patch
@copilotkit/react-textarea Patch
@copilotkit/react-ui Patch
@copilotkit/runtime-client-gql Patch
@copilotkit/runtime Patch
@copilotkit/sdk-js Patch
@copilotkit/shared Patch
@copilotkit/voice Patch
@copilotkitnext/agent Patch
@copilotkitnext/angular Patch
@copilotkitnext/core Patch
@copilotkitnext/demo-agents Patch
@copilotkitnext/eslint-config Patch
@copilotkitnext/runtime Patch
@copilotkitnext/shared Patch
@copilotkitnext/sqlite-runner Patch
@copilotkitnext/typescript-config Patch
@copilotkitnext/web-inspector Patch
@copilotkitnext/node-express Patch
@copilotkit-storybook/angular Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Mar 1, 2026

@zhangxinping666 is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

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.

🐛 Bug: Input gets cleared when typing with IME on mobile devices(v2)

1 participant