plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Modebar button click function does not update on rerender

Open vdgodse opened this issue 4 years ago • 4 comments

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.

vdgodse avatar Jul 02 '21 12:07 vdgodse

Having the same issue, any updates?

l4j3b avatar Apr 07 '22 22:04 l4j3b

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 avatar Jan 19 '24 15:01 NZepeda

@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 avatar Jan 19 '24 15:01 NZepeda

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.

NZepeda avatar Jan 19 '24 19:01 NZepeda

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

gvwilson avatar Jul 12 '24 13:07 gvwilson