Repository navigation
Keep Terminal logs in order with other stdout/stderr output - #2162
Conversation
Summary: In interactive mode, `Terminal.log()` queued lines and wrote them with the next status update. When an update was already in flight, the line was written up to ~33ms later, after any `console.log`, `console.error` or other direct writes made in the meantime, so output appeared out of order. - `log()` writes the line immediately: it discards the written status (erasing it unless other output followed it), writes the line, then schedules the status redraw. Status redraws remain throttled, so a burst of logs redraws the status once. - `persistStatus()` clears the pending status before logging it, so the redraw doesn't draw it again. - Status updates call `readline.moveCursor`, `readline.clearScreenDown` and `stream.write` directly instead of `promisify` wrappers. An update resolves on its last write's callback, as writes to a stream complete in order. Write errors no longer reject `flush()` / `waitForUpdates()`. - Private members are renamed for clarity (e.g. `#nextStatusStr` -> `#status`, `#statusStr` -> `#writtenStatus`). The public API is unchanged. Changelog: [Fix] Keep `Terminal.log()` output in order with other stdout/stderr output Test Plan: - New test "keeps logs in order with output written outside of Terminal" fails before this change and passes after. - `yarn jest packages/metro-core packages/metro/src/lib` - `yarn flow check`, `yarn eslint packages/metro-core/src`
Metro review: Looks goodRisk: low · Commit:
No findings. Verified
Not run: No real terminal: pty allocation failed in the sandbox, so sequences were checked on a fake TTY with real Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
robhogan
left a comment
There was a problem hiding this comment.
I wanted to make sure this isn't isn't perf regressing (especially for main thread dominated builds) since stdout can be sneaky like that - but it looks fine:
Cheers! |
Summary
In interactive mode,
Terminal.log()queued lines and wrote them with the next status update. When an update was already in flight, the line was written up to ~33ms later, after anyconsole.log,console.erroror other direct writes made in the meantime, so output appeared out of order.log()writes the line immediately: it discards the written status (erasing it unless other output followed it), writes the line, then schedules the status redraw. Status redraws remain throttled, so a burst of logs redraws the status once.persistStatus()clears the pending status before logging it, so the redraw doesn't draw it again.readline.moveCursor,readline.clearScreenDownandstream.writedirectly instead ofpromisifywrappers. An update resolves on its last write's callback, as writes to a stream complete in order. Write errors no longer rejectflush()/waitForUpdates().#nextStatusStr->#status,#statusStr->#writtenStatus). The public API is unchanged.Changelog: [Fix] Keep
Terminal.log()output in order with other stdout/stderr outputTest plan
yarn jest packages/metro-core packages/metro/src/libyarn flow check,yarn eslint packages/metro-core/src