-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat: bypass Link click handler if alt click or defaultPrevented #1249
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
I think this is a draft until we create an e2e test. |
ed3d6aa
to
08e2b4d
Compare
packages/waku/src/router/client.ts
Outdated
if (!isAltClick) { | ||
event.preventDefault(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can it be this?
if (isAltClick) {
return;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That skips the onClick prop. What do you think about firing the onClick prop first? React Router does that and then doesn't run the internal handler if the onClick calls preventDefault().
https://github.com/remix-run/react-router/blob/react-router%407.2.0/packages/react-router/lib/dom/lib.tsx#L628-L635
function handleClick(
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
) {
if (onClick) onClick(event);
if (!event.defaultPrevented) {
internalOnClick(event);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that looks great. Any drawbacks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I can think of. It looks good to me. I'm traveling for the next few days so I probably won't push another update until the beginning of next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last two weeks flew by 😅 But yes, I was also just looking at the open issues and would like to get all of these loose ends wrapped up asap.
08e2b4d
to
1bcc4b4
Compare
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
1bcc4b4
to
7d85d80
Compare
packages/waku/src/router/client.ts
Outdated
@@ -81,6 +81,13 @@ const parseRouteFromLocation = (): RouteProps => { | |||
return parseRoute(new URL(window.location.href)); | |||
}; | |||
|
|||
function isAltClick(event: MouseEvent<HTMLAnchorElement>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make it an arrow function? (Just a preference)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All set
packages/waku/src/router/client.ts
Outdated
@@ -265,8 +272,7 @@ export function Link({ | |||
}; | |||
} | |||
}, [unstable_prefetchOnView, router, to]); | |||
const onClick = (event: MouseEvent<HTMLAnchorElement>) => { | |||
event.preventDefault(); | |||
const internalOnClick = (_event: MouseEvent<HTMLAnchorElement>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not confusing without it.
const internalOnClick = (_event: MouseEvent<HTMLAnchorElement>) => { | |
const internalOnClick = () => { |
@@ -265,8 +272,7 @@ export function Link({ | |||
}; | |||
} | |||
}, [unstable_prefetchOnView, router, to]); | |||
const onClick = (event: MouseEvent<HTMLAnchorElement>) => { | |||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this causes e2e tests to fail, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was a mistake. I thought I moved it, not deleted.
Fixes #1248.