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

Preloader does not use FetchRequest and therefore does not trigger events #963

Closed
sascha-egerer opened this issue Aug 17, 2023 · 1 comment · Fixed by #1034
Closed

Preloader does not use FetchRequest and therefore does not trigger events #963

sascha-egerer opened this issue Aug 17, 2023 · 1 comment · Fixed by #1034

Comments

@sascha-egerer
Copy link

When using data-turbo-preload the FetchRequest implementation is not used but a native fetch(). See

const response = await fetch(location.toString(), { headers: { "VND.PREFETCH": "true", Accept: "text/html" } })

So the preload function will not trigger any events and is therefore useless in some cases e.g. if fetchOptions are set in turbo:before-fetch-request

Expected behavior: Preload function should trigger fetch events like turbo:before-fetch-request

seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Oct 12, 2023
Closes [hotwired#963][]

Replace the raw call to `fetch` with a new `FetchRequest` instance that
treats the `Preloaded` instances as its delegate. During that request's
lifecycle, dispatch the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events with the `<a>` element as its
target.

Prepare the request with the [Sec-Purpose][] header in the
`prepareRequest` delegate callback.

Write to the snapshot cache from within the
`requestSucceededWithResponse` delegate callback.

[hotwired#963]: hotwired#963
[Sec-Purpose]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch
@seanpdoyle
Copy link
Contributor

Thank you for opening this issue! I've opened #1034 to implement this behavior, and I've opened hotwired/turbo-site#151 to document it.

seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Nov 16, 2023
Closes [hotwired#963][]

Replace the raw call to `fetch` with a new `FetchRequest` instance that
treats the `Preloaded` instances as its delegate. During that request's
lifecycle, dispatch the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events with the `<a>` element as its
target.

Prepare the request with the [Sec-Purpose][] header in the
`prepareRequest` delegate callback.

Write to the snapshot cache from within the
`requestSucceededWithResponse` delegate callback.

[hotwired#963]: hotwired#963
[Sec-Purpose]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch
seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Dec 8, 2023
Closes [hotwired#963][]

Replace the raw call to `fetch` with a new `FetchRequest` instance that
treats the `Preloaded` instances as its delegate. During that request's
lifecycle, dispatch the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events with the `<a>` element as its
target.

Prepare the request with the [Sec-Purpose][] header in the
`prepareRequest` delegate callback.

Write to the snapshot cache from within the
`requestSucceededWithResponse` delegate callback.

[hotwired#963]: hotwired#963
[Sec-Purpose]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch
seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Dec 8, 2023
Closes [hotwired#963][]

Replace the raw call to `fetch` with a new `FetchRequest` instance that
treats the `Preloaded` instances as its delegate. During that request's
lifecycle, dispatch the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events with the `<a>` element as its
target.

Prepare the request with the [Sec-Purpose][] header in the
`prepareRequest` delegate callback.

Write to the snapshot cache from within the
`requestSucceededWithResponse` delegate callback.

[hotwired#963]: hotwired#963
[Sec-Purpose]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch
afcapel pushed a commit that referenced this issue Dec 14, 2023
…1034)

Closes [#963][]

Replace the raw call to `fetch` with a new `FetchRequest` instance that
treats the `Preloaded` instances as its delegate. During that request's
lifecycle, dispatch the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events with the `<a>` element as its
target.

Prepare the request with the [Sec-Purpose][] header in the
`prepareRequest` delegate callback.

Write to the snapshot cache from within the
`requestSucceededWithResponse` delegate callback.

[#963]: #963
[Sec-Purpose]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch
domchristie pushed a commit to domchristie/turbo that referenced this issue Jul 20, 2024
…otwired#1034)

Closes [hotwired#963][]

Replace the raw call to `fetch` with a new `FetchRequest` instance that
treats the `Preloaded` instances as its delegate. During that request's
lifecycle, dispatch the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events with the `<a>` element as its
target.

Prepare the request with the [Sec-Purpose][] header in the
`prepareRequest` delegate callback.

Write to the snapshot cache from within the
`requestSucceededWithResponse` delegate callback.

[hotwired#963]: hotwired#963
[Sec-Purpose]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose#prefetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants