Skip to content

Commit

Permalink
fix: prerendering with Nuxt in v4 compat mode
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Jul 10, 2024
1 parent 843c3bc commit 1c193ae
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/runtime/composables/useApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ export function _useApiData<T = unknown>(
async (nuxt) => {
controller?.abort?.()

// Workaround to persist response client-side
// https://github.com/nuxt/nuxt/issues/15445
if ((nuxt!.isHydrating || cache) && nuxt!.payload.data[_key.value])
return nuxt!.payload.data[_key.value]
if (nuxt && (nuxt.isHydrating || cache) && nuxt.payload.data[_key.value])
return nuxt.payload.data[_key.value]

controller = new AbortController()

Expand Down Expand Up @@ -228,13 +226,13 @@ export function _useApiData<T = unknown>(
}
catch (error) {
// Invalidate cache if request fails
nuxt!.payload.data[_key.value] = undefined
if (nuxt) nuxt.payload.data[_key.value] = undefined

throw error
}

if (cache)
nuxt!.payload.data[_key.value] = result
if (nuxt && cache)
nuxt.payload.data[_key.value] = result

return result
},
Expand Down

0 comments on commit 1c193ae

Please sign in to comment.