fix(nuxt): don't refresh when hydrating when data is present (#20916)

This commit is contained in:
Daniel Roe 2023-05-17 14:23:52 +01:00 committed by GitHub
parent d2e14b678b
commit 2cdc22a746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -135,7 +135,7 @@ export function useAsyncData<
(nuxt._asyncDataPromises[key] as any).cancelled = true
}
// Avoid fetching same key that is already fetched
if (opts._initial && hasCachedData()) {
if ((opts._initial || (nuxt.isHydrating && opts._initial !== false)) && hasCachedData()) {
return getCachedData()
}
asyncData.pending.value = true

View File

@ -15,14 +15,14 @@ if (count || data.value !== 1) {
}
timeout = 100
const p = refresh({ dedupe: true })
const p = refresh({ dedupe: true, _initial: false })
if (process.client && (count !== 0 || data.value !== 1)) {
throw new Error('count should start at 0')
}
timeout = 0
await refresh()
await refresh({ _initial: false })
if (process.client && (count !== 1 || data.value !== 1)) {
throw new Error('override should execute')