Skip to content

Fix/table state identity - #10768

Open
asxxb wants to merge 4 commits into
adobe:mainfrom
asxxb:fix/table-state-identity
Open

asxxb wants to merge 4 commits into
adobe:mainfrom
asxxb:fix/table-state-identity

Conversation

@asxxb

@asxxb asxxb commented Oct 13, 2026 •

Copy link
Copy Markdown

Closes #10759

✅ Pull Request Checklist

AI assistance disclosure: This contribution was developed with AI assistance. I will review and understand the implementation and tests before submission, in accordance with the repository's AI contribution guidelines.

📝 Test Instructions

Run the table container width regression tests:

yarn jest packages/react-aria-components/test/Table.test.js -t "container width changes"

Run the table resizing tests:

yarn jest packages/react-aria-components/test/Table.test.js -t "resizing table"

Run the React Stately table state tests:

yarn jest packages/react-stately/test/table/useTableState.test.tsx

Run the table utility tests:

yarn jest packages/react-stately/test/table/TableUtils.test.js

Run repository checks:

yarn format:check
yarn check-types
yarn lint

Expected behavior: When only the ResizableTableContainer width changes, cells should not re-render unnecessarily because the table state context value remains stable when its meaningful state has not changed. Legitimate updates to selection, sorting, expansion, filtering, and collection state must continue to propagate correctly.

Verification results: The container-width regression tests (3), table resizing tests (4), table state tests (10), and table utility tests (11) passed. Formatting, type checking, and linting also passed.

🧢 Your Project

Independent open-source contribution — React Spectrum.

@asxxb asxxb closed this Oct 13, 2026
@asxxb asxxb reopened this Oct 13, 2026
@snowystinger

Copy link
Copy Markdown
Member

Thanks for the PR

AI assistance disclosure: This contribution was developed with AI assistance. I will review and understand the implementation and tests before submission, in accordance with the repository's AI contribution guidelines.

Can you please explain the changes in this PR? Why did you make them? What was the approach? Why did it touch so many more lines than the Issue suggested? Why did you need to disable the react compiler lint rules for some lines?

@asxxb

asxxb commented Oct 17, 2026

Copy link
Copy Markdown
Author

Thanks for the PR

AI assistance disclosure: This contribution was developed with AI assistance. I will review and understand the implementation and tests before submission, in accordance with the repository's AI contribution guidelines.

Can you please explain the changes in this PR? Why did you make them? What was the approach? Why did it touch so many more lines than the Issue suggested? Why did you need to disable the react compiler lint rules for some lines?

Thanks for reviewing!

The core change is intended to keep the TableStateContext value stable when the table's meaningful state has not changed, so ResizableTableContainer width changes don't cause every cell to re-render.

Why these changes

The issue comes from the table state/context value being recreated across renders even when the underlying table state is unchanged. Since the context value is consumed by table cells, a container width update can propagate through the context and cause unnecessary cell re-renders.

The fix memoizes the relevant table state/context value based on the state that actually affects consumers. This keeps the identity stable across renders where there has been no meaningful table-state change, while still producing a new value when selection, sorting, expansion, filtering, or collection state changes.

Why the PR touches more lines than the issue suggests

The functional change itself is relatively small, but I added regression coverage at multiple levels to make sure the identity optimization doesn't change legitimate table behavior.

The additional changes cover:

  • the TableState memoization behavior,
  • container-width changes,
  • table resizing,
  • and the existing table utility/state behavior.

Some of the extra lines are test setup and stronger assertions needed to reproduce the render behavior reliably. The goal was to verify both sides of the optimization: unnecessary renders are avoided, while legitimate state changes still propagate.

React Compiler lint rules

I disabled the React Compiler lint rule only at the specific lines where the existing code pattern conflicts with the optimization/memoization approach. This was intentionally kept local rather than disabling the rule for the file or project.

The underlying behavior is intentional here: the memoization is being used to preserve referential identity for the context value, which is important for preventing the unnecessary consumer updates described in #10759.

I can also reduce or restructure those lines if there is a preferred pattern for satisfying the compiler lint rules without the local suppressions.

All requested tests and repository checks are passing.

@snowystinger

Copy link
Copy Markdown
Member

I disabled the React Compiler lint rule only at the specific lines where the existing code pattern conflicts with the optimization/memoization approach

If at all possible I do not want to add more ignores, we're working towards reducing the number of these so that we can use the compiler, which I believe would address the issue you're fixing in this PR anyways.

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

2 participants