Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt)!: include request url and params in useFetch key #6632

Merged
merged 5 commits into from
Nov 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: hash url key
  • Loading branch information
danielroe committed Nov 15, 2022
commit c9ef662152e5ca429552577640ebf94480de78f9
3 changes: 2 additions & 1 deletion packages/nuxt/src/app/composables/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FetchError, FetchOptions } from 'ofetch'
import type { TypedInternalResponse, NitroFetchRequest } from 'nitropack'
import { computed, unref, Ref, reactive } from 'vue'
import { withBase, withQuery } from 'ufo'
import { hash } from 'ohash'
import type { AsyncDataOptions, _Transform, KeyOfRes, AsyncData, PickFrom } from './asyncData'
import { useAsyncData } from './asyncData'

Expand Down Expand Up @@ -45,7 +46,7 @@ export function useFetch<
arg2?: string
) {
const [opts = {}, autoKey] = typeof arg1 === 'string' ? [{}, arg1] : [arg1, arg2]
const _key = opts.key || typeof request === 'string' ? withBase(unref(opts.baseURL) || '', withQuery(request as string, unref(opts.params) || {})) : autoKey
const _key = opts.key || (typeof request === 'string' ? hash(withBase(unref(opts.baseURL) || '', withQuery(request as string, unref(opts.params) || {}))) : autoKey)
pi0 marked this conversation as resolved.
Show resolved Hide resolved
if (!_key || typeof _key !== 'string') {
throw new TypeError('[nuxt] [useFetch] key must be a string: ' + _key)
}
Expand Down