Skip to content

Dispatch turbo:before-fetch-{request,response} during preloading#1034

Merged
afcapel merged 1 commit intohotwired:mainfrom
seanpdoyle:preload-fetch-request
Dec 14, 2023
Merged

Dispatch turbo:before-fetch-{request,response} during preloading#1034
afcapel merged 1 commit intohotwired:mainfrom
seanpdoyle:preload-fetch-request

Conversation

@seanpdoyle
Copy link
Copy Markdown
Contributor

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.

seanpdoyle added a commit to seanpdoyle/turbo-site that referenced this pull request Oct 12, 2023
Documents [@hotwired/turbo#1034][]

Document the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events dispatched during `<a>` preloading.

[@hotwired/turbo#1034]: hotwired/turbo#1034
@seanpdoyle seanpdoyle force-pushed the preload-fetch-request branch from 0ca4e35 to e24b91e Compare November 16, 2023 17:02
@seanpdoyle seanpdoyle force-pushed the preload-fetch-request branch from e24b91e to f214f61 Compare December 8, 2023 17:22
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 seanpdoyle force-pushed the preload-fetch-request branch from f214f61 to 6791cde Compare December 8, 2023 17:24
@seanpdoyle
Copy link
Copy Markdown
Contributor Author

@afcapel this is rebased off #1033 and ready for review.

@afcapel afcapel merged commit af16eee into hotwired:main Dec 14, 2023
@afcapel
Copy link
Copy Markdown
Collaborator

afcapel commented Dec 14, 2023

Makes sense, thanks @seanpdoyle 👍

@seanpdoyle seanpdoyle deleted the preload-fetch-request branch December 14, 2023 16:05
afcapel added a commit to pfeiffer/turbo that referenced this pull request Jan 29, 2024
* origin/main:
  Introduce `turbo:{before-,}morph-{element,attribute}` events
  Turbo 8.0.0-beta.4
  Introduce data-turbo-track="dynamic" (hotwired#1140)
  Ensure that the turbo-frame header is not sent when the turbo-frame has a target of _top (hotwired#1138)
  Turbo 8.0.0-beta.3
  Fix attribute name (hotwired#1134)
  Add InstantClick behavior (hotwired#1101)
  Revert hotwired#926. (hotwired#1126)
  Keep Trix dynamic styles in the head (hotwired#1133)
  Remove unused stylesheets when navigating (hotwired#1128)
  Upgrade idiomorph to 0.3.0 (hotwired#1122)
  Debounce page refreshes triggered via Turbo streams
  Update copyright year to 2024 (hotwired#1118)
  Turbo 8.0.0-beta.2
  Set aria-busy on the form element during a form submission (hotwired#1110)
  Dispatch `turbo:before-fetch-{request,response}` during preloading (hotwired#1034)
seanpdoyle added a commit to seanpdoyle/turbo-site that referenced this pull request Feb 20, 2024
Documents [@hotwired/turbo#1034][]

Document the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events dispatched during `<a>` preloading.

[@hotwired/turbo#1034]: hotwired/turbo#1034
@seanpdoyle
Copy link
Copy Markdown
Contributor Author

@afcapel I've opened hotwired/turbo-site#151 to document this behavior.

seanpdoyle added a commit to seanpdoyle/turbo-site that referenced this pull request Feb 20, 2024
Documents [@hotwired/turbo#1034][]

Document the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events dispatched during `<a>` preloading.

[@hotwired/turbo#1034]: hotwired/turbo#1034
afcapel pushed a commit to hotwired/turbo-site that referenced this pull request Feb 22, 2024
Documents [@hotwired/turbo#1034][]

Document the `turbo:before-fetch-request` and
`turbo:before-fetch-response` events dispatched during `<a>` preloading.

[@hotwired/turbo#1034]: hotwired/turbo#1034
domchristie pushed a commit to domchristie/turbo that referenced this pull request 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 this pull request may close these issues.

Preloader does not use FetchRequest and therefore does not trigger events

2 participants