Skip to content

Commit

Permalink
fix: don't hash FormData
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Feb 8, 2023
1 parent 3df9e44 commit 71f373c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/runtime/composables/$api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { hash } from 'ohash'
import type { NitroFetchOptions } from 'nitropack'
import { headersToObject, serializeMaybeEncodedBody } from '../utils'
import type { EndpointFetchOptions } from '../utils'
import { isFormData } from '../formData'
import { useNuxtApp } from '#imports'

export type ApiFetchOptions = Pick<
Expand Down Expand Up @@ -29,7 +30,13 @@ export function _$api<T = any>(
const nuxt = useNuxtApp()
const promiseMap: Map<string, Promise<T>> = nuxt._promiseMap = nuxt._promiseMap || new Map()
const { query, headers, method, body, cache = false, ...fetchOptions } = opts
const key = `$party${hash([endpointId, path, query, method, body])}`
const key = `$party${hash([
endpointId,
path,
query,
method,
...(isFormData(body) ? [] : [body]),
])}`

if ((nuxt.isHydrating || cache) && key in nuxt.payload.data)
return Promise.resolve(nuxt.payload.data[key])
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/composables/useApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Ref } from 'vue'
import type { AsyncData, AsyncDataOptions } from 'nuxt/app'
import { headersToObject, resolveUnref, serializeMaybeEncodedBody } from '../utils'
import type { EndpointFetchOptions, MaybeComputedRef } from '../utils'
import { isFormData } from '../formData'
import { useAsyncData } from '#imports'

type ComputedOptions<T extends Record<string, any>> = {
Expand Down Expand Up @@ -93,7 +94,7 @@ export function _useApiData<T = any>(
_path.value,
unref(query),
unref(method),
body,
...(isFormData(body) ? [] : [body]),
])}`)

return useAsyncData<T, FetchError>(
Expand Down

0 comments on commit 71f373c

Please sign in to comment.