-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(cli): yield to React after addItem to reduce input lag #6059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7c50e1d
6389b39
787465d
d5d9a78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1036,6 +1036,18 @@ export const useGeminiStream = ( | |||||||||||
| id: insertedId, | ||||||||||||
| text: trimmedQuery, | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| // Yield via macrotask to let Ink/React flush the user message | ||||||||||||
| // render before continuing with @-command processing and API | ||||||||||||
| // call. React 19.2.4 (Ink 7.0.3) schedules renders via | ||||||||||||
| // MessageChannel.postMessage (a macrotask), so a microtask yield | ||||||||||||
| // (await Promise.resolve()) does NOT give React a chance to | ||||||||||||
| // render — the continuation runs first. setImmediate fires in | ||||||||||||
| // the check phase after I/O events (where MessageChannel | ||||||||||||
| // delivers its postMessage), guaranteeing React renders first | ||||||||||||
| // without the ~1ms timer overhead of setTimeout(0). | ||||||||||||
| // Only needed for non-Cron submissions since Cron skips addItem(). | ||||||||||||
| await new Promise((r) => setImmediate(r)); | ||||||||||||
| } | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The
Suggested change
— qwen3.7-max via Qwen Code /review |
||||||||||||
|
|
||||||||||||
| // Handle @-commands (which might involve tool calls) | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] No regression test asserts that the yield is a macrotask (not a microtask). All 9 updated tests flush via
vi.advanceTimersByTimeAsync(0)and then assertsendMessageStream.toHaveBeenCalledTimes(1)— but if someone replacessetImmediatewithPromise.resolve()(or removes the yield entirely), the twoawait Promise.resolve()lines already present would flush the microtask, and all assertions still pass. The input lag silently returns with no test failure.Consider adding a test that asserts the ordering invariant:
This guards against the yield being weakened to a microtask in the future.
— qwen3.7-max via Qwen Code /review