Skip to content

An AI-powered search engine with a generative UI

fix(chat): shorten post-composition Enter debounce (#849)

Eliauk82cb07c9cfb4
diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx
index 6c359f38..ca0b789b 100644
--- a/components/chat-panel.tsx
+++ b/components/chat-panel.tsx
@@ -91,10 +91,14 @@ export function ChatPanel({
const handleCompositionEnd = () => {
setIsComposing(false)
+ // Brief debounce — the candidate-confirm Enter that fires
+ // immediately after compositionend may otherwise be treated as a
+ // submit. 50ms is enough to swallow that synchronous event but
+ // short enough not to drop a real "finish typing, press Enter".
setEnterDisabled(true)
setTimeout(() => {
setEnterDisabled(false)
- }, 300)
+ }, 50)
}
const handleNewChat = useCallback(() => {
@@ -270,17 +274,20 @@ export function ChatPanel({
className="resize-none w-full min-h-12 bg-transparent border-0 p-3 md:p-4 text-sm placeholder:text-muted-foreground focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"
onChange={handleInputChange}
onKeyDown={e => {
- if (e.key !== 'Enter' || isComposing || enterDisabled) {
+ // e.nativeEvent.isComposing stays true on the keydown that
+ // confirms an IME candidate, even after React-level
+ // isComposing has flipped.
+ if (
+ e.key !== 'Enter' ||
+ isComposing ||
+ (e.nativeEvent as KeyboardEvent).isComposing ||
+ enterDisabled
+ ) {
return
}
// Plain Enter (no modifiers) → submit
- if (
- !e.shiftKey &&
- !e.altKey &&
- !e.metaKey &&
- !e.ctrlKey
- ) {
+ if (!e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey) {
if (input.trim().length === 0) {
e.preventDefault()
return
diff --git a/components/user-text-section.tsx b/components/user-text-section.tsx
index 42da1df2..1eb2a480 100644
--- a/components/user-text-section.tsx
+++ b/components/user-text-section.tsx
@@ -86,12 +86,15 @@ export const UserTextSection: React.FC<UserTextSectionProps> = ({
// Any modifier (Shift / Alt / Meta / Ctrl) + Enter → let it insert a
// newline instead of submitting the edit.
+ // nativeEvent.isComposing catches the IME candidate-confirm Enter even
+ // after React-level isComposing has flipped.
if (
event.shiftKey ||
event.altKey ||
event.metaKey ||
event.ctrlKey ||
isComposing ||
+ (event.nativeEvent as KeyboardEvent).isComposing ||
enterDisabled
) {
// Alt+Enter on macOS does not insert \n by default; do it manually.
@@ -127,7 +130,7 @@ export const UserTextSection: React.FC<UserTextSectionProps> = ({
enterResetTimeoutRef.current = setTimeout(() => {
setEnterDisabled(false)
enterResetTimeoutRef.current = null
- }, 300)
+ }, 50)
}
return (