Skip to content

fix(tablev2): keep RenderRow stable #1120

Merged
bert-e merged 3 commits into
development/1.0from
improvement/fix-tablev2-row-remount-on-rerender
Jun 4, 2026
Merged

fix(tablev2): keep RenderRow stable #1120
bert-e merged 3 commits into
development/1.0from
improvement/fix-tablev2-row-remount-on-rerender

Conversation

@JeanMarcMilletScality

@JeanMarcMilletScality JeanMarcMilletScality commented May 29, 2026

Copy link
Copy Markdown
Contributor

Problem

TableV2 renders its rows virtualized via react-window. RenderRow was defined inline inside the component body, so it got a new function identity on every render. react-window caches rows by component type, so a fresh identity made it unmount and remount every visible row — and therefore every cell — on any table re-render, regardless of the cause (a parent state change, a context update, etc.), not just when the data changed.

Remounting (as opposed to re-rendering) is destructive: cell subtrees lose their internal state and re-run their mount effects. Cells whose content is loaded asynchronously on mount, or that animate/resolve on mount, re-trigger all of that work — producing visible flicker and redundant refetches every time the table re-rendered for any reason.

What this PR does

  • Stabilize RenderRow. Wrap it in useMemo so its identity only changes when something that affects the rendered row actually changes (activeRowId/selectedId, separationLineVariant). The row is read from react-window's itemData (data) prop instead of closing over rows, and the volatile values (prepareRow, the selection callbacks, selectedRowIds) are read through refs. Unrelated re-renders now re-render rows (cheap, state-preserving) instead of remounting them.
  • Read selection callbacks at call time. The row click/keydown handlers read onSingleRowSelected / onRowSelected from their refs at event time rather than from a render-time snapshot, removing a stale-closure edge case (the other volatile callbacks were already read this way).
  • Document the columns / data contract. Added guidance on TableProps.columns: callers must memoize their columns and keep each Cell renderer stable across renders. react-table renders cells as <column.Cell />, so an unstable Cell identity is itself a new component type and remounts the cell subtree — independently of this fix.

What's still missing (follow-up)

RenderRow's useMemo deps include the selection state (activeRowId / selectedId). So while unrelated re-renders no longer remount rows, changing the selection still recreates RenderRow and remounts all rows — async/animated cells still flicker on row click/selection. This is intentional here: the selection is read by value so the row highlight stays correct.

Eliminating it requires keeping RenderRow fully stable and instead passing the selection through a memoized itemData object (e.g. { rows, selectedId }), letting a custom areEqual re-render (not remount) only the affected rows. That ripples into TableCommon / VirtualizedRows, the itemKey / customItemKey selectors, and the single-select highlight path, so it is deferred to a separate PR to keep this one focused and low-risk.

Verification

npm run build-storybook (exit 0), tsc --noEmit clean, ESLint clean, full Jest suite passing (446/446).


Split out of the original combined branch — icon fallback rendering is in #1122, the Storybook guideline import fix was #1121 (merged).

🤖 Generated with Claude Code

@bert-e

bert-e commented May 29, 2026

Copy link
Copy Markdown
Contributor

Hello jeanmarcmilletscality,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e

bert-e commented May 29, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • one peer

Peer approvals must include at least 1 approval from the following list:

const rows = data;
const row = data[index];
prepareRowRef.current(row);
const onSingleRowSelected = onSingleRowSelectedRef.current;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSingleRowSelected is captured from the ref at render time into a local variable, then used in the click handler ternary on line 169. The other refs (handleMultipleSelectedRowsRef, toggleAllRowsSelectedRef, selectedRowIdsRef) are correctly read from .current at click time — but this one isn't, so if the prop changes after the row renders, the click handler uses a stale reference and may pick the wrong branch (single-select vs multi-select).

Read the ref inside the click handler instead:

Suggested change
const onSingleRowSelected = onSingleRowSelectedRef.current;
const rowProps = {
...row.getRowProps({
/**
* Note:We need to pass the style property to the row component.
* Otherwise when we scroll down, the next rows are flashing
* because they are re-rendered in loop.
*/
style: { ...style },
}),
onClick: () => {
const onSingleRowSelected = onSingleRowSelectedRef.current;
if (onSingleRowSelected) {
onSingleRowSelected(row);
toggleAllRowsSelectedRef.current(false);
setActiveRowId(row.id);
} else {
handleMultipleSelectedRowsRef.current(
selectedRowIdsRef.current,
rows,
row,
index,
);
}
},

The same change applies to the checkbox onClick on the selection column (line 207) — read onSingleRowSelectedRef.current there too.

memo(({ index, style, data }: ListChildComponentProps<Row<DATA_ROW>[]>) => {
const row = data[index];
prepareRowRef.current(row);
const onRowSelected = onRowSelectedRef.current;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as in MultiSelectableContentonRowSelected is captured from the ref at render time and used in the click/keyDown handlers. Read it from the ref at call time instead:

Suggested change
const onRowSelected = onRowSelectedRef.current;
const rowProps = {
...rowProps,
...{
onClick: () => {
const onRowSelected = onRowSelectedRef.current;
if (onRowSelected) return onRowSelected(row);
},
tabIndex: onRowSelectedRef.current ? 0 : undefined,
onKeyDown: (event) => {
const onRowSelected = onRowSelectedRef.current;

</TableRowMultiSelectable>
);
}, areEqual),
[activeRowId, separationLineVariant],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activeRowId in the useMemo deps means every row click (via onSingleRowSelected) creates a new component type, causing react-window to unmount and remount all visible rows — the same flashing problem this PR fixes for other re-render triggers. The same applies to selectedId in SingleSelectableContent.

To keep the component stable across selection changes, move activeRowId into a ref (like the other volatile values) and pass it through itemData so areEqual can trigger re-renders without changing the component identity:

const activeRowIdRef = useRef<string | null>(null);
activeRowIdRef.current = activeRowId;

// in useMemo deps: remove activeRowId, keep only [separationLineVariant]
// in the row component: read activeRowIdRef.current instead of activeRowId
// pass activeRowId through itemData so areEqual detects the change:
//   itemData={useMemo(() => ({ rows, activeRowId }), [rows, activeRowId])}

This changes the itemData shape from Row[] to { rows, activeRowId }, which touches VirtualizedRows and TableRows types — a bigger refactor, so it may belong in a follow-up.

svg {
width: 1em;
height: 1em;
fill: #a14fbf;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded hex color bypasses the theme system. This won't adapt to dark/light mode or custom themes. Use a theme token instead:

Suggested change
fill: #a14fbf;
fill: ${({ theme }) => theme.infoPrimary};

RenderRow: React.MemoExoticComponent<
({ index, style }: RenderRowType) => JSX.Element
>;
RenderRow: ComponentType<ListChildComponentProps<Row<DATA_ROW>[]>>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderRowType (line 120) and its CSSProperties import (line 18) are now dead code — no remaining importers after this change. Clean them up.

@JeanMarcMilletScality JeanMarcMilletScality force-pushed the improvement/fix-tablev2-row-remount-on-rerender branch from caf9b49 to 8010104 Compare June 1, 2026 15:39
JeanMarcMilletScality and others added 2 commits June 1, 2026 18:43
…nder

RenderRow was redefined inline on every render, so react-window saw a new
component type and remounted every row (and cell) whenever the table
re-rendered, making async cell content reload and flash. Read the row from
react-window's itemData and volatile callbacks from refs so RenderRow keeps a
stable identity.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@JeanMarcMilletScality JeanMarcMilletScality force-pushed the improvement/fix-tablev2-row-remount-on-rerender branch from 8010104 to f463fc4 Compare June 1, 2026 16:44
…time

Addresses review feedback on PR #1120. `onSingleRowSelected` (Multi) and
`onRowSelected` (Single) were snapshotted from their refs at render time and
closed over by the click/keydown handlers. Since RenderRow only re-renders when
`data` identity changes, a callback whose identity changed without a `rows`
change would leave the row with a stale closure until its next re-render — while
the other volatile values (handleMultipleSelectedRows, toggleAllRowsSelected,
selectedRowIds) were already read from refs at call time.

Read these callbacks from `.current` inside the handlers so they're always
current, consistent with the other refs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bert-e

bert-e commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • one peer

Peer approvals must include at least 1 approval from the following list:

@JeanMarcMilletScality JeanMarcMilletScality marked this pull request as ready for review June 4, 2026 14:59
@bert-e

bert-e commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • one peer

Peer approvals must include at least 1 approval from the following list:

@JeanMarcMilletScality

Copy link
Copy Markdown
Contributor Author

/approve

@bert-e

bert-e commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

In the queue

The changeset has received all authorizations and has been added to the
relevant queue(s). The queue(s) will be merged in the target development
branch(es) as soon as builds have passed.

The changeset will be merged in:

  • ✔️ development/1.0

There is no action required on your side. You will be notified here once
the changeset has been merged. In the unlikely event that the changeset
fails permanently on the queue, a member of the admin team will
contact you to help resolve the matter.

IMPORTANT

Please do not attempt to modify this pull request.

  • Any commit you add on the source branch will trigger a new cycle after the
    current queue is merged.
  • Any commit you add on one of the integration branches will be lost.

If you need this pull request to be removed from the queue, please contact a
member of the admin team now.

The following options are set: approve

@bert-e

bert-e commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

I have successfully merged the changeset of this pull request
into targetted development branches:

  • ✔️ development/1.0

Please check the status of the associated issue None.

Goodbye jeanmarcmilletscality.

@bert-e bert-e merged commit f6cc295 into development/1.0 Jun 4, 2026
7 of 8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants