#1107·hunk

Resizing a review can emit MaxListenersExceededWarning and corrupt the display

Author: jeieaCreated Sep 16, 2026Updated Sep 17, 2026
Labelsbug

What happened?

Resizing a Hunk review can print the following warning over the bottom of the alternate-screen UI:

(node:<pid>) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 blur listeners added to [CliRenderer]. MaxListeners is 10.

The warning text becomes interleaved with the UI, and subsequent output is incomplete or incorrectly drawn.

GPT Diagnosis

Each mounted DiffSectionBody registers a blur listener on the shared renderer and removes it on unmount. Once 11 file bodies are mounted, this exceeds the EventEmitter default warning threshold of 10. Node's EventEmitter documentation notes that this is a warning threshold rather than a hard limit. Since Hunk does remove the listeners on unmount, this may be intentional listener fan-out rather than a retained memory leak.

A width change also remounts the diff content using a key that includes width, which makes resizing the visible trigger.

The (node:<pid>) ... line is the runtime's default warning output to stderr. Hunk/OpenTUI renders the alternate screen through stdout, while both streams target the same terminal. The warning therefore bypasses OpenTUI's framebuffer, writes at the current cursor position, and moves the cursor without the renderer knowing. Since subsequent frames may update only changed cells, overwritten or stale cells can remain until a full repaint.

OpenTUI also forwards process warnings to console.warn, but openConsoleOnError opens the console only through the error handler. It therefore does not prevent the runtime warning from interfering with the active terminal screen.

Steps to reproduce

  1. Open a review containing enough small changed files for at least 11 file sections to be mounted.
  2. Resize the terminal or multiplexer pane horizontally.
  3. Observe the warning at the bottom of the UI and incorrect subsequent rendering.

Expected behavior

Resizing should redraw the review without emitting a listener warning or corrupting the display. Ideally, terminal blur handling would use one renderer-level listener rather than one listener per mounted file body.

Version

Hunk 0.22.0, source commit ee556ac841c1b5a872b80f247816a71e8104605f (Nix installation).