DataTable: rows rendered before column widths are measured stay truncated (row/line caches not invalidated in _update_dimensions)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start by reading DataTable._update_dimensions and its cache handling, then compare it with _on_idle and the reproduction in the issue. Reproduce the mixed row widths by rendering rows before the idle handler runs; done means every row renders with the measured column widths afterward.
Written by the indexing model from the issue text.
Description
Description
When a DataTable is rebuilt (clear(columns=True), add_column, add_row) and the screen repaints before the table's idle handler has measured the new rows, the header and the rows painted in that window are rendered with the label-only column widths – and they stay that way after the widths have been computed. Rows painted later use the correct widths, so the table ends up with a mix of truncated and full rows.
I ran into this in task-tui, which rebuilds its table on every report switch and after leaving edit mode (the focus/class change triggers the repaint). Resizing the terminal fixes the display.
Minimal reproduction
import asyncio
from textual.app import App, ComposeResult
from textual.widgets import DataTable
ROWS = [(str(i), "a-rather-long-project-name", "20261113", "some description") for i in range(5)]
class TableApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def rebuild(self) -> None:
table = self.query_one(DataTable)
table.clear(columns=True)
for label in ("ID", "Project", "Due", "Description"):
table.add_column(label, key=label)
for i, row in enumerate(ROWS):
table.add_row(*row, key=f"row{i}")
async def main() -> None:
app = TableApp()
async with app.run_test(size=(80, 10)) as pilot:
table = app.query_one(DataTable)
app.rebuild() # first build, settles normally
await pilot.pause()
app.rebuild() # rebuild the same table (e.g. after a filter change)
# A repaint before the DataTable's idle handler has measured the new rows
# (in a real app: focus change, class change, any screen refresh):
for y in range(3):
table.render_line(y)
await pilot.pause() # idle: column widths are now computed
for y in range(6):
print(table.render_line(y).text.rstrip())
asyncio.run(main())
Actual output
ID Project Due Description
0 a-rathe 202 some descri
1 a-rathe 202 some descri
2 a-rather-long-project-name 20261113 some description
3 a-rather-long-project-name 20261113 some description
4 a-rather-long-project-name 20261113 some description
Expected output
All lines rendered with the measured column widths:
ID Project Due Description
0 a-rather-long-project-name 20261113 some description
...
Analysis
add_row only records the row in _new_rows; column widths are measured later in _on_idle → _update_dimensions, which updates column.content_width. Rendered rows and lines are cached in _row_render_cache / _line_cache with keys that include _update_count. _update_dimensions changes the widths but neither bumps _update_count nor clears these caches (_line_cache is only cleared in the auto_height_rows branch), so lines cached during the window between add_row and idle are served with the old widths.
Suggested fix
Invalidate the render caches once the widths have been recomputed, e.g. at the end of _update_dimensions:
self._clear_caches()
(or self._update_count += 1). With this one line the reproduction above renders correctly.
Environment
- Textual 8.2.6 (also reproduced with 8.2.8, the current release)
- Rich 14.x, Python 3.13
- NixOS 26.05, KDE Konsole/Yakuake
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day