Skip to content

Conversation

@Suntgr
Copy link
Contributor

@Suntgr Suntgr commented Jan 11, 2026

Fixes #92

Problem

The toggleCollapsed method in ArrayGroup component has a bug when handling sparse arrays. When this.state.expanded is a sparse array (e.g., only some indices are set to true while others are undefined), expanding and collapsing groups may trigger the wrong group to collapse or expand. This causes state inconsistencies where clicking on one group affects other groups unexpectedly.

Root Cause

The original implementation used for...in loop which only iterates over defined indices in sparse arrays. This leads to:

  • Missing indices in the new array
  • Incorrect toggle behavior when switching undefined indices
  • State inconsistencies

Solution

  • Replace for...in with a standard for loop to ensure all required indices are processed
  • Calculate the maximum length needed (current array length or target index + 1)
  • Explicitly initialize undefined indices to false to avoid sparse array issues
  • Use strict equality check (=== true) for clarity

Changes

  • Modified toggleCollapsed method to properly handle sparse arrays
  • Ensures all indices are correctly initialized and toggled

@vercel
Copy link

vercel bot commented Jan 11, 2026

Someone is attempting to deploy a commit to the Microlink Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jan 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
react-json-view Ready Ready Preview, Comment Jan 11, 2026 2:57pm

@Kikobeats
Copy link
Member

amazing, thanks a lot!

@Kikobeats Kikobeats merged commit 7406175 into microlinkhq:master Jan 11, 2026
3 checks passed
@Suntgr Suntgr deleted the fix/toggle-collapsed branch January 11, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large list expansion/collapse the wrong target group

2 participants