Repository navigation
Conversation
Co-authored-by: bryan.fullam <bryan.fullam@consensys.net>
Co-authored-by: bryan.fullam <bryan.fullam@consensys.net>
🛑 Files requiring codeowner reviewTo merge this PR, you'll need to get approvals from the following owners. @MetaMask/swaps-engineers (3 files)
@MetaMask/core-platform (expand for more) |
Co-authored-by: bryan.fullam <bryan.fullam@consensys.net>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 61381c5. Configure here.
| this.#getShouldYieldAfterFirstQuote?.() | ||
| ) { | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
| } |
There was a problem hiding this comment.
Stale quotes written after yield
Medium Severity
After the first quote is written, the handler yields with setTimeout and then keeps processing the rest of the buffered burst with no abort check. A newer fetch that cancels this stream during that gap can still receive the remaining old quotes in state.quotes.
Reviewed by Cursor Bugbot for commit 61381c5. Configure here.


Explanation
On mid-tier Android, the first streamed quote reaches controller state well before it reaches the screen. The stream reader processes the rest of the buffered burst (parsing, validation, fees, and a state update for each quote, roughly 75–120ms each) back to back on the JS thread. The client's Redux flush and render only run once that work is done.
This PR adds an optional
getShouldYieldAfterFirstQuoteconstructor option. When it returnstrue, the quote stream handler awaits one macrotask (setTimeout(0)) right after the first valid quote is written to state, so the client can flush and render it before the rest of the burst is processed. It's a getter, likegetUseAssetsControllerForRates, so clients can A/B it behind a remote flag that's read at fetch time. When the option is omitted or returnsfalse, behavior is unchanged.Only the first valid quote of each stream triggers a yield, so it costs at most one task tick per fetch. Grouping later quote updates into fewer state writes is out of scope.
References
Checklist
Note
Low Risk
Opt-in constructor flag with a single macrotask pause on the first quote only; default behavior is unchanged when the option is not used.
Reviewed by Cursor Bugbot for commit 61381c5. Bugbot is set up for automated code reviews on this repo. Configure here.