Skip to content

Commit 77fcc12

Browse files
committed
feat: optimize perf and fix composing type
1 parent 3d31beb commit 77fcc12

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/bubble.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,11 @@ export function BubbleList({
272272
const scrollContainer = useCallback((smooth?: boolean) => {
273273
if (pauseScroll.current) return;
274274

275-
containerRef.current?.scrollTo({
276-
top: containerRef.current?.scrollHeight,
277-
behavior: smooth === false ? "instant" : "smooth",
275+
requestAnimationFrame(() => {
276+
containerRef.current?.scrollTo({
277+
top: containerRef.current?.scrollHeight,
278+
behavior: smooth ? "smooth" : "instant",
279+
});
278280
});
279281
}, []);
280282

src/sender.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,23 @@ export function Sender({
157157
}, [isSending, message, onSend, controller, input]);
158158
const handleKeyDown = useCallback(
159159
(event: React.KeyboardEvent<HTMLTextAreaElement>) => {
160-
if (event.key === "Enter" && !event.shiftKey) {
160+
if (
161+
event.key === "Enter" &&
162+
!event.shiftKey &&
163+
!event.nativeEvent.isComposing
164+
) {
161165
event.preventDefault();
162166
handleSend();
163167
}
164168
},
165169
[handleSend],
166170
);
171+
const handleChange = useCallback(
172+
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
173+
setMessage(e.target.value);
174+
},
175+
[],
176+
);
167177

168178
return (
169179
<div
@@ -179,7 +189,7 @@ export function Sender({
179189
<textarea
180190
ref={textareaRef}
181191
value={message}
182-
onChange={(e) => setMessage(e.target.value)}
192+
onChange={handleChange}
183193
onKeyDown={handleKeyDown}
184194
placeholder={placeholder}
185195
className="w-full pt-4 px-4 border-0 rounded-2xl resize-none focus:ring-0 focus:outline-none text-gray-700 placeholder-gray-400"

0 commit comments

Comments
 (0)