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 types and remove use of deprecated browser event prop #1910

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

derrickreimer
Copy link
Contributor

Thanks to some crafty sleuthing by @shengslogar (#1908 (comment)), there are a few things to clean up after #1908:

  • The event we were passing to shouldIntercept from the React adapter was the React synthetic event, which does not have all the properties of the underlying native event. It seems wise to keep the intercept helper function framework-agnostic, so this change now passes the event.nativeEvent to shouldIntercept.
  • The event.which property is deprecated. The purpose it previously served for evaluating MouseEvent eligibility is now covered by the newly-introduced event.button check.
  • I realized TypeScript didn't have my back here to catch the type mismatch mismatch, so I added a type signature to the visit function and expanded the onClick prop signature (since this is a polymorphic element, this may not always be an HTMLAnchorElement).

@@ -67,10 +67,10 @@ const Link = forwardRef<unknown, InertiaLinkProps>(
ref,
) => {
const visit = useCallback(
(event) => {
(event: React.MouseEvent) => {

Choose a reason for hiding this comment

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

Shouldn't this be a mouse or keyboard event? Tabbing onto a link/button and pressing "enter" can trigger a click

Copy link

@shengslogar shengslogar Jun 26, 2024

Choose a reason for hiding this comment

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

I lied. It's still a mouse event. Carry on 😅

@shengslogar
Copy link

Thanks for all your work on this! Lots of learnings over the past few days for me 💪

@derrickreimer
Copy link
Contributor Author

@shengslogar me as well, thanks for collaborating with me on it!

@reinink reinink merged commit dedc932 into master Jun 28, 2024
7 checks passed
@reinink reinink deleted the follow-up-to-1908 branch June 28, 2024 19:09
@reinink
Copy link
Member

reinink commented Jun 28, 2024

Thanks guys!!

derrickreimer added a commit that referenced this pull request Dec 12, 2024
In #1910 (d53b2b3), we switched to passing `event.nativeEvent` to
`shouldIntercept` in an attempt to consistently always pass native
browser events to this framework-agnostic helper. This actually
introduced a bug though, because `currentTarget` is _different_ on
React's synthetic event vs. the underlying native event. The correct
value for `currentTarget` lives on the synthetic event.

Since we are no longer relying on `event.which` (and this is the only
property we used to be concerned with that was not included on the
React synthetic event), we'll simply move back to passing the React
synthetic event to `shouldIntercept`.
derrickreimer added a commit that referenced this pull request Dec 12, 2024
In #1910 (d53b2b3), we switched to passing `event.nativeEvent` to
`shouldIntercept` in an attempt to consistently always pass native
browser events to this framework-agnostic helper. This actually
introduced a bug though, because `currentTarget` is _different_ on
React's synthetic event vs. the underlying native event. The correct
value for `currentTarget` lives on the synthetic event.

Since we are no longer relying on `event.which` (and this is the only
property we used to be concerned with that was not included on the
React synthetic event), we'll simply move back to passing the React
synthetic event to `shouldIntercept`.
reinink pushed a commit that referenced this pull request Dec 13, 2024
In #1910 (d53b2b3), we switched to passing `event.nativeEvent` to
`shouldIntercept` in an attempt to consistently always pass native
browser events to this framework-agnostic helper. This actually
introduced a bug though, because `currentTarget` is _different_ on
React's synthetic event vs. the underlying native event. The correct
value for `currentTarget` lives on the synthetic event.

Since we are no longer relying on `event.which` (and this is the only
property we used to be concerned with that was not included on the
React synthetic event), we'll simply move back to passing the React
synthetic event to `shouldIntercept`.
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.

4 participants