Repository navigation
Conversation
Contributor
|
🔴 CI: The generic type parameter — Navi (after-hours CI triage) |
The selection plugin was causing all table rows to re-render when any single row was selected or deselected. This happened because: 1. The plugin object changed on every render (useMemo depended on config, which is recreated each render as callbacks close over selection state) 2. MemoizedTableRow compares plugins by reference — new plugin = all rows re-render 3. transformBodyRow read selection state inline, tying row rendering to the full selection state Fix: Replace the Context-based approach with an external store pattern using useSyncExternalStore for fine-grained subscriptions: - SelectionStore holds config via ref, keeping the plugin object stable - Each row's SelectionRowContent subscribes to its own selection state - Only the row whose selection actually changed re-renders - aria-selected and background styles are applied imperatively via DOM effects to avoid re-rendering the memoized row wrapper Closes #195 Co-authored-by: Navi <[email protected]>
…generic The SelectionStore<T> interface and related functions (useIsItemSelected, SelectionRowContent) were missing the T extends Record<string, unknown> constraint required by UseXDSTableSelectionConfig<T>, causing TS2344 build errors.
cixzhang
force-pushed
the
navi/fix-selection-overrender
branch
from
February 26, 2026 20:50
6a4f0e0 to
1c95c67
Compare
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsTable · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Component PreviewsIncludes interactive hover previews as animated GIFs. XDSTableSelectionDefaultScreenshot: Interaction Preview: (view video) View in Storybook · Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
Contributor
Author
|
Closing for now. Still a problem but need focus time for this. |
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.
Problem
When making a selection in a table with the selection plugin, all rows re-render — not just the row that was selected or deselected. This is a significant performance issue for tables with many rows.
Root Cause
The
useXDSTableSelectionhook returned a new plugin object on every render because:useMemodepended onconfig, which is recreated each render (callbacks close over selection state)MemoizedTableRowinXDSBaseTablecomparespluginsby reference — new plugin object = all rows re-rendertransformBodyRowread selection state inline (config.getIsItemSelected(item)), coupling every row's render to the full selection stateSolution
Replace the Context-based approach with an external store pattern using
useSyncExternalStorefor fine-grained subscriptions:SelectionStore— lightweight store that holds config via ref, keeping the plugin object referentially stable across rendersSelectionRowContent— each row's content subscribes to its own item's selection state viauseSyncExternalStore. Only re-renders when this specific item's selection state changesSelectAllCheckbox— subscribes to all-selected/indeterminate state independentlyaria-selectedand background color are applied viauseEffecton the parent<tr>, avoiding re-renders of the memoized row wrapperBefore
Selecting 1 row in a 100-row table → 100 row re-renders
After
Selecting 1 row in a 100-row table → 1 row re-render (the selected row)
Tests
Closes #195
Crafted with care by Navi