Repository navigation
fix(Table): guard rowExpansion tree walks against cyclic data - #4070
Conversation
Cyclic or self-referential row data crashed useTableRowExpansionState with a stack overflow: all three tree walks (depthMap, flattened data, allExpandableKeys) recursed without ancestor tracking. Track the ancestor-key path in a Set and skip the cyclic edge, keeping first-encountered depth semantics. The allExpandableKeys walk crashed even with nothing expanded, since it recurses unconditionally. Fixes meta#3971 Claude-Session: https://claude.ai/code/session_01P9qSoGWZPPp9pUNNRUSwkM
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
…ard (meta#3971) The cycle tests couldn't tell the prescribed ancestor-path guard from a global visited-set (which would silently drop a shared child under its second expanded parent on acyclic DAG data). Replace the redundant first-depth test with a DAG pin that fails on the visited-set variant, and retitle the once-each claims to what the assertions actually prove (termination).
There was a problem hiding this comment.
Approving. This is exactly the ancestor-path guard prescribed in #3971, and it's done right.
All three walks (depthMap, flattened data, allExpandableKeys) now track the keys on the current path and skip an edge that points back at an ancestor, adding before recursing and deleting after. That terminates on cycles without corrupting acyclic output.
The highlight for me was DAG test: a shared child under two expanded parents must flatten under both, and a naive global visited-set would emit it only once. Pinning ['p1','s','leaf','p2','s','leaf'] proves you chose ancestor-path semantics deliberately over the easy-but-wrong visited-set.
Thanks for picking this up and for the rigor on the test design, awesome work!
What this does
Stops the Table's row-expansion feature from crashing when the row data accidentally contains a loop (a row that ends up being its own ancestor).
Why
With cyclic data, the three internal tree walks recursed forever and crashed with a stack overflow — one of them even with nothing expanded. This is the cycle-guard follow-up humbertovirtudes prescribed in #3971, and the fix pattern mirrors the guarded tree walks already reviewed in #3789.
What changed
main(lint-staged applies it on commit) — safe to skip in review.How to see it
pnpm exec vitest run packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx— 13/13 pass (the 3 cyclic ones crash with RangeError before the fix; the DAG test fails if the guard is degraded to a visited-set). Full core suite green.Fixes #3971