Calling row.toggleExpanded(bool) triggers re-render even without state change #6136
Send to my agentTanStack Table version#
8.21.3
Framework/Library version#
"react": "19.2.1",
Describe the bug and the steps to reproduce it#
I experienced a tiny freeze when tab-navigating between inputs with tab. This was in the onBlur handler:
if (newValue == "") row.toggleExpanded(false) else row.toggleExpanded(true)
I suspected it was re-rendering freeze, which I later confirmed too. The solution was to add an additional check
if (newValue == "") row.getIsExpanded() && row.toggleExpanded(false) else !row.getIsExpanded() && row.toggleExpanded(true)
And I realized that when the state is false, setting row.toggleExpanded(false) would not produce a changed UI, but it would still re-render the whole table.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
code provided below
Screenshots or Videos (Optional)#
export const columns = [ { accessorKey: "priceSuggestion", header: "Price Suggestion", id: "priceSuggestion", cell: ({ row }) => { const priceSuggestion = row.original.priceSuggestion
const handleSubmit = (e: React.FormEvent) => { e.preventDefault() const formData = new FormData(e.currentTarget) const newValue = formData.get("priceSuggestion") if (newValue == "" || newValue == priceSuggestion) row.getIsExpanded() && row.toggleExpanded(false) else !row.getIsExpanded() && row.toggleExpanded(true) }
return ( ) }, },
Do you intend to try to help solve this bug with your own PR?#
No, because I do not have time to dig into it
Terms & Code of Conduct#
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
I've submitted a fix for this in #6184. The root cause is that
toggleExpandedcallstable.setExpanded()unconditionally — even when the desired state matches the current state. The fix adds an early return that checks the current expanded state before proceeding, completely avoiding the unnecessaryonExpandedChangecallback.KevinVandy closed this
Sign in to join this conversation.
📝 CodeRabbit Plan Mode#
Generate an implementation plan and prompts that you can use with your favorite coding agent.
Examples
🔗 Similar Issues
Related Issues
https://github.com/TanStack/table/issues/6109
👤 Suggested Assignees
bsvetlik
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord or schedule a call!