Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering issue with large number of Text components when using useState #694

Open
only-issues opened this issue Jan 20, 2025 · 0 comments

Comments

@only-issues
Copy link

bandicam.2025-01-20.14-04-27-912.mp4

When rendering a large number of Text components (around 50) with dynamic state updates using useState, the terminal output behaves incorrectly. Instead of updating the existing content, it appends new content below, creating duplicate output.

Steps to Reproduce

  1. Create a component with multiple Text elements using Array.map (e.g., 50 items)
  2. Implement state update using useInput
  3. Run the application and try to update the state by pressing any key

Code Example

import {Box, render, Text, useInput} from "ink";
import {useState} from "react";

export default function Test() {
    const [tab, setTab] = useState('Q');
    useInput((input) => {
        setTab(input);
    })
    return (
        <Box flexDirection={'column'}>
            <Box flexDirection={'column'}>
                {Array(50).fill(null).map((_, index) => (
                    <Text key={`${index}`}>
                        Tab: {tab}, Index: {index}
                    </Text>
                ))}
            </Box>
            <Text>Footer Text</Text>
        </Box>
    );
}
render(<Test />);

Expected Behavior

When the state updates (by pressing a key), the terminal should update the existing content in place, replacing old values with new ones.

Actual Behavior

  • With small number of items (~5): Works correctly, updates content in place
  • With large number of items (~50): Instead of updating in place, it appends the new content below the existing output, creating duplicate content in the terminal

Example Output with 50 items

Initial output:

Tab: Q, Index: 0
Tab: Q, Index: 1
...
Tab: Q, Index: 49

After pressing 'h' key (incorrect behavior):

Tab: Q, Index: 0
Tab: Q, Index: 1
...
Tab: Q, Index: 49
Tab: h, Index: 0
Tab: h, Index: 1
...
Tab: h, Index: 49

Environment

  • Node.js version: 22.13.0
  • Ink version: 5.1.0
  • Operating System: Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant