From 55e0f38dde4d9f3a0f1588a095599946336821d1 Mon Sep 17 00:00:00 2001 From: webfansplz <308241863@qq.com> Date: Thu, 16 Nov 2023 22:04:48 +0800 Subject: [PATCH] fix(nuxt): do not compute `useFetch` key from headers (reverts #23462) (#24333) --- packages/nuxt/src/app/composables/fetch.ts | 4 ++-- test/nuxt/composables.test.ts | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index a18934b301..85256a59b2 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -211,12 +211,12 @@ function generateOptionSegments <_ResT, DataT, DefaultT>(opts: UseFetchOptions<_ toValue(opts.method as MaybeRef | 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 = {} - 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) } diff --git a/test/nuxt/composables.test.ts b/test/nuxt/composables.test.ts index 6086ea5102..fc80b96f98 100644 --- a/test/nuxt/composables.test.ts +++ b/test/nuxt/composables.test.ts @@ -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) }) })