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 to override turbo fetch response (or export FetchRequest class) #898

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

Conversation

omohokcoj
Copy link

@omohokcoj omohokcoj commented Mar 23, 2023

I'm attempting to implement http://instantclick.io functionality (prefetch on link hover) in my turbo app - one of the ways to implement it is via turbo:before-fetch-request event handler with the ability to override turbo fetch response:
8de3c39

https://gist.github.com/omohokcoj/781a18b3615e4e721ae5fa7f5d5c44ec (prefetch on hover implementation on top of the turbo:before-fetch-request event)

Another way to implement it is via the FetchRequest class monkey patch (not exported in turbo currently).

Would appreciate it a lot if any of those two commits (or both) could be merged and released in the next version.

Related issue: #174

@omohokcoj omohokcoj changed the title export FetchRequest class Allow to override turbo fetch response (export FetchRequest class) Mar 23, 2023
@omohokcoj omohokcoj changed the title Allow to override turbo fetch response (export FetchRequest class) Allow to override turbo fetch response (or export FetchRequest class) Mar 23, 2023
@davidalejandroaguilar
Copy link
Contributor

@omohokcoj This PR might be of interest #1000, since it touches the same files as this PR.

@davidalejandroaguilar
Copy link
Contributor

@seanpdoyle @dhh Have you guys looked at this?

Oleksandr and Pete from Docuseal (Open Source Document Signing built with Rails and Turbo) added a Turbo version of Instantclick, and the perceived speed benefits are simply amazing (they can be experienced on their page.

@dhh
Copy link
Member

dhh commented Sep 23, 2023

I'd like to see us add instaclick functionality straight into Turbo, if anyone feels like investigating that.

@shiftyp
Copy link
Contributor

shiftyp commented Sep 23, 2023

Maybe a good place to “start”

start() {
this.element.addEventListener("click", this.clickBubbled)
document.addEventListener("turbo:click", this.linkClicked)
document.addEventListener("turbo:before-visit", this.willVisit)
}
stop() {
this.element.removeEventListener("click", this.clickBubbled)
document.removeEventListener("turbo:click", this.linkClicked)
document.removeEventListener("turbo:before-visit", this.willVisit)
}

start() {
if (!this.started) {
this.eventTarget.addEventListener("click", this.clickCaptured, true)
this.started = true
}
}
stop() {
if (this.started) {
this.eventTarget.removeEventListener("click", this.clickCaptured, true)
this.started = false
}
}

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.

4 participants