Skip to content

Table tree: fold useTableRowExpansion affordances into useTableTreeData, then converge #4142

Closed

Description

@humbertovirtudes

Problem

We now have two overlapping tree/hierarchy plugins for Table:

useTableRowExpansion has no remaining detail-panel / arbitrary-content surface — that path was stripped earlier, so it is purely hierarchy. The two plugins are therefore genuinely redundant, not two different surfaces that happen to overlap.

Why converge on the tree plugin (not rowExpansion)

useTableTreeData is the stronger base to keep:

  1. Fine-grained re-render — a toggle re-renders only the affected cells via useSyncExternalStore, not the whole body (useTableRowExpansion re-renders broadly).
  2. Cycle guard — an ancestor-chain Set in the flatten walk skips cyclic edges. This is exactly the fix useTableRowExpansion: add cycle guard to tree walks (stack overflow on cyclic data) #3971 wants for useTableRowExpansion; converging resolves that bug class for free.
  3. Row ARIA — aria-level / aria-expanded applied imperatively per <tr>, self-cleaning on disconnect.
  4. Uncontrolled + controlled modes, token indent ('sm' | 'md' | 'lg'), and a flat-data no-op so adopting it ahead of hierarchical data costs nothing.

The Q3 Table tracker (#3639) is explicitly trying to avoid API sprawl, so we land one tree plugin and retire the other.

What to fold from useTableRowExpansion into useTableTreeData

Two affordances useTableRowExpansion has that the tree plugin does not yet:

  1. Header expand-all toggle. useTableRowExpansion renders a header toggle button driven by isAllExpanded: boolean | 'indeterminate' + onToggleExpandAll. useTableTreeState already computes the state (expandAll / collapseAll) but there is no built-in header UI. Port the header affordance, wired to the tree state's all / none / indeterminate.
  2. Whole-row-click expansion. useTableRowExpansion's hasRowClickExpansion toggles a row from a click anywhere on it, not just the chevron. Add the equivalent to useTableTreeData.

Both are additive and behind opt-in flags, so existing tree consumers are unaffected.

Migration + deprecation

  1. Document a migration path for existing useTableRowExpansion consumers: expandedKeys / onToggle map to useTableTreeState controlled mode; getDepth + flat data map to constructing a treeConfig directly (the tree plugin already supports pre-flattened / server-driven trees this way). Ship a codemod if the consumer surface is wide enough.
  2. Once the two affordances land and the migration path is documented, deprecate useTableRowExpansion — soft-deprecate in docs + JSDoc first; removal is a later breaking change.

Fallback if we must keep both

If back-compat forces us to keep useTableRowExpansion as a distinct plugin, do not keep two independent tree walks. Extract the shared flatten / depth / expand-all / cycle-guard logic into one internal util both plugins consume, and at minimum port the cycle guard (#3971) so both are correct. Convergence is preferred; this is the floor.

Refs

Activity

  1. added
    enhancement
    component
    on Jul 21, 2026
  2. humbertovirtudes commented on Jul 22, 2026

    @humbertovirtudes
    ContributorAuthor

    Implementation plan

    Now that #3789 has merged, useTableTreeData + useTableTreeState is the surviving engine and the stronger base: it already has the cycle guard, controlled + uncontrolled modes, the flat-data no-op, per-row useSyncExternalStore subscriptions, and imperative row ARIA. This is the concrete work to converge useTableRowExpansion into it.

    The two feature gaps to fold in

    Both are additive and behind opt-in flags, so existing tree consumers are unaffected.

    1. Header expand-all toggle. useTableRowExpansion renders a header toggle driven by isAllExpanded: boolean | 'indeterminate' + onToggleExpandAll. useTableTreeState already computes the underlying state (expandAll / collapseAll exist) but exposes no 'indeterminate' value and no header UI. Add the all / none / indeterminate value to useTableTreeState's result, then render the header toggle button in useTableTreeData.
    2. Whole-row-click expansion. useTableRowExpansion's hasRowClickExpansion toggles a row from a click anywhere on it, not just the chevron. Add the equivalent to useTableTreeData (a row-level click handler in its row-props path).

    The one real design decision: column model

    This is where the two plugins genuinely diverge and a consumer will see a difference:

    • useTableRowExpansion prepends a synthetic 40px __expansion column for the depth-0 chevron, then indents child-row chevrons inline in the first user column.
    • useTableTreeData uses no extra column: it decorates the tree column's cells in place (chevron + indent inline at every depth), with a configurable treeColumnKey.

    The tree in-place model is cleaner (no phantom column), but any useTableRowExpansion consumer whose layout assumes the dedicated leading column will shift. Decision needed: adopt the tree in-place model as the single behavior (recommended), or add an opt-in "leading expander column" mode to the tree plugin for back-compat. Flagging for @cixzhang and @AKnassa.

    Config mapping (the migration surface)

    useTableRowExpansion useTableTreeData / useTableTreeState equivalent
    expandedKeys: Set + onToggle(key) + setExpandedKeys expandedIds: ReadonlySet + onExpandedIdsChange (controlled), or initialExpandedIds (uncontrolled)
    flat data + getDepth nested data + childrenKey; useTableTreeState flattens and derives depth
    getChildren childrenKey
    getRowKey id derived from the table's idKey
    getIsItemExpandable getIsExpandable (rename)
    isAllExpanded / onToggleExpandAll new header affordance (gap 1)
    hasRowClickExpansion new (gap 2)

    The sharpest mismatch is id/key derivation: useTableRowExpansion accepts a standalone getRowKey, while the tree plugin keys off the table's idKey. Consumers passing a custom getRowKey need a documented migration path, or the tree plugin needs to accept an optional key override. Scope this carefully.

    Work breakdown (stacked PRs, after #4070 and #4073 merge)

    1. PR A: header expand-all in the tree plugin (minor, non-breaking). Add the 'indeterminate' state to useTableTreeState's result and the header toggle UI in useTableTreeData, behind a flag. Tests + story.
    2. PR B: whole-row-click in the tree plugin (minor, non-breaking). Opt-in hasRowClickExpansion equivalent. Tests.
    3. PR C: migration doc + optional codemod (patch/docs). Document the config table above, resolve the getRowKey -> idKey gap and the column-model decision. Ship a codemod if the internal consumer count justifies it.
    4. PR D: soft-deprecate useTableRowExpansion (patch). JSDoc @deprecated + a docs banner pointing to the tree plugin, keeping it functional. Update the non-plugin references: apps/sandbox/.../table-lab/page.tsx, apps/storybook/stories/TableRowExpansion.stories.tsx, packages/cli/templates/blocks/components/Table/TableRowExpansionTable.tsx + .doc.mjs, the Table/index.ts exports, and the {@link useTableRowExpansionState} reference in useTableGroupedRows.tsx.
    5. PR E: remove useTableRowExpansion (major, later). Delete the plugin directory and drop the exports. Only after consumers have migrated.

    Notes

    Fallback if we must keep both

    If back-compat forces keeping useTableRowExpansion as a distinct plugin, do not keep two independent tree walks. Extract the shared flatten / depth / expand-all / cycle-guard logic into one internal util both plugins consume. Convergence is preferred; this is the floor.

  3. humbertovirtudes commented on Jul 22, 2026

    @humbertovirtudes
    ContributorAuthor

    PR #4172 (draft) implements step 1 of the plan above: the expand-all/collapse-all header control folded into useTableTreeData + useTableTreeState. Whole-row-click, the migration doc, and deprecation follow in separate PRs.

  4. humbertovirtudes commented on Jul 31, 2026

    @humbertovirtudes
    ContributorAuthor

    PR #4584 implements step 3 of the plan: the migration guide from useTableRowExpansion to useTableTreeData + useTableTreeState (before/after example + config mapping) on the useTableRowExpansion docs. Deprecation (step D) and removal + codemod (step E) follow.

  5. humbertovirtudes commented on Jul 31, 2026

    @humbertovirtudes
    ContributorAuthor

    PR #4587 implements step 4 (soft-deprecate): @deprecated JSDoc on useTableRowExpansion + useTableRowExpansionState and a Deprecated: marker in the docs, pointing to the tree plugin and the migration guide. Non-breaking; the hooks still work. Step 5 (removal + version-keyed codemod) is the last one.

  6. humbertovirtudes commented on Jul 31, 2026

    @humbertovirtudes
    ContributorAuthor

    PR #4609 takes the convergence in a different direction, per discussion: instead of removing useTableRowExpansion, it repurposes it as a detail-panel plugin (renderExpanded), so the two plugins are distinct (tree = hierarchy, rowExpansion = detail panel). This supersedes the deprecate/remove path. The soft-deprecation PR #4587 should be closed rather than merged.

  7. humbertovirtudes commented on Aug 11, 2026

    @humbertovirtudes
    ContributorAuthor

    PR #4884 adds the automated migration codemod (migrate-table-rowexpansion-to-tree) for consumers moving off the old tree-mode useTableRowExpansion, following the plugin change in #4609. Runs on astryx upgrade; detail-panel usage is left untouched.

  8. humbertovirtudes commented on Aug 11, 2026

    @humbertovirtudes
    ContributorAuthor

    Converged and shipped

    This is complete. useTableTreeData + useTableTreeState and useTableRowExpansion are now two plugins with distinct, non-overlapping purposes, and there is an automated migration path between the old world and the new one.

    The two plugins, differentiated

    • useTableTreeData + useTableTreeState own hierarchy: nested/child rows that reuse the parent's columns, with expand/collapse, an expand-all header control, and whole-row-click expansion.
    • useTableRowExpansion owns master-detail: renderExpanded(item) renders a full-width detail panel below a row (accordion / detail-drawer patterns). This restored its original design intent instead of deleting it.

    The redundant tree affordances that used to live in useTableRowExpansion were folded into the tree plugin, and the tree-flatten helper useTableRowExpansionState was removed (tree users move to useTableTreeState).

    What shipped

    PR What Status
    #3789 useTableTreeState + useTableTreeData tree data plugin merged
    #4172 Tree expand-all header control merged
    #4548 Tree whole-row-click expansion merged
    #4584 useTableRowExpansion to tree-plugin migration guide merged
    #4587 Initial soft-deprecation docs for the tree use case merged
    #4609 Repurpose useTableRowExpansion as a detail-panel plugin (renderExpanded); remove useTableRowExpansionState; re-add the additive afterRow core primitive merged
    #4884 migrate-table-rowexpansion-to-tree codemod (runs on astryx upgrade) merged

    Direction note

    The plan started by leaning toward deprecating useTableRowExpansion (the soft-deprecation docs in #4587). During implementation the direction changed: rather than remove a useful plugin, #4609 repurposed it for the master-detail pattern it was originally designed for. The result keeps both plugins, each with a clear job, and supersedes the deprecation framing.

    Migration for consumers

    Closing as done. The breaking change and its automated escape hatch both land in v0.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

componentenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions