Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix inf rerender tables col sizing (#8997)

Shahmir Varqhaa59b8f4f40f1
diff --git a/frontend/src/components/data-table/renderers.tsx b/frontend/src/components/data-table/renderers.tsx
index 02dab02f05..94b3c3efe4 100644
--- a/frontend/src/components/data-table/renderers.tsx
+++ b/frontend/src/components/data-table/renderers.tsx
@@ -9,7 +9,6 @@ import {
type HeaderGroup,
type Row,
type Table,
- type Table as TanStackTable,
} from "@tanstack/react-table";
import { useVirtualizer } from "@tanstack/react-virtual";
import { type JSX, useLayoutEffect, useRef, useState } from "react";
@@ -52,7 +51,7 @@ export function renderTableHeader<TData>(
)}
style={style}
ref={(thead) => {
- columnSizingHandler(thead, table, header.column);
+ columnSizingHandler({ table, column: header.column, thead });
}}
>
{header.isPlaceholder
@@ -323,23 +322,30 @@ function getPinningStyles<TData>(
// Update column sizes in table state for column pinning offsets
// https://github.com/TanStack/table/discussions/3947#discussioncomment-9564867
-function columnSizingHandler<TData>(
- thead: HTMLTableCellElement | null,
- table: TanStackTable<TData>,
- column: Column<TData>,
-) {
+function columnSizingHandler<TData>({
+ table,
+ column,
+ thead,
+}: {
+ table: Table<TData>;
+ column: Column<TData>;
+ thead: HTMLTableCellElement | null;
+}): void {
if (!thead) {
return;
}
- if (
- table.getState().columnSizing[column.id] ===
- thead.getBoundingClientRect().width
- ) {
+ // Round to avoid infinite re-render loops: the browser's table layout
+ // algorithm may render a <th> at a slightly different width than the
+ // CSS `width` we set via column.getSize(), so a strict float === float
+ // comparison never stabilizes. Rounding to integers ensures convergence
+ // after at most one cycle.
+ const measuredWidth = Math.round(thead.getBoundingClientRect().width);
+ if (table.getState().columnSizing[column.id] === measuredWidth) {
return;
}
table.setColumnSizing((prevSizes) => ({
...prevSizes,
- [column.id]: thead.getBoundingClientRect().width,
+ [column.id]: measuredWidth,
}));
}
diff --git a/marimo/_smoke_tests/pandas_smoke_tests/dates.py b/marimo/_smoke_tests/pandas_smoke_tests/dates.py
index edfd3803c4..bb944a6706 100644
--- a/marimo/_smoke_tests/pandas_smoke_tests/dates.py
+++ b/marimo/_smoke_tests/pandas_smoke_tests/dates.py
@@ -1,6 +1,6 @@
import marimo
-__generated_with = "0.17.8"
+__generated_with = "0.22.0"
app = marimo.App(width="medium")
@@ -9,6 +9,7 @@ def _():
import marimo as mo
import pandas as pd
from datetime import datetime
+
return datetime, mo, pd
@@ -106,5 +107,19 @@ def _(datetime, pd):
return
+def _(mo, pd):
+ # Bug with inf re-render https://github.com/marimo-team/marimo/issues/8964
+ df = pd.DataFrame(
+ {
+ "ID_SBSC": [6013949] * 10,
+ "ID_DATE": [20260401] * 10,
+ },
+ index=pd.Index(["2026-04-01"] * 10, name="ID_DATE"),
+ )
+ mo.ui.table(df)
+ return
+
+
if __name__ == "__main__":
app.run()