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

[1.x] Restore command + click behavior on Inertia links in React #2132

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

derrickreimer
Copy link
Contributor

@derrickreimer derrickreimer commented 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.

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 derrickreimer changed the title Restore command + click behavior on Inertia links in React [1.x] Restore command + click behavior on Inertia links in React Dec 12, 2024
@derrickreimer derrickreimer linked an issue Dec 12, 2024 that may be closed by this pull request
event: Pick<
MouseEvent,
'altKey' | 'ctrlKey' | 'defaultPrevented' | 'target' | 'currentTarget' | 'metaKey' | 'shiftKey' | 'button'
>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There might be a more elegant way to do this? I didn't want to introduce a dependency on React type definitions in the core package (to make this a union type), so figured the next best thing was to narrow this down to accommodate both native and synthetic event shapes.

I confirmed that TypeScript will fail if this is type is just a MouseEvent, since React.MouseEvent contains some different stuff.

@reinink reinink merged commit 4737a05 into v1 Dec 13, 2024
7 checks passed
@reinink reinink deleted the restore-cmd-click-in-react branch December 13, 2024 01:07
@joelstein
Copy link

Thanks!

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.

Can't command + click Inertia links to open them in a new tab
3 participants