Skip to content

fix(ui): defensive indexed access in getItemIndexAtPosition #93900

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

Merged
merged 2 commits into from
Jun 21, 2025

Conversation

TkDodo
Copy link
Contributor

@TkDodo TkDodo commented Jun 19, 2025

Copy link

sentry-io bot commented Jun 19, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: static/app/components/searchQueryBuilder/hooks/useSelectOnDrag.tsx

Function Unhandled Issue
getItemIndexAtPosition TypeError: undefined is not an object (evaluating 'r.rect') /...
Event Count: 8 Affected Users: 129

Did you find this useful? React with a 👍 or 👎

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jun 19, 2025
@TkDodo TkDodo marked this pull request as ready for review June 19, 2025 17:59
@TkDodo TkDodo requested a review from a team June 19, 2025 17:59
const key = keys[i]!;
const coords = coordinates[key]!;
for (const [i, key] of keys.entries()) {
const coords = coordinates[key];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why we need to allow non block returns :P

Suggested change
const coords = coordinates[key];
const coords = coordinates[key];
if(!coords) continue;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (let i = 0; i < keys.length; i++) {
const key = keys[i]!;
const coords = coordinates[key]!;
for (const [i, key] of keys.entries()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how the rest of the logic works here, but the return value is now no longer guaranteed to be an integer return type, and I don't know if that is something that breaks anything down the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the return value is now no longer guaranteed to be an integer return type

why not? TypeScript still infers the return type as number 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can return -1 if keys is empty but that was the same before as well...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the return value is now no longer guaranteed to be an integer return type

why not? TypeScript still infers the return type as number 🤔

I didn't see that the types still infer an int. That's fine with me then, my intention was to highlight that we used to enforce this at runtime before

@TkDodo TkDodo merged commit 0da7850 into master Jun 21, 2025
44 checks passed
@TkDodo TkDodo deleted the tkdodo/fix/JAVASCRIPT-31AG branch June 21, 2025 08:42
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants