schrodinger/fixed-data-table-2

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

MKrutii opened this issue · 2 comments

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

  • Have the table with the lots of items
  • Have the vertical/horizontal scrollbar
  • Click to the very beginning of the scrollbar
  • Observe the error in console

Your Environment

  • Browser Name and version: MS Edge latest / Chrome latest
  • Operating System and version (desktop or mobile): Win 11 x64

Oh good find!
targetTouches is undefined at

getTouchX = (/*object*/ e) => {
return Math.round(
e.targetTouches[0].clientX - e.target.getBoundingClientRect().x
);
};
getTouchY = (/*object*/ e) => {
return Math.round(
e.targetTouches[0].clientY - e.target.getBoundingClientRect().y
);
};

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

let position = this.state.isHorizontal
? nativeEvent.offsetX ||
nativeEvent.layerX ||
this.getTouchX(nativeEvent)
: nativeEvent.offsetY ||
nativeEvent.layerY ||
this.getTouchY(nativeEvent);

We should instead use the ?? operator for cases like this.
I'll put a quick fix.

Fixed via #724 and released with v2.0.12.