fix(cli-kit): batch large output chunks to prevent event loop blocking#7008
Draft
alfonso-noriega wants to merge 1 commit intomainfrom
Draft
fix(cli-kit): batch large output chunks to prevent event loop blocking#7008alfonso-noriega wants to merge 1 commit intomainfrom
alfonso-noriega wants to merge 1 commit intomainfrom
Conversation
When a POS UI extension throws a large stack trace (3MB+), all lines arrive as a single write to ConcurrentOutput's Writable stream. The synchronous stripAnsi + split + React state update causes a long render cycle that blocks the Node.js event loop, making keyboard shortcuts (q, p) unresponsive. Fix: split chunks exceeding 100 lines into batches and schedule each via setImmediate, yielding to the event loop between renders so Ink's useInput hook can process keypresses between batches. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Coverage report
Test suite run success3807 tests passing in 1462 suites. Report generated by 🧪jest coverage report action from 585b600 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a POS UI extension throws a large stack trace (3MB+), the entire output arrives as a single
write()call toConcurrentOutput'sWritablestream. The synchronous processing —stripAnsi(),split(/\n/), andsetProcessOutputwith a spread of the full accumulated array — causes a render cycle expensive enough to block the Node.js event loop for several seconds. During that time, Ink'suseInputhook cannot process keypresses, soq(quit) andp(preview) become unresponsive.Reported via Dev Support: a developer building POS UI Extensions observed the CLI freezing on large stack traces during
shopify app dev.Fix
In
ConcurrentOutput.tsx, thewritableStreamwrite handler now splits chunks exceedingMAX_LINES_PER_BATCH(100) lines into smaller batches. Each batch is scheduled viasetImmediate, yielding to the event loop between renders so Ink's input handling can run between batches.next()called synchronouslysetImmediatebetween each,next()deferred until all batches are queued (backpressure preserved)Test
Added a test that writes 250 lines as a single chunk and asserts all lines appear in the rendered output.
Checklist
🤖 Generated with Claude Code