Skip to content

feat(table): tree data plugin — useTableTreeState + useTableTreeData - #3789

Merged
humbertovirtudes merged 2 commits into
meta:mainfrom
AKnassa:feat/3346-table-tree-plugin
Jul 21, 2026
Merged

humbertovirtudes merged 2 commits into
meta:mainfrom
AKnassa:feat/3346-table-tree-plugin

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3346.

What this does

Adds tree support to Table: rows can nest under a children key, and the table shows them as an expandable, indented hierarchy — like a file browser. Clicking a chevron opens a row's children; clicking again closes them.

Why

Internal-tool builders keep hand-rolling row indentation and expand/collapse on top of Table (the Meridian gap report rebuilt all of it from scratch). #3346 specs this as a first-class plugin pair, and the Q3 Table tracker (#3639) lists tree rows as an open item.

What changed

default-dark default-light expand-and-collapse-all-dark expand-and-collapse-all-light flat-data-is-a-no-op-dark flat-data-is-a-no-op-light indent-sizes-dark indent-sizes-light interaction-1-collapsed interaction-2-expanded with-selection-dark with-selection-light with-sibling-sorting-dark with-sibling-sorting-light

Two hooks, following the same state/plugin split as sorting and selection:

  • useTableTreeState owns which rows are open (controlled or uncontrolled) and flattens the nested data into exactly the rows the table shows. Closed branches are unmounted, not hidden — a 10,000-node tree with everything closed renders only its roots. Also returns expandAll/collapseAll, supports lazy-loaded children (isItemExpandable), and per-sibling-group sorting (sortSiblings — pass applySort from useTableSortableState; levels never interleave).
  • useTableTreeData draws the tree: per-level indent (spacing tokens sm/md/lg) and an expander chevron in the tree column (first column by default, configurable via treeColumnKey), plus aria-level/aria-expanded on rows and the expander button per the issue's ARIA scope. No synthetic column — other columns get zero extra DOM.
  • 'tree' joins the canonical plugin order between 'sort' and 'selection', so the selection checkbox column lands left of the indented tree column.

Migration guarantee: with flat data the plugin is a true no-op — cells render byte-identical to a plugin-free Table (tested), so teams can adopt it before their data becomes hierarchical.

Performance: mirrors the selection plugin's external-store design — toggling a row re-renders only the affected cells, not the body (perf test included). Wrapped column identity is cached (shallow-equal keyed) so row memoization survives; row refs return cleanups so subscriptions can't leak across re-renders; the plugin keeps one stable shape so flat↔nested data flips never remount the table.

Relationship to useTableRowExpansion (#3441)

That plugin covers inline expansion with a dedicated chevron column and controlled-only state. This one implements the #3346 spec, which asks for a different surface: no synthetic column, row-level tree ARIA, uncontrolled + controlled expansion, token-based indent, the flat-data no-op, and sibling-scoped sorting. Happy to align naming/deprecation however maintainers prefer.

While mirroring the selection architecture we found its row-ref subscriptions leak one listener per row re-render (refs never unsubscribe on detach) — this plugin returns ref cleanups instead; we can file a follow-up for selection.

How to check it

  • pnpm vitest run packages/core/src/Table/plugins/tree/ — 55 tests: expansion, ARIA, controlled/uncontrolled, lazy loading, composition with selection + sorting, flat-data no-op, cyclic-data guard, render-count budgets.
  • Full core suite: 3996 passing; lint/typecheck/typecheck:docs/build/sync-exports all clean.
  • CLI docs render: node packages/cli/bin/astryx.mjs component useTableTreeData --dense.

Known limitation (documented in the doc.mjs): the tree column wraps its cell content, so textOverflow="truncate" tooltips don't apply inside that column — same trade-off as rowExpansion.

…ata (meta#3346)

Two-layer tree support for Table, mirroring the sort/selection family
split: useTableTreeState owns the expanded set (controlled or
uncontrolled) and flattens nested data into visible rows (collapsed
subtrees unmount); useTableTreeData decorates the tree column with
token-based indent + expander chevrons and reflects hierarchy via
aria-level/aria-expanded on rows. Flat data is a render-identical
no-op. 'tree' joins PLUGIN_ORDER between 'sort' and 'selection'.

Claude-Session: https://claude.ai/code/session_01EvReRVRbXoudGVphwR5oEw
@vercel

vercel Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 11, 2026 3:13am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 11, 2026
…#3346)

Seven stories matching the plugin's surfaces: default org chart, expand/
collapse all, the three indent tokens, composition with selection and with
sibling-scoped sorting, lazy-loaded children, and the flat-data no-op.
Every other Table plugin ships a story; this brings tree to parity.

Claude-Session: https://claude.ai/code/session_01EvReRVRbXoudGVphwR5oEw
@AKnassa
AKnassa marked this pull request as ready for review July 11, 2026 03:14
@cixzhang cixzhang added area:core needs:code-review High-risk change (new package/component/API) — needs human code review before merge and removed area:core labels Jul 11, 2026
@github-actions github-actions Bot added the community Authored by a community contributor (not on the eng/design team) label Jul 11, 2026
@humbertovirtudes

Copy link
Copy Markdown
Contributor

Thanks for this — it's a genuinely strong PR, and the writeup is excellent. I like how you documented the issues with the current row expansion plugin and how your approach tackles them. Rigorous testing too.

Before we go deeper on line-level review, I want to raise the bigger question up front, because I think it changes the shape of the PR: I'd like to propose folding this into useTableRowExpansion (#3441) rather than landing a second tree plugin.

Why converge

useTableRowExpansion is already an inherited-columns tree plugin — child rows reuse the parent columns, indented by depth, with a chevron toggle and expand-all. We deliberately stripped its detail-panel / customRow path a while back, so it has no "arbitrary expanded content" surface left; it's purely hierarchy. That means tree and rowExpansion aren't two different surfaces that happen to overlap — they're ~90% the same plugin. The Q3 tracker (#3639) is explicitly trying to avoid API sprawl, and shipping two overlapping tree plugins with no guidance on which to reach for is exactly the sprawl we're trying to prevent.

The good news: almost everything your tree plugin does better than rowExpansion is additive and lands cleanly on the existing plugin. Here's the mapping I see:

tree feature How it folds into useTableRowExpansion
Uncontrolled mode (defaultExpandedIds) Make expandedKeys/setExpandedKeys optional in useTableRowExpansionState; fall back to internal useState.
Token-based indent (sm/md/lg) Replace the hardcoded INDENT_PER_DEPTH = 24 with an indent enum → spacing tokens.
Row ARIA (aria-level/aria-expanded) rowExpansion re-renders rows on toggle already, so we can set these declaratively via props.htmlProps in transformBodyRow — no imperative ref, no store subscription, no leak surface. I think this is actually simpler than the ref approach here.
Flat-data no-op Guard transformColumns to return columns unchanged (and skip the synthetic column) when nothing is expandable.
sortSiblings Add to the flatten walk in useTableRowExpansionState — sort each sibling array before recursing.
Cycle guard Port your path ancestor-chain Set. rowExpansion's walks currently have no guard and will stack-overflow on cyclic data — this is a latent bug we should fix regardless.

The one real design difference

useTableRowExpansion uses a dedicated synthetic __expansion column (chevron in its own column for depth-0 rows, inline for children); tree uses no synthetic column and decorates the tree column's cell in place. I suggest keeping the separate __expansion column approach, so we have a good separation of concerns.

The external-store perf model is an internal optimization rather than public API, so I don't think we need it to converge the API — it can be a follow-up if toggle re-renders ever show up as a real cost. IMO this deserves a separate discussion.

Proposed path

Rather than drop your work, I'd love to convert it into a small stack of enhancement PRs against useTableRowExpansion (or a single one if a stack is hard to manage):

  1. Cycle guard (bug fix, standalone)
  2. Uncontrolled mode + token indent
  3. Row ARIA (declarative via htmlProps)
  4. Flat-data no-op
  5. sortSiblings

Your tests port over almost directly. Happy to pair on the split or take some of these on myself — whatever's easiest for you.

Two follow-ups your PR surfaced that I'll file separately either way: the missing cycle guard in useTableRowExpansion, and the selection plugin's row-ref subscription leak you spotted.

How do you feel about this direction? Not trying to discount the work — the opposite; I think it makes rowExpansion meaningfully better and keeps the tree story to one plugin.

@humbertovirtudes humbertovirtudes left a comment

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.

Requesting changes to align on direction before line-level review — see my comment above: I'd like to converge this into useTableRowExpansion (#3441) rather than land a second overlapping tree plugin, and split the genuinely-better bits (cycle guard, uncontrolled mode, token indent, row ARIA, flat-data no-op, sortSiblings) into enhancement PRs against it. Happy to pair on the split. Not a knock on the work — it makes rowExpansion meaningfully better and keeps the tree story to one plugin.

@AKnassa

AKnassa commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @humbertovirtudes for the thorough read, and for filing #3971 and #3972 already — much appreciated.

I agree with the goal: there should be one tree story, and most of what tree does lands fine on either plugin. Uncontrolled mode, token indent, sortSiblings, and the cycle guard all port cleanly, and I'm happy to do that work whichever direction we pick.

One thing can't be deferred, though: the ARIA mechanism and the perf model are the same decision. Declarative aria-level/aria-expanded via htmlProps stays fresh only because rowExpansion currently re-renders every row per toggle (the plugin object and __expansion column are useMemo'd on expandedKeys, so areRowPropsEqual fails on plugins/columns identity for every row). If the external-store model is added later as a follow-up, the toggled row memo-bails — its rowKey, rowIndex, item, plugins, and columns are all unchanged — transformBodyRow never re-runs, and aria-expanded goes stale on exactly the row that changed. The imperative ref in this PR isn't complexity for its own sake; it's what makes correct row ARIA compatible with not re-rendering the body. So I'd ask that we decide store-vs-declarative as part of convergence, not after it. (It's also why "tests port almost directly" is optimistic: two of the three perf tests assert render budgets the declarative model can't meet by design.)

The other deltas are spec-level rather than taste-level, so I'd like a maintainer call on them. #3346 explicitly specifies: no synthetic column ("zero extra DOM on other columns; zero wrapper rows"), a configurable treeColumnKey, key-first accessors (idKey/childrenKey — it calls out that a required getChildren would be the only accessor in the family with no key form), an expandedIds/onExpandedIdsChange contract, and "store-based per-row subscriptions so a toggle doesn't re-render the whole body." The fold as mapped drops all of these, and the flat-data no-op also changes shape under a synthetic column (the __expansion column popping in when data turns nested is a layout shift the in-place design doesn't have). One more structural note: #3639 still lists "Row-expansion data source — async-loaded expansion content" (#3949), which suggests rowExpansion may grow detail-content back — worth deciding whether the single tree plugin should be the one slated to regain a content surface.

A third option that gets to one plugin without deviating from the spec: converge on the tree API/architecture as the single plugin and fold rowExpansion's extras (hasRowClickExpansion, the context-menu action, the expand-all header toggle) into it, with a deprecation alias for useTableRowExpansion. Same end-state you're after — one plugin — just anchored on the spec'd surface.

Since either direction rewrites part of #3346's written API or #3639's item structure, @cixzhang / @thedjpetersen — could you weigh in on which surface the tree story should converge to? Meanwhile I'll pick up the direction-independent pieces (#3971, and the selection-leak fix in #3972) so nothing stalls on this discussion — and happy to take you up on the pairing offer on those.

@cixzhang

Copy link
Copy Markdown
Contributor

Thanks @AKnassa and @humbertovirtudes — really valuable thread. I think the decision breaks into a few areas. Let me lay them out; correct me if I'm framing any wrong.

1. Render performance, ARIA, and how we sequence the work

On the technical question: I think AKnassa's right that the ARIA mechanism and the render model can't be cleanly decoupled. Once you re-render only the toggled row, declaratively-set row ARIA can go stale on exactly the row that changed — so "correct row ARIA" and "external store + imperative ref" end up being one decision, not two. My lean is toward the ref + store model (it's what selection already does, and it's what keeps ARIA correct without re-rendering the body).

But I think the more useful conversation is about how we move forward, not just the end state. Humberto — you framed this as improving the expansion plugin in incremental chunks (cycle guard, uncontrolled mode, token indent, ARIA, no-op, sortSiblings), which I really like as an approach. The one wrinkle: if the ARIA/render coupling above holds, then the "row ARIA" chunk and the "store model" chunk are effectively the same chunk — you can't land declarative ARIA as a step and swap in the store later without the ARIA regressing. So I don't think it breaks the incremental plan, but it does constrain the ordering: the store/ref model probably has to come with (or before) the ARIA work, not after. Does that match how you're seeing it, or is there a way to stage it I'm missing?

2. Toggle position & indentation

Two sub-questions, and I don't think either is settled:

  • Dedicated column vs in-cell toggle. Our internal table uses an extra column; the tree PR decorates the tree column in place. There are real tradeoffs both ways (separation of concerns / column alignment vs. zero extra DOM on other columns and no column appearing when data turns nested). Worth weighing rather than defaulting.
  • A11y note for context: today useTableRowExpansion sets aria-expanded on the chevron button but not on the <tr>, and no aria-level; the Table: tree data support (indentation + expand/collapse) as a useTableTreeData plugin #3346 spec / tree PR put aria-level + aria-expanded on the row. Whichever direction we pick should implement the row-level tree-grid ARIA contract (full role="treegrid" + arrow-nav stays deferred to Accessibility & keyboard-management program: build shared interaction primitives, then migrate components #3343 either way). The contract is a must-have on the converged plugin regardless of base; how it's applied (declarative vs imperative ref) ties back to point 1.
  • Indentation configurability. For context, internally we've had feedback from teams wanting to tune indent to minimize whitespace — flagging it as a user consideration to factor in, not a position on whether/how we expose it.

@ernestt — curious for your thoughts on the toggle-in-a-column vs in-cell question and the indent configurability specifically.

3. API

My preference is to align to the Table-family API patterns (key-first accessors like idKey/childrenKey, and a controlled contract shaped like the other plugins). Genuine question rather than a foregone conclusion: can we get both rowExpansion and tree to that shape, or does one of them fit the family conventions more naturally? If they can both land there, API shape stops being a differentiator. On the name (tree vs expansion), rather than argue it we could vibe-test both and see which an LLM reaches for — a decent tiebreaker. Process per the API Arbitration wiki.

Feature set to preserve on convergence

Regardless of which surface we build on, here's what each implementation brings that we'd want to keep — so we don't lose capability in the merge:

useTableTreeData (#3789) / the #3346 spec:

  • True flat-data no-op (byte-identical to a plugin-free Table)
  • Uncontrolled (defaultExpandedIds) + controlled (expandedIds/onExpandedIdsChange)
  • Token-based indent (sm/md/lg) and configurable treeColumnKey
  • Lazy children via isItemExpandable (also what Table: row-expansion data source #3949 needs)
  • Sibling-scoped sort (sortSiblings, levels never interleave)
  • Row-level aria-level/aria-expanded
  • Cycle guard (ancestor-chain path set)

useTableRowExpansion (#3441):

  • hasRowClickExpansion (click the row, not just the chevron)
  • Context-menu Expand/Collapse action
  • Expand-all header toggle (isAllExpanded incl. indeterminate + onToggleExpandAll)

Framing this as "what to carry forward" rather than "which is the base" — the base is really what points 1–3 decide.

A case we need to handle: row identity in a DAG

Internally we hit bugs where the same child record appears under multiple parents (a DAG, not a strict tree). Both the current rowExpansion and the tree PR key rows by the bare node id, which collides in that case — shared/overwritten expansion state, duplicate React keys, and the cycle guard false-firing on legitimate diamond paths. Whatever we converge on needs to separate node id (may repeat) from row key (the parent→child path, e.g. <parentId>-<childId>, which must be unique) and key expansion/meta/ARIA/React-key on the latter. Flagging it because it's a shared gap, not a point for either side.

@humbertovirtudes since I'm in town this week, let's grab time to talk through the sequencing in point 1 and the toggle/API questions — I don't think the thread alone will settle them, and I'd rather hash them out together.

@humbertovirtudes
humbertovirtudes dismissed their stale review July 21, 2026 17:04

Aligned offline with Cindy: we are letting this land and will fold anything needed from useTableRowExpansion into it (tracked in #4142). Dismissing the earlier converge-first request.

@humbertovirtudes humbertovirtudes left a comment •

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.

@AKnassa update on direction: I aligned with @cixzhang offline and we've agreed to let this land as its own plugin rather than converge first. So I'm withdrawing my earlier "converge into useTableRowExpansion" request. This is good work, and it's the stronger tree base of the two.

The convergence still happens, just in the other direction and after this lands: we'll fold the two affordances useTableRowExpansion has that this doesn't yet (the header expand-all toggle and whole-row-click expansion) into useTableTreeData, then retire useTableRowExpansion. I've written that up as #4142 (sub-issue of the Q3 tracker #3639) so it's tracked and doesn't get lost. Notably, your ancestor-chain cycle guard is exactly the fix #3971 wants for useTableRowExpansion, so converging resolves that bug class for free.

Nothing for you to do here: #4142 is follow-up work, not a change request on this PR. A couple of small things worth a follow up, none blocking:

  • Header expand-all and whole-row-click are the two gaps vs useTableRowExpansion; fine to leave for #4142, just flagging so it's a conscious call.
  • The migration path for existing useTableRowExpansion consumers (expandedKeys/onToggle -> controlled useTableTreeState, getDepth+flat data -> a directly-constructed treeConfig) is worth a line in the docs so the deprecation later is smooth.

Approving. Thanks for the rigor on this one: the fine-grained subscriptions, the cycle guard, the flat-data no-op, and the test coverage are all awesome!

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 21, 2026
@humbertovirtudes
humbertovirtudes merged commit 9da0792 into meta:main Jul 21, 2026
23 checks passed
josephfarina pushed a commit that referenced this pull request Jul 22, 2026
…#4149)

The tree data plugin (#3789) shipped hardcoded "Expand row" / "Collapse
row" aria-labels on the expander button. The @astryx/no-hardcoded-i18n-string
rule (added in #4010) flags these as errors, so `pnpm lint` fails
repo-wide — main is red and every open PR inherits the failure.

Route both strings through useTranslator() with new catalog keys
@astryx.tableTree.expandRow / .collapseRow (mirroring the sibling
selection and rowExpansion plugins) and add matching entries to
packages/core/locales/en.json.
@github-actions
github-actions Bot deleted the feat/3346-table-tree-plugin branch July 22, 2026 08:25
cixzhang added a commit that referenced this pull request Jul 22, 2026
Seven published-behavior PRs merged since v0.1.7 without a changeset, which
would leave their contributors uncredited in the CHANGELOG. Add changesets so
the v0.1.8 bump credits them:

- core docs.mjs redirect to the CLI (#4207)
- Table tree-data plugin: useTableTreeState / useTableTreeData (#3789)
- Table tree expander aria-label localization (#4149)
- foolproof init: postinstall nudges + non-interactive init (#4147, #4153, #4154, #4155)

This branch was successfully deployed

1 active deployment
Preview — 8a2351af Deployed Jul 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tables CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) type:feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table: tree data support (indentation + expand/collapse) as a useTableTreeData plugin

3 participants