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

DragAndDrop with custom components causes re-mount on each render #2588

Open
5 tasks done
Poky85 opened this issue Apr 26, 2024 · 1 comment
Open
5 tasks done

DragAndDrop with custom components causes re-mount on each render #2588

Poky85 opened this issue Apr 26, 2024 · 1 comment
Labels

Comments

@Poky85
Copy link

Poky85 commented Apr 26, 2024

Check that this is really a bug

  • I confirm

Reproduction link

https://github.com/Poky85/demo-react-big-calendar-issue

Bug description

When using Drag and drop addon in combination with custom components there is an issue with components being recreated on each render.

See the minimal reproduction repo. There I use custom EventWrapper component and log each remount in the console. It remounts although components passed in the prop are stable.

image


react-big-calendar@1.9.1 introduced change in custom components merge. In DragAndDrop class component there was mergeComponents() call moved from constructor to render function. See the pull request here.

This is bad approach. Now custom components gets recomputed on each render. React unmounts previous components and mounts them again because references (component functions) are not stable. This has negative impacts:

  • Performance issue – unmounted components gets removed from the DOM and then are added again. It triggers lot of unnecessary DOM operations.
  • It breaks components lifecycle

Expected Behavior

Custom components should not remount unless the items in components prop changes.

Actual Behavior

Custom components are remounted on each render.

react-big-calendar version

1.9.1

React version

18.3.1

Platform/Target and Browser Versions

macOS 14.2.1 + Chrome 124 / Firefox 125 / Safari 17.2.1

Validations

  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a react-big-calendar issue and not an implementation issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
@TemaTarasov
Copy link

TemaTarasov commented May 29, 2024

We have the same issues, the root cause of the issue is that every render they create new factories of provided components.

I fixed that by moving this.components to a constructor, to provide more general behavior I would move that logic with merging + verification of links inside the shouldComponentUpdate function to prevent additional re-renders along with updating the this.components

...
  shouldComponentUpdate(nextProps, nextState) {
    if (!isEqual(this.props.components, nextProps.components)) {
      this.components = mergeComponents(nextProps.components, {
        eventWrapper: EventWrapper,
        eventContainerWrapper: EventContainerWrapper,
        weekWrapper: WeekWrapper,
      });
    }

    return true;
  }
...

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

No branches or pull requests

2 participants