Skip to content

Modebar button click function does not update on rerender #5796

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

Closed
vdgodse opened this issue Jul 2, 2021 · 4 comments
Closed

Modebar button click function does not update on rerender #5796

vdgodse opened this issue Jul 2, 2021 · 4 comments

Comments

@vdgodse
Copy link

vdgodse commented Jul 2, 2021

https://codepen.io/vdgodse/pen/ExmjGLN

In plotly we can provide config as: modeBarButtonsToAdd: [
{
name: 'button1',
icon: Plotly.Icons.pencil,
direction: 'up',
click: function(gd) {
// this does not update on rerender and always holds the stale react state in closure as shown in the codepen demo
}
}],

Click on the pencil icon to see alert with realCount and staleCount. Since second click the counts diverge.

@NZepeda
Copy link

NZepeda commented Jan 19, 2024

Hello, I'm also facing the same issue with the latest version (2.27.0). It seems like this is still a bug within Plotly.js.

@NZepeda
Copy link

NZepeda commented Jan 19, 2024

@vdgodse Can you please add the type:bug label on this issue so that it is visible under the bugs filter? This is still a legit issue and it would be nice to get more visibility on it. In the meantime, I'll look into a fix.

@NZepeda
Copy link

NZepeda commented Jan 19, 2024

I believe I have a found a workaround for this. When calculating whether to redraw the modebar or not, plotly compares the buttons via their name propery. So if you do some thing like:

{
    modeBarButtonsToAdd: [
      {
        title: "My custom modebar button",
        name: `custom-button-name-${key-that-changes-when-I-need-to}`,
        icon,
        click: onClick,
      },
    ],
  }

It will redraw the modebar thus refresh the button click handler.

@gvwilson
Copy link
Contributor

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

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

No branches or pull requests

3 participants