Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

it has performance issue when we drag&drop on a tree with about 500 rows open all #192

Open
btnguyen76 opened this issue Mar 15, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@btnguyen76
Copy link

I'm following the doc, everything is working fine. However if we have a tree with about 500 rows openAll, it's very slow (responsive) when we drag&drop
Do you have any suggestion on how to improve performance?
Thank you!

@btnguyen76 btnguyen76 added the enhancement New feature or request label Mar 15, 2023
@minop1205
Copy link
Owner

@btnguyen76 I recognize the performance challenges.
This issue is a library issue and I will update the library soon to improve it.

At the very least, I can improve it by reducing unnecessary rendering during drag operations.

@btnguyen76
Copy link
Author

yes, When dragging all my custom nodes are keeping re-rendered. Do you know when you are able to improve it by reducing unnecessary rendering during drag operations? Thanks @minop1205

@minop1205
Copy link
Owner

The problem is caused where the top level component in the library is re-rendered during a drag operation.

Therefore, a library modification is required to correct the problem. I am currently working on resolving this issue, but have not yet completed the process.

@JorisPannekeet
Copy link

@minop1205 Any update about this?

@kibertoad
Copy link

@minop1205 Any updates?

@jorgedanisc
Copy link

@minop1205 Are you continuing to work on this?

@yuri2peter
Copy link

yuri2peter commented Aug 16, 2024

Hey everyone! I've uncovered a way to drastically reduce re-renders for our CustomNode component, and in my project, it's resulted in a significant performance boost !

The key is using useFuncImmutable to make the changing handles immutable, allowing React.memo to work.

Hope this helps you out!

type CustomNodeProps = {
  node: TreeNode;
  depth: number;
  isOpen: boolean;
  onToggle: () => void;
  onClick: () => void;
  onCtrlClick: () => void;
};

function useFuncImmutable<T extends (...args: any[]) => any>(fn: T) {
  const ref = React.useRef(fn);
  ref.current = fn;
  return React.useCallback((...args: any[]) => {
    return ref.current(...args);
  }, [])  as T;
}

export const CustomNodeWrapper: React.FC<CustomNodeProps> = (props) => {
  const onToggle = useFuncImmutable(props.onToggle);
  const onClick = useFuncImmutable(props.onClick);
  const onCtrlClick = useFuncImmutable(props.onCtrlClick);
  return (
    <CustomNodeMemo
      {...props}
      {...{
        onToggle,
        onClick,
        onCtrlClick,
      }}
    />
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants