Repository navigation
feat(table): tree data plugin — useTableTreeState + useTableTreeData - #3789
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…#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
|
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 Why converge
The good news: almost everything your
The one real design difference
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 pathRather than drop your work, I'd love to convert it into a small stack of enhancement PRs against
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 How do you feel about this direction? Not trying to discount the work — the opposite; I think it makes |
humbertovirtudes
left a comment
There was a problem hiding this comment.
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.
|
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 One thing can't be deferred, though: the ARIA mechanism and the perf model are the same decision. Declarative 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 A third option that gets to one plugin without deviating from the spec: converge on the 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. |
|
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 workOn 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 & indentationTwo sub-questions, and I don't think either is settled:
@ernestt — curious for your thoughts on the toggle-in-a-column vs in-cell question and the indent configurability specifically. 3. APIMy preference is to align to the Table-family API patterns (key-first accessors like Feature set to preserve on convergenceRegardless 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:
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 DAGInternally we hit bugs where the same child record appears under multiple parents (a DAG, not a strict tree). Both the current @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. |
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.
There was a problem hiding this comment.
@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
useTableRowExpansionconsumers (expandedKeys/onToggle-> controlleduseTableTreeState,getDepth+flat data -> a directly-constructedtreeConfig) 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!
…#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.
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)
Closes #3346.
What this does
Adds tree support to Table: rows can nest under a
childrenkey, 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
Two hooks, following the same state/plugin split as sorting and selection:
useTableTreeStateowns 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 returnsexpandAll/collapseAll, supports lazy-loaded children (isItemExpandable), and per-sibling-group sorting (sortSiblings— passapplySortfromuseTableSortableState; levels never interleave).useTableTreeDatadraws the tree: per-level indent (spacing tokenssm/md/lg) and an expander chevron in the tree column (first column by default, configurable viatreeColumnKey), plusaria-level/aria-expandedon 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.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.