Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MKrutii opened this issue Jun 17, 2024 · 2 comments · Fixed by #724
Closed

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

MKrutii opened this issue Jun 17, 2024 · 2 comments · Fixed by #724
Assignees
Labels

Comments

@MKrutii
Copy link

MKrutii commented Jun 17, 2024

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
@pradeepnschrodinger
Copy link
Collaborator

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.

@pradeepnschrodinger
Copy link
Collaborator

Fixed via #724 and released with v2.0.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants