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

Allow customizing the delay for InstantClick behavior #1164

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davidalejandroaguilar
Copy link
Contributor

@davidalejandroaguilar davidalejandroaguilar commented Feb 5, 2024

Description

This PR adds a configurable delay to the new InstantClick behavior.

The 100 ms default is a nice one. However, some apps might be fine with having no delay and would prefer to prefetch as soon as possible, so let's provide sharp knives.

Configuration

  • Via a data-turbo-prefetch-delay attribute on the <a> element.
  • Via a turbo-prefetch-delay meta tag.

Both can be set to any numerical value, or to "0" for no delay. Note that the latter means that setTimeout won't be used at all, so it will be an instant prefetch.

Notes
I also thought about using "false" instead of "0" for no delay, let me know if that or something else is preferred.

@davidalejandroaguilar davidalejandroaguilar force-pushed the davidramos-customize-delay-for-instant-click-behavior branch from 263365b to cdf89ef Compare February 5, 2024 23:17
@kevinmcconnell
Copy link
Collaborator

@davidalejandroaguilar what would be a use case for someone needing to change the prefetch delay? Do you think there will be cases where the difference is quite noticeable, or the default won't provide a good experience?

I think it's generally good if we can keep Turbo's API simple and small, by only adding attributes/tags that many people are likely to need. If a customisation is not in high demand, it might be better to keep it out of that API. (Which is not to say there couldn't still be a way to affect it in code, if necessary.)

Perhaps this is one of those common needs! But I was struggling to think of a concrete example of needing it, so was curious if you had more context about why the setting needs to be exposed. Thanks!

@afcapel
Copy link
Collaborator

afcapel commented Feb 6, 2024

I agree with @kevinmcconnell. I'd like to see some practical cases where we need this before expanding the public API.

Another thing to note is that we may add InstaClick for keyboard navigation, but that could need different timing. It'd be useful to know what we're going to do with the keyboard events, and if we need different delays for different events, before committing to an API for this.

@davidalejandroaguilar davidalejandroaguilar changed the title Allow customizing the delay for InstantClick behavior Allow disabling the delay for InstantClick behavior Feb 6, 2024
@davidalejandroaguilar davidalejandroaguilar force-pushed the davidramos-customize-delay-for-instant-click-behavior branch from cdf89ef to 28fa3fb Compare February 6, 2024 11:13
@davidalejandroaguilar davidalejandroaguilar force-pushed the davidramos-customize-delay-for-instant-click-behavior branch from 448cdd7 to cdf89ef Compare April 4, 2024 21:22
@davidalejandroaguilar davidalejandroaguilar changed the title Allow disabling the delay for InstantClick behavior Allow customizing the delay for InstantClick behavior Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants