Skip to content

Commit bc45ddb

Browse files
Update usePromptEnhancer hook
1 parent dc9310c commit bc45ddb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

app/lib/hooks/usePromptEnhancer.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,35 @@ export function usePromptEnhancer() {
5151
try {
5252
setInput('');
5353

54+
let rafId: number | null = null;
55+
let pendingUpdate = false;
56+
57+
const updateInput = () => {
58+
setInput(_input);
59+
pendingUpdate = false;
60+
rafId = null;
61+
};
62+
5463
while (true) {
5564
const { value, done } = await reader.read();
5665

5766
if (done) {
67+
if (rafId) {
68+
cancelAnimationFrame(rafId);
69+
}
70+
71+
setInput(_input);
5872
break;
5973
}
6074

6175
_input += decoder.decode(value);
6276

6377
logger.trace('Set input', _input);
6478

65-
setInput(_input);
79+
if (!pendingUpdate) {
80+
pendingUpdate = true;
81+
rafId = requestAnimationFrame(updateInput);
82+
}
6683
}
6784
} catch (error) {
6885
_error = error;

0 commit comments

Comments
 (0)