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

fix(brush): fix issue 'update was scheduled' warning on resetOnEnd #1465 #1778

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

dsdevgit
Copy link
Contributor

@dsdevgit dsdevgit commented Dec 15, 2023

🐛 Bug Fix

React warns 'An update was scheduled from inside an update function' in case we set resetOnEnd = true or if we call the reset() method imperatively.

The problem:

In short we call setState method inside of updater function of another setState

this.setState(() => {
    // ...
    //...
    this.setState(() => {
        //...
    })
})

In the BaseBrush.ts

  1. updateBrush() calls the setState() method
  2. handleDragEnd() or handleWindowPointerUp() call the updateBrush() with updater function contains reset()
  3. reset() also calls updateBrush()

The Solution:

  1. Move brush "idle" state object to getIdleState() (state of brush if it is not in use)
  2. Avoid calling the setState method again by modifying the state passed in the first call (if resetOnEnd=true we set 'idle' state from getIdleState())
  3. For reset() method, we just call updateBrush() with 'idle' state

Copy link
Collaborator

@williaster williaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @dsdevgit thanks for such a great write-up and PR for a long-outstanding bug ❤️ 🙏

this lgtm, will get it released shortly.

@williaster williaster merged commit 78e6459 into airbnb:master Dec 15, 2023
2 checks passed
Copy link

🎉 This PR is included in version v3.6.1 of the packages modified 🎉

@dsdevgit
Copy link
Contributor Author

dsdevgit commented Dec 15, 2023

Many thanks @williaster

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

Successfully merging this pull request may close these issues.

2 participants