leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.51k stars 371 forks source link

setSelect hook is called on every click when cursor is coming back to the browser page. #766

Closed lucianbaciu closed 1 year ago

lucianbaciu commented 1 year ago

I have one of the simplest sin chart (one of your example).

hooks: { setSelect: [(uplot) => { console.log('SET SELECT'); }],}

If you click on something outside of the browser, then come back and click the chart, this event will be fired. You can do this as many times as you want. I'm not sure this is a normal behaviour and I think it's not. It is causing issues when dealing with more complex situations like linked charts, ranger, etc. Thank you!

leeoniya commented 1 year ago

i'm not able to reproduce this. can you make a screen rec of it happening with this fiddle?

https://jsfiddle.net/s5vnq2ht/

it only happens on chart init for me, so maybe something in your code is re-initializing the plot?

lucianbaciu commented 1 year ago

Yes. it happens in this fiddle too. I will come back with the rec

lucianbaciu commented 1 year ago

https://user-images.githubusercontent.com/103116491/203511806-4f252e8c-6bb0-4d1e-88d8-e941b57f09ec.mp4

lucianbaciu commented 1 year ago

I did some more testing, and it is triggered when you switch between chrome windows. In this example I just click on the google page, then on the chart, then google, etc.. Every time I get back to the chart the setSelect is called. This happens also when you click on a DevTools window (inspector)

lucianbaciu commented 1 year ago

Tested on Mozilla. It can't be reproduced, so I think we can say it happens just in google chrome

leeoniya commented 1 year ago

i'm not sure what's going on in your case. at least on Linux, Chromium 107 (Incognito) it works okay. i'll try on windows in a bit. the extreme cursor lag in your screen rec is concerning, there should be almost no lag like in my rec below. maybe you have some misbehaving Chrome extensions. try the same in Incognito mode (with all extensions disabled).

https://user-images.githubusercontent.com/43234/203643065-fc9a1de1-18a7-40f3-a334-06ad0ede2ca7.mp4

leeoniya commented 1 year ago

ok, i got it to fail on windows. :bomb: :window:

now need to figure out whose bug it is, mine or Google's.

lucianbaciu commented 1 year ago

glad to hear that! I was planning to test on a different browser. The issues is if you have a ranger, the selection is badly affected.. otherwise I'd ignore it.

leeoniya commented 1 year ago

looks like a Chrome bug, i'll have to put together a minimal repro to file a bug with them.

at least the work-around did not end up being too miserable. should be fixed now, can you try the same fiddle again?

https://github.com/leeoniya/uPlot/blob/27f1aafb2b5d18d61d47441a86a65c6a5d26d7d7/src/uPlot.js#L2733-L2737

lucianbaciu commented 1 year ago

I managed to reproduce it every ~20 clicks (with or without moving to another window). I think it is fine. Most likely this will not happen in a real environment. Thank you!

leeoniya commented 1 year ago

the fix for this broke mobile cursor moves in Chrome-based browsers, so needed another work-around to unbreak it: https://github.com/leeoniya/uPlot/commit/9a3db41d254f80e8be3e44841baf7f35f3ccc85d