Skip to content

shouldExpandNodeInitially causes a confusing visual bug where the array looks like an empty array, objects behave similar #76

Closed

Description

@Seigiard

shouldExpandNodeInitially works, but it causes a confusing visual bug where the array looks like an empty array.

Also user should click it twice to open it.

How it looks now:
Image

Expecting
Image

Also, it works strangely with objects.

How it looks now:
Image

Expecting
Image

Video
https://github.com/user-attachments/assets/b93b19b8-26a0-4c2b-add8-ac3628ad1591

Playground:
https://stackblitz.com/edit/vitejs-vite-jnppc39x?file=src%2FApp.tsx

Activity

  1. added a commit that references this issue on Aug 16, 2025
  2. jaywcjlove commented on Aug 16, 2025

    @jaywcjlove
    Member
    react-json-view

    const shouldExpandNodeInitially: ShouldExpandNodeInitially<object> = (isExpanded, props) => {
    const { value, level, keyName, parentValue, keys } = props;
    console.log('~~~~:', keyName, level, parentValue, keys);
    const isArray = Array.isArray(value);
    const isObject = typeof value === 'object' && !isArray;
    if (isArray) {
    return isExpanded || value.length > 5;
    }
    if (isObject && level > 3) {
    return isExpanded || true; // Expand if it's an object and level is greater than 3
    }
    return isExpanded;
    };
    export default function App() {
    return <JsonView value={example} displayObjectSize={false} shouldExpandNodeInitially={shouldExpandNodeInitially} />;
    }

    @Seigiard Looks like I’ve fixed it

  3. Seigiard commented on Aug 23, 2025

    @Seigiard
    Author

    Confirmed! Works like a charm!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions