#1035·ink

Support column-level incremental updates to avoid rewriting unchanged regions

Author: Blackn-LCreated Sep 29, 2026Updated Sep 29, 2026

Proposal

Please consider an optional column-level / unchanged-prefix optimization for incremental rendering. Currently a change confined to the right-hand side of a row causes the unchanged left-hand side to be written again from column 1.

I understand that incrementalRendering is documented as changed-line rendering, so this is a feature/performance request, not a claim that the existing option violates its documented contract.

Environment

  • Ink 7.1.1, installed from the public npm package, without patches
  • React 19.2.4
  • Windows x64
  • Reproduced with both Node.js 22.22.0 and Bun 1.4.2
  • NODE_ENV=production, FORCE_COLOR=0

The reproducer captures Ink's real interactive output using a Node Writable with isTTY=true. It does not use debug mode, ink-testing-library, private Ink imports, application wrappers, or external terminal graphics. This verifies emitted terminal control sequences, not a particular terminal emulator's visual behavior.

Reproduce

In an empty directory, use this package.json and run npm install --ignore-scripts:

json
{
  "private": true,
  "type": "module",
  "dependencies": {
    "ink": "7.1.1",
    "react": "19.2.4"
  }
}

PowerShell environment used for the runs:

powershell
$env:NODE_ENV = "production"
$env:FORCE_COLOR = "0"

Save the following as line-update-repro.mjs:

javascript
import React, {useEffect, useState} from 'react';
import {Writable, PassThrough} from 'node:stream';
import {render, Box, Text} from 'ink';

const h = React.createElement;
const writes = [];
const stdout = new Writable({
  write(chunk, _encoding, done) {
    writes.push(chunk.toString());
    done();
  },
});
Object.assign(stdout, {isTTY: true, columns: 60, rows: 24});
let advance;

function Counter() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    advance = () => setCount(value => value + 1);
    return () => { advance = undefined; };
  }, []);
  return h(Text, null, `Counter: ${count}`);
}

const app = render(
  h(Box, {width: 50, height: 4},
    h(Box, {width: 20}, h(Text, null, 'UNCHANGED LEFT')),
    h(Counter)),
  {
    stdout, stdin: new PassThrough(), patchConsole: false,
    interactive: true, alternateScreen: true,
    incrementalRendering: true, exitOnCtrlC: false,
  },
);
const settle = async () => {
  await new Promise(resolve => setTimeout(resolve, 100));
  await app.waitUntilRenderFlush();
};

try {
  await settle();
  const updates = [];
  for (let index = 0; index < 3; index++) {
    writes.length = 0;
    advance();
    await settle();
    updates.push(writes.join(''));
  }
  const result = {
    incrementalRendering: true,
    updates: updates.length,
    unchangedPrefixRewritten: updates.filter(value => value.includes('UNCHANGED LEFT')).length,
    frames: updates,
  };
  app.unmount();
  console.log(JSON.stringify(result, null, 2));
} finally {
  app.cleanup();
}

Run:

node line-update-repro.mjs
bun line-update-repro.mjs

Current result

Both runtimes report:

json
{
  "incrementalRendering": true,
  "updates": 3,
  "unchangedPrefixRewritten": 3
}

The first update contains:

\u001b[?2026h\u001b[4A\u001b[1GUNCHANGED LEFT      Counter: 1\u001b[K\n\u001b[E\u001b[E\u001b[E\u001b[?2026l

UNCHANGED LEFT is re-emitted on every update even though only Counter changes and the layout dimensions remain fixed.

Desired behavior

When safe, leave the unchanged prefix untouched, move to the first changed column, restore the necessary ANSI state, and write the changed suffix. A cell/range diff would also satisfy the use case; no particular public API or algorithm is required.

This can reduce output volume and redundant writes in side-by-side/full-screen interfaces, especially over SSH. It would also make external terminal-graphics integration easier by avoiding writes over unaffected placements. The demo intentionally contains no images and does not assume that Ink has built-in sixel support.

Correctness considerations

  • Compare styles as well as text; preserve SGR state at the start of the changed region.
  • Respect grapheme/display-cell boundaries for CJK, combining characters and emoji.
  • Preserve line-shortening, clear-to-end, cursor placement and full-width/wrap-pending behavior.
  • Fall back to existing full-line output for unsupported control sequences, uncertain state, resize/full-clear paths, or when the application explicitly needs a repaint.
  • Keep the current behavior as a fallback; an opt-in mode would be sufficient.

Related

#1032 addresses tokenization/measurement work per frame. This request is about the terminal writes after the frame has already been composed, so it is a separate optimization.