Skip to content
Source
Sign inSign up
TanStack/table

Calling row.toggleExpanded(bool) triggers re-render even without state change #6136

Send to my agent
Closedackvf(GitHub profile, opens in a new tab) opened this issue 2 comments

TanStack 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.

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.
  1. 📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees

  2. bsvetlik


  3. 🧪 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:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  • I've submitted a fix for this in #6184. The root cause is that toggleExpanded calls table.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 unnecessary onExpandedChange callback.

  • KevinVandy closed this

  • Sign in to join this conversation.