#1034·ink

useCursor position is lost after a sibling-only re-render

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

Summary

A mounted component calls useCursor().setCursorPosition() during render, as in the documented usage. Its cursor is initially shown at the requested position. When a separate sibling updates only its own state, the cursor owner does not re-render, but the next terminal frame hides the cursor and does not restore it.

This reproduces with incrementalRendering both true and false. No focus change, unmount, explicit setCursorPosition(undefined), input event, or selection implementation is involved.

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 cursor-repro.mjs:

javascript
import React, {useEffect, useState} from 'react';
import {Writable, PassThrough} from 'node:stream';
import {render, Box, Text, useCursor} 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: 40, rows: 24});
let advance;
let ownerCommits = 0;

function CursorOwner() {
  const {setCursorPosition} = useCursor();
  setCursorPosition({x: 7, y: 1});
  useEffect(() => { ownerCommits++; });
  return h(Text, null, 'Input: __');
}

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

const incrementalRendering = !process.argv.includes('--standard');
const app = render(
  h(Box, {width: 40, height: 4, flexDirection: 'column'},
    h(Counter), h(CursorOwner)),
  {
    stdout, stdin: new PassThrough(), patchConsole: false,
    interactive: true, alternateScreen: true,
    incrementalRendering, exitOnCtrlC: false,
  },
);
const settle = async () => {
  await new Promise(resolve => setTimeout(resolve, 100));
  await app.waitUntilRenderFlush();
};

try {
  await settle();
  const initial = writes.join('');
  const before = ownerCommits;
  writes.length = 0;
  advance();
  await settle();
  const update = writes.join('');
  const result = {
    incrementalRendering,
    ownerCommitsBefore: before,
    ownerCommitsAfter: ownerCommits,
    initialShowsCursor: initial.includes('\u001b[?25h'),
    siblingUpdateHidesCursor: update.includes('\u001b[?25l'),
    siblingUpdateShowsCursor: update.includes('\u001b[?25h'),
    update,
  };
  app.unmount();
  console.log(JSON.stringify(result, null, 2));
} finally {
  app.cleanup();
}

Run:

node cursor-repro.mjs
node cursor-repro.mjs --standard
bun cursor-repro.mjs
bun cursor-repro.mjs --standard

Actual result

All four runs produce these observations:

json
{
  "ownerCommitsBefore": 1,
  "ownerCommitsAfter": 1,
  "initialShowsCursor": true,
  "siblingUpdateHidesCursor": true,
  "siblingUpdateShowsCursor": false
}

For example, the incremental sibling update is:

\u001b[?2026h\u001b[?25l\u001b[3B\u001b[1G\u001b[4A\u001b[1GCounter: 1\u001b[K\n\u001b[E\u001b[E\u001b[E\u001b[?2026l

It contains a hide-cursor sequence but no show-cursor sequence. The captured update is taken before unmount; this is not the cursor restoration behavior on process exit.

Expected result

A sibling-only update should preserve the mounted cursor owner's last declared position and visibility, unless that owner changes or clears its cursor intent. Otherwise an input component must be coupled to unrelated animation/status updates to keep the caret and IME anchor alive.

If cursor intent is deliberately scoped to every global terminal frame rather than to its owner component, could that contract and the supported way for an isolated component to reassert its intent be clarified?

Related work

  • #984 describes reasserting cursor intent for selection-triggered repaints. This report isolates a sibling-only repaint using the existing public API, with no selection code.
  • #870 concerns layout-relative/declarative positioning. This case uses fixed coordinates; layout does not move.
  • Unlike #864, this occurs before exit and also reproduces on Node.js.