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

fix: typescript strict on to prevent null calls #477

Merged
merged 4 commits into from
Oct 13, 2024

Conversation

maiconcarraro
Copy link
Contributor

@maiconcarraro maiconcarraro commented Oct 7, 2024

fixes #476

the root cause was about a missing check caused by event possibly null, suggesting to keep strict: true in tsconfig to help prevent these bugs, included the fixes to keep it on.

image

@@ -205,7 +206,7 @@ export function useSnapPoints({
const dragDirection = hasDraggedUp ? 1 : -1; // 1 = up, -1 = down

// Don't do anything if we swipe upwards while being on the last snap point
if (dragDirection > 0 && isLastSnapPoint) {
if (dragDirection > 0 && isLastSnapPoint && snapPoints) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

its using snapPoints inside

@@ -60,7 +60,7 @@ export function useSnapPoints({
);

const activeSnapPointIndex = React.useMemo(
() => snapPoints?.findIndex((snapPoint) => snapPoint === activeSnapPoint),
() => snapPoints?.findIndex((snapPoint) => snapPoint === activeSnapPoint) ?? null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prevent undefined checks

@@ -1005,8 +1011,10 @@ export const Handle = React.forwardRef<HTMLDivElement, HandleProps>(function (
// Make sure to clear the timeout id if the user releases the handle before the cancel timeout
handleCancelInteraction();

if ((!snapPoints || snapPoints.length === 0) && dismissible) {
closeDrawer();
if (!snapPoints || snapPoints.length === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

right below this condition there is a call to snapPoints.length and overall there is no effect having an empty array (would return on line 1029)... so returning early

src/index.tsx Outdated
pointerStartRef.current = null;
wasBeyondThePointRef.current = false;
onRelease(event);
if (event) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the actual fix to the opened issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% sure on this one, the safest approach would be to handle the null check inside of the onRelease so we can still set isDragging to false, lmk what you prefer.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's go with the safer approach.

Copy link
Contributor Author

@maiconcarraro maiconcarraro Oct 8, 2024

Choose a reason for hiding this comment

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

@emilkowalski done, but playwright had a flaky test, I'm investigating if it's a regression: https://github.com/emilkowalski/vaul/actions/runs/11240999977/job/31251582106?pr=477

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like intermittent, locally it passes (not always)... maybe related to the animation timeout?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only flask/intermittent, nothing that I could find, lmk if you want me to check a specific case.

@emilkowalski emilkowalski merged commit 1a8d000 into emilkowalski:main Oct 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentry: null is not an object (evaluating 't.target')
2 participants