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

Consider headers in useFetch key #23455

Closed
3 of 4 tasks
hendrikheil opened this issue Sep 28, 2023 · 4 comments · Fixed by #23462
Closed
3 of 4 tasks

Consider headers in useFetch key #23455

hendrikheil opened this issue Sep 28, 2023 · 4 comments · Fixed by #23462

Comments

@hendrikheil
Copy link
Contributor

Describe the feature

We are using Laravel Precognition feature to validate forms server-side before we actually submit them.

By default we use useFetch, and simply add the header required by this feature to perform the validation instead of the actual request.
Since useFetch deduplicates identical requests by default, our validation request is actually the request that gets cached. This means that when we actually want to make the request, we just get our cached response back instantly, which does not actually do anything.

We traced this down to this line

const _key = opts.key || hash([autoKey, unref(opts.method as MaybeRef<string | undefined> | undefined)?.toUpperCase() || 'GET', unref(opts.baseURL), typeof _request.value === 'string' ? _request.value : '', unref(opts.params || opts.query)])

Since we don't actually change the body, url, or params, the cache is hit.

I think it would be sensible to also include the headers in the caching key.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

@danielroe
Copy link
Member

I think this is reasonable 👍

@c-schwan
Copy link
Contributor

I think this is reasonable 👍

I reported that issue a Long time ago with bearer Token in Header Hits the cache

@sisou
Copy link

sisou commented Oct 25, 2023

Ha! This now triggers cache-misses when setting headers with useRequestHeaders, which only populates the headers on server-side, but not client-side: #23900

@ahoiroman
Copy link

Broke my little $larafetch util, as I now get multiple XSRF-cookies back as reported in #23900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants