Compare commits

...

9 Commits

Author SHA1 Message Date
Rohan Dhimal
f9b003d9cb
Merge c376a1f240 into edc299a043 2024-11-20 06:35:52 -05:00
renovate[bot]
edc299a043
chore(deps): update all non-major dependencies (main) (#29995)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-20 06:35:43 -05:00
renovate[bot]
ad3ab4d310
chore(deps): update all non-major dependencies (main) (#29986)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-19 23:36:17 -05:00
Daniel Roe
c376a1f240
Merge remote-tracking branch 'origin/main' into remove-pending 2024-10-08 16:56:55 +02:00
Rohan Dhimal
902933243f chore: revert the description changes 2024-02-19 20:26:29 +05:45
Rohan Dhimal
898f5d796b Merge branch 'main' of https://github.com/drowhannn/nuxt into remove-pending 2024-02-19 19:37:42 +05:45
Rohan Dhimal
65be561a37 docs: remove pending property from data fetching composables 2024-02-14 21:30:48 +05:45
Rohan Dhimal
9766421739 fix: use status instead of pending 2024-02-14 21:27:37 +05:45
Rohan Dhimal
f2b3806618 feat: remove pending from data fetching composables 2024-02-14 21:20:28 +05:45
8 changed files with 16 additions and 35 deletions

View File

@ -248,7 +248,7 @@ jobs:
TEST_PAYLOAD: ${{ matrix.payload }}
SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }}
- uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
- uses: codecov/codecov-action@985343d70564a82044c1b7fcb84c2fa05405c1a2 # v5.0.4
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
with:
token: ${{ secrets.CODECOV_TOKEN }}

View File

@ -91,7 +91,7 @@
"devalue": "5.1.1",
"eslint": "9.15.0",
"eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-perfectionist": "4.0.2",
"eslint-plugin-perfectionist": "4.0.3",
"eslint-typegen": "0.3.2",
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
"happy-dom": "15.11.6",
@ -118,7 +118,7 @@
"vue-router": "4.4.5",
"vue-tsc": "2.1.10"
},
"packageManager": "pnpm@9.13.2",
"packageManager": "pnpm@9.14.1",
"engines": {
"node": "^16.10.0 || >=18.0.0"
},

View File

@ -106,10 +106,6 @@ export interface AsyncDataExecuteOptions {
export interface _AsyncData<DataT, ErrorT> {
data: Ref<DataT>
/**
* @deprecated Use `status` instead. This may be removed in a future major version.
*/
pending: Ref<boolean>
refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
clear: () => void
@ -249,7 +245,6 @@ export function useAsyncData<
const _ref = options.deep ? ref : shallowRef
nuxtApp._asyncData[key] = {
data: _ref(hasCachedData ? initialCachedData : options.default!()),
pending: ref(!hasCachedData),
error: toRef(nuxtApp.payload._errors, key),
status: ref('idle'),
_default: options.default!,
@ -277,7 +272,6 @@ export function useAsyncData<
return Promise.resolve(cachedData)
}
}
asyncData.pending.value = true
asyncData.status.value = 'pending'
// TODO: Cancel previous promise
const promise = new Promise<ResT>(
@ -322,8 +316,6 @@ export function useAsyncData<
.finally(() => {
if ((promise as any).cancelled) { return }
asyncData.pending.value = false
delete nuxtApp._asyncDataPromises[key]
})
nuxtApp._asyncDataPromises[key] = promise
@ -366,7 +358,6 @@ export function useAsyncData<
if (fetchOnServer && nuxtApp.isHydrating && (asyncData.error.value || typeof initialCachedData !== 'undefined')) {
// 1. Hydration (server: true): no fetch
asyncData.pending.value = false
asyncData.status.value = asyncData.error.value ? 'error' : 'success'
} else if (instance && ((nuxtApp.payload.serverRendered && nuxtApp.isHydrating) || options.lazy) && options.immediate) {
// 2. Initial load (server: false): fetch on mounted
@ -527,7 +518,6 @@ function clearNuxtDataByKey (nuxtApp: NuxtApp, key: string): void {
if (nuxtApp._asyncData[key]) {
nuxtApp._asyncData[key]!.data.value = nuxtApp._asyncData[key]!._default()
nuxtApp._asyncData[key]!.error.value = undefined
nuxtApp._asyncData[key]!.pending.value = false
nuxtApp._asyncData[key]!.status.value = 'idle'
}

View File

@ -126,10 +126,6 @@ interface _NuxtApp {
/** @internal */
_asyncData: Record<string, {
data: Ref<unknown>
/**
* @deprecated This may be removed in a future major version.
*/
pending: Ref<boolean>
error: Ref<Error | undefined>
status: Ref<AsyncDataRequestStatus>
/** @internal */

View File

@ -114,8 +114,8 @@ importers:
specifier: 3.3.0
version: 3.3.0
eslint-plugin-perfectionist:
specifier: 4.0.2
version: 4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
specifier: 4.0.3
version: 4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
eslint-typegen:
specifier: 0.3.2
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
@ -4373,8 +4373,8 @@ packages:
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
engines: {node: '>=5.0.0'}
eslint-plugin-perfectionist@4.0.2:
resolution: {integrity: sha512-zWdgyg2SdHqhp/P9d9vKwo5qD9is28xMAGzBslHqkZz5mVIikjyz1qvuJ4yS7Wrsf4KlbGorORefb4Kbe7Puzg==}
eslint-plugin-perfectionist@4.0.3:
resolution: {integrity: sha512-CyafnreF6boy4lf1XaF72U8NbkwrfjU/mOf1y6doaDMS9zGXhUU1DSk+ZPf/rVwCf1PL1m+rhHqFs+IcB8kDmA==}
engines: {node: ^18.0.0 || >=20.0.0}
peerDependencies:
eslint: '>=8.0.0'
@ -11519,7 +11519,7 @@ snapshots:
eslint-plugin-no-only-tests@3.3.0: {}
eslint-plugin-perfectionist@4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
eslint-plugin-perfectionist@4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
dependencies:
'@typescript-eslint/types': 8.15.0
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)

View File

@ -1,6 +1,6 @@
<template>
<div
v-if="!pending"
v-if="status !== 'pending'"
v-text="'resolved:' + data.resolved"
/>
<div
@ -11,5 +11,5 @@
<script setup>
useNuxtData('call')
const { data, pending } = await useAsyncData('call', () => Promise.resolve({ resolved: true }), { server: false })
const { data, status } = await useAsyncData('call', () => Promise.resolve({ resolved: true }), { server: false })
</script>

View File

@ -17,7 +17,7 @@ const ComponentDefinedInSetup = computed(() => h({
template: compTemplate.value,
}) as Component)
const { data, pending } = await useAsyncData('templates', async () => {
const { data, status } = await useAsyncData('templates', async () => {
const [interactiveComponent, templateString] = await Promise.all([
$fetch('/api/full-component'),
$fetch('/api/template'),
@ -54,7 +54,7 @@ const Interactive = h({
>
{{ count }}
</button>
<template v-if="!pending">
<template v-if="status !== 'pending'">
<Name
id="name"
template="<div>I am the Name.ts component</div>"

View File

@ -131,7 +131,6 @@ describe('useAsyncData', () => {
expect(Object.keys(res)).toMatchInlineSnapshot(`
[
"data",
"pending",
"error",
"status",
"execute",
@ -149,29 +148,25 @@ describe('useAsyncData', () => {
const immediate = await useAsyncData(() => Promise.resolve('test'))
expect(immediate.data.value).toBe('test')
expect(immediate.status.value).toBe('success')
expect(immediate.pending.value).toBe(false)
const nonimmediate = await useAsyncData(() => Promise.resolve('test'), { immediate: false })
expect(nonimmediate.data.value).toBe(undefined)
expect(nonimmediate.status.value).toBe('idle')
expect(nonimmediate.pending.value).toBe(true)
})
it('should capture errors', async () => {
const { data, error, status, pending } = await useAsyncData('error-test', () => Promise.reject(new Error('test')), { default: () => 'default' })
const { data, error, status } = await useAsyncData('error-test', () => Promise.reject(new Error('test')), { default: () => 'default' })
expect(data.value).toMatchInlineSnapshot('"default"')
expect(error.value).toMatchInlineSnapshot('[Error: test]')
expect(status.value).toBe('error')
expect(pending.value).toBe(false)
expect(useNuxtApp().payload._errors['error-test']).toMatchInlineSnapshot('[Error: test]')
// TODO: fix the below
// const { data: syncedData, error: syncedError, status: syncedStatus, pending: syncedPending } = await useAsyncData('error-test', () => ({}), { immediate: false })
// const { data: syncedData, error: syncedError, status: syncedStatus } = await useAsyncData('error-test', () => ({}), { immediate: false })
// expect(syncedData.value).toEqual(null)
// expect(syncedError.value).toEqual(error.value)
// expect(syncedStatus.value).toEqual('idle')
// expect(syncedPending.value).toEqual(true)
})
// https://github.com/nuxt/nuxt/issues/23411
@ -248,9 +243,9 @@ describe('useAsyncData', () => {
it('should use default while pending', async () => {
const promise = useAsyncData(() => Promise.resolve('test'), { default: () => 'default' })
const { data, pending } = promise
const { data, status } = promise
expect(pending.value).toBe(true)
expect(status.value).toBe('pending')
expect(data.value).toMatchInlineSnapshot('"default"')
await promise