Repository navigation
Fix/table state identity - #10768
Fix/table state identity#10768asxxb wants to merge 4 commits into
Conversation
|
Thanks for the PR
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 Why these changesThe 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 suggestsThe 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:
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 rulesI 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. |
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. |
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:
Run the table utility tests:
Run repository checks:
Expected behavior: When only the
ResizableTableContainerwidth 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.