fix(Table): keep group headers out of the caller's cell renderers - #5317
Open
ernestt wants to merge 1 commit into
Open
fix(Table): keep group headers out of the caller's cell renderers#5317ernestt wants to merge 1 commit into
ernestt wants to merge 1 commit into
Conversation
The grouped-rows plugin wraps each synthetic header in a Proxy that answers unknown fields with '', on the theory that a cell renderer reaching into a header would then read an empty string rather than throw. That only holds for a renderer that prints a field. The common shape keys a lookup off one -- STATUS_META[item.status].dot -- and '' is no more a member of that map than undefined is, so the renderer throws and takes the page down with it. There was no way for a consumer to opt out: BaseTable evaluates every column's renderCell against every row before transformBodyRow can discard a header's cells. Skip the call instead. Those cells are thrown away moments later regardless, so nothing is lost by never producing them, and the Proxy stays as a backstop for the default renderer that reads item[key] directly. Wrapped columns are cached against their source column because BaseTable compares the resolved column array element by element to decide whether every row must re-render -- allocating a fresh column per render would have quietly cost that. Also return isGroupHeader, so a consumer guarding their own row-level plugin has something better to test than whether the row key starts with __group_. Co-authored-by: Cursor <cursoragent@cursor.com>
ernestt
requested review from
cixzhang,
humbertovirtudes and
imdreamrunner
as code owners
August 22, 2026 00:54
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsTable (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
useTableGroupedRowsinjects synthetic group-header rows into the flattened data. Each is a Proxy that answers unknown fields with'', and the source comment claims this makes "arbitrary field access from user cell renderers" safe.It doesn't. The Proxy rescues a renderer that prints a field. It does nothing for the far more common one that keys a lookup off it:
''is no more a member of that map thanundefinedis, so this throws and blanks the page the moment grouping is switched on. There was no way to opt out from the consumer side, becauseBaseTableevaluates every column'srenderCellagainst every row beforetransformBodyRowgets to discard a header's cells:I hit this building a table template and had to work around it with a
transformColumnswrapper in the consumer — which is what this PR moves into the plugin, where it belongs.How
transformColumnsnow wraps each column sorenderCellis skipped for header rows. Those cells are discarded moments later bytransformBodyRowregardless, so nothing is lost by never producing them. The Proxy stays as a backstop for the default renderer, which readsitem[key]directly.Wrapped columns are cached against their source column in a
WeakMap. This matters:BaseTablestabilises the resolved column array with an element-by-element reference check, so allocating a fresh column object per render would have silently defeatedMemoizedTableRowand re-rendered every row on every render. There's a test locking that down.The hook also now returns
isGroupHeader, so a consumer guarding their own row-level plugin (click-to-open-detail, row links, per-row menus) has something better to test than whether the row key happens to start with__group_:Test plan
Three tests added, each verified to fail without its fix:
renderCellkeys a lookup off a field no longer throws when grouping is on; only the three real rows reach the renderer. Without the guard:TypeError: Cannot read properties of undefined.transformColumnsreturns the same wrapped column objects across calls, and leavesrenderCell-less columns untouched. Without theWeakMap: fails.isGroupHeaderdistinguishes the two synthetic headers from the three real rows.tsc --noEmit,eslint, andprettier --checkall clean.Notes
One thing I chose not to change:
aria-rowcount/aria-rowindexdrift when headers are present, since the rendered rows include them. Fixing it properly needs a count the plugin doesn't own, so it seemed out of scope here.Made with Cursor