-
Notifications
You must be signed in to change notification settings - Fork 541
Support touchstart, focus, blur events in link prefetch
#2134
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
Conversation
|
|
||
| const regularEvents = { | ||
| onClick: (event) => { | ||
| onClick: (event: Parameters<InertiaLinkProps['onClick']>[0]) => { |
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.
This looks a bit ugly but it's basically reusing the type of the first parameter of the onClick property defined in InertiaLinkProps above
| blur: regularEvents.mouseleave, | ||
| click: regularEvents.click, | ||
| } | ||
| } satisfies ActionEventHandlers |
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.
I replaced the type assignment with the satisfies operator to make autocomplete smarter. Now typescript knows which properties from ActionEventHandlers are defined and which aren't while still validating the types are correct.
| await page.getByRole('link', { name: 'On Mount' }).click() | ||
| await isPrefetchPage(page, 2) | ||
| await expect(requests.requests.length).toBe(0) | ||
| expect(requests.requests.length).toBe(0) |
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.
awaits here were not necessary, expect().toBe() doesn't return a promise, it's all synchronous
4d726f2 to
c9e0aa2
Compare
joetannenbaum
left a comment
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.
This looks cool, I just have a couple of questions here that I need clarification on. Thanks!
packages/core/src/shouldIntercept.ts
Outdated
| @@ -1,9 +1,9 @@ | |||
| export default function shouldIntercept(event: MouseEvent | KeyboardEvent): boolean { | |||
| export default function shouldIntercept(event: MouseEvent | KeyboardEvent | import('react').MouseEvent<Element>): boolean { | |||
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.
Might be a silly question, but doesn't this make react a dependency in the core library now?
| } | ||
|
|
||
| const prefetchHoverEvents = { | ||
| onMouseEnter: () => { |
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 did you move these events into the regularEvents? These shouldn't be fired if they don't intend to prefetch, correct?
|
@m5r Thanks for this, looks like a great PR! Could you maybe check out Joe's comments about the React import and the |
|
I'm closing this pull request due to lack of activity. If you're still working on this or have updates to share, feel free to open a new PR. We'd be happy to take another look. Thanks! |
Add support for
touchstart,focus, andblurevents in link prefetchhoverbehavior.This is hugely inspired from React Router's link prefetching code. Their event handlers composition is pretty neat too but I don't think it's necessary here.