schrodinger / fixed-data-table-2

A React table component designed to allow presenting millions of rows of data.
http://schrodinger.github.io/fixed-data-table-2/
Other
1.29k stars 289 forks source link

Type error if to click at the very beginning of the scrollbar with lots of items #723

Closed MKrutii closed 4 months ago

MKrutii commented 4 months ago

Noticed an issue that cause error in the console/rollbar

screen_2 screen_1

Expected Behavior

No errors in the console

Current Behavior

TypeError: Cannot read properties of undefined (reading '0')
    at t.getTouchY (Scrollbar.js:572:9)
    at Scrollbar.js:374:16
    at Object.Va (react-dom.production.min.js:52:317)
    at Za (react-dom.production.min.js:52:471)
    at react-dom.production.min.js:53:35
    at Ao (react-dom.production.min.js:100:68)
    at Co (react-dom.production.min.js:101:380)
    at react-dom.production.min.js:113:65
    at Ra (react-dom.production.min.js:292:189)
    at react-dom.production.min.js:50:57 

Possible Solution

For some reason targetTouches is undefined, the logic might be improved to have the optional chaining or other solution

Steps to Reproduce (for bugs)

Can be reproducible in the examples page

Your Environment

pradeepnschrodinger commented 4 months ago

Oh good find! targetTouches is undefined at https://github.com/schrodinger/fixed-data-table-2/blob/522e82be907c41c250b231a76e3127abed9aed81/src/plugins/Scrollbar.js#L527-L537 because we're actually doing a normal mouse click instead of a "touch" click. But the code shouldn't have reached here in the first place.

The root problem is that FDT thinks it's a touch event because of the way we use the || operator in https://github.com/schrodinger/fixed-data-table-2/blob/522e82be907c41c250b231a76e3127abed9aed81/src/plugins/Scrollbar.js#L358-L364 We should instead use the ?? operator for cases like this. I'll put a quick fix.

pradeepnschrodinger commented 4 months ago

Fixed via #724 and released with v2.0.12.