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

fix(nuxt): do not compute useFetch key from headers (reverting #23462) #24333

Merged
merged 2 commits into from Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/composables/fetch.ts
Expand Up @@ -211,12 +211,12 @@ function generateOptionSegments <_ResT, DataT, DefaultT>(opts: UseFetchOptions<_
toValue(opts.method as MaybeRef<string | undefined> | undefined)?.toUpperCase() || 'GET',
toValue(opts.baseURL),
]
for (const _obj of [opts.params || opts.query, opts.headers]) {
for (const _obj of [opts.params || opts.query]) {
const obj = toValue(_obj)
if (!obj) { continue }

const unwrapped: Record<string, string> = {}
const iterator = Array.isArray(obj) ? obj : obj instanceof Headers ? obj.entries() : Object.entries(obj)
const iterator = Array.isArray(obj) ? obj : Object.entries(obj)
for (const [key, value] of iterator) {
unwrapped[toValue(key)] = toValue(value)
}
Expand Down
14 changes: 4 additions & 10 deletions test/nuxt/composables.test.ts
Expand Up @@ -257,19 +257,13 @@ describe('useFetch', () => {
expect.soft(getPayloadEntries()).toBe(baseCount + 2)

/* @ts-expect-error Overriding auto-key */
await useFetch('/api/test', { headers: { id: '3' } }, '')
await useFetch('/api/test', { query: { id: '3' } }, '')
/* @ts-expect-error Overriding auto-key */
await useFetch('/api/test', { headers: { id: ref('3') } }, '')
const headers = new Headers()
headers.append('id', '3')
await useFetch('/api/test', { query: { id: ref('3') } }, '')
/* @ts-expect-error Overriding auto-key */
await useFetch('/api/test', { headers }, '')
await useFetch('/api/test', { params: { id: '3' } }, '')
/* @ts-expect-error Overriding auto-key */
await useFetch('/api/test', { headers: [['id', '3']] }, '')
/* @ts-expect-error Overriding auto-key */
await useFetch('/api/test', { headers: [['id', ref('3')]] }, '')
/* @ts-expect-error Overriding auto-key */
await useFetch('/api/test', { headers: [[computed(() => 'id'), '3']] }, '')
await useFetch('/api/test', { params: { id: ref('3') } }, '')
expect.soft(getPayloadEntries()).toBe(baseCount + 3)
})
})
Expand Down