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

Don't call callbacks from this.setState() to avoid double rendering #298

Open
eldargab opened this issue Dec 23, 2019 · 2 comments · May be fixed by #302
Open

Don't call callbacks from this.setState() to avoid double rendering #298

eldargab opened this issue Dec 23, 2019 · 2 comments · May be fixed by #302
Labels
enhancement New feature or request fresh

Comments

@eldargab
Copy link

Hello, I noticed that react-calendar notifies parent component about various events via .setState() callback.

E.g.

this.setState({ value: nextValue }, callback);

The problem is that.setState() callback is called after react finishes real DOM updates. That means, changes from parent component will cause another update cycle. Also parent component might remove calendar in response to event entirely making previous update completely useless.

You can verify such behaviour via DevTools profiler

image

In the screenshot above all the work before Lifecycle hook scheduled a cascading update is completely useless and causes substantial delay.

Another reason not to use .setState() for parent callbacks is to avoid crashing entire app in case parent event handler erroneously raises exception.

@wojtekmaj
Copy link
Owner

Hmmm, if we moved this to the beginning of the function then we would potentially start two asynchronous updates - one via onChange & props, one internal via state. That would be even worse, I think?

@eldargab
Copy link
Author

eldargab commented Jan 2, 2020

No, there would be only one update incorporating both props and state changes.

This is what currently happens with react-calendar/sample/parcel app.

image

On other hand, immediate invocation of onChange callback yields the following picture

image

PR #302 illustrates proposed changes.

@github-actions github-actions bot added the stale label Nov 15, 2021
@wojtekmaj wojtekmaj reopened this Nov 30, 2021
@wojtekmaj wojtekmaj added enhancement New feature or request and removed stale labels Nov 30, 2021
@github-actions github-actions bot added the stale label Mar 7, 2022
@wojtekmaj wojtekmaj reopened this Mar 21, 2022
@wojtekmaj wojtekmaj added fresh and removed stale labels Mar 21, 2022
@wojtekmaj wojtekmaj linked a pull request Mar 21, 2022 that will close this issue
Repository owner deleted a comment from github-actions bot Mar 21, 2022
Repository owner deleted a comment from github-actions bot Mar 21, 2022
Repository owner deleted a comment from github-actions bot Mar 21, 2022
Repository owner deleted a comment from github-actions bot Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fresh
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants