Modebar button click function does not update on rerender
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.
Having the same issue, any updates?
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.
@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.
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.
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