mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
Compare commits
9 Commits
9d4f4d18ab
...
f9b003d9cb
Author | SHA1 | Date | |
---|---|---|---|
|
f9b003d9cb | ||
|
edc299a043 | ||
|
ad3ab4d310 | ||
|
c376a1f240 | ||
|
902933243f | ||
|
898f5d796b | ||
|
65be561a37 | ||
|
9766421739 | ||
|
f2b3806618 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -248,7 +248,7 @@ jobs:
|
|||||||
TEST_PAYLOAD: ${{ matrix.payload }}
|
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' }}
|
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'
|
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
"devalue": "5.1.1",
|
"devalue": "5.1.1",
|
||||||
"eslint": "9.15.0",
|
"eslint": "9.15.0",
|
||||||
"eslint-plugin-no-only-tests": "3.3.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",
|
"eslint-typegen": "0.3.2",
|
||||||
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
||||||
"happy-dom": "15.11.6",
|
"happy-dom": "15.11.6",
|
||||||
@ -118,7 +118,7 @@
|
|||||||
"vue-router": "4.4.5",
|
"vue-router": "4.4.5",
|
||||||
"vue-tsc": "2.1.10"
|
"vue-tsc": "2.1.10"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.13.2",
|
"packageManager": "pnpm@9.14.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^16.10.0 || >=18.0.0"
|
"node": "^16.10.0 || >=18.0.0"
|
||||||
},
|
},
|
||||||
|
@ -106,10 +106,6 @@ export interface AsyncDataExecuteOptions {
|
|||||||
|
|
||||||
export interface _AsyncData<DataT, ErrorT> {
|
export interface _AsyncData<DataT, ErrorT> {
|
||||||
data: Ref<DataT>
|
data: Ref<DataT>
|
||||||
/**
|
|
||||||
* @deprecated Use `status` instead. This may be removed in a future major version.
|
|
||||||
*/
|
|
||||||
pending: Ref<boolean>
|
|
||||||
refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
|
refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
|
||||||
execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
|
execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
|
||||||
clear: () => void
|
clear: () => void
|
||||||
@ -249,7 +245,6 @@ export function useAsyncData<
|
|||||||
const _ref = options.deep ? ref : shallowRef
|
const _ref = options.deep ? ref : shallowRef
|
||||||
nuxtApp._asyncData[key] = {
|
nuxtApp._asyncData[key] = {
|
||||||
data: _ref(hasCachedData ? initialCachedData : options.default!()),
|
data: _ref(hasCachedData ? initialCachedData : options.default!()),
|
||||||
pending: ref(!hasCachedData),
|
|
||||||
error: toRef(nuxtApp.payload._errors, key),
|
error: toRef(nuxtApp.payload._errors, key),
|
||||||
status: ref('idle'),
|
status: ref('idle'),
|
||||||
_default: options.default!,
|
_default: options.default!,
|
||||||
@ -277,7 +272,6 @@ export function useAsyncData<
|
|||||||
return Promise.resolve(cachedData)
|
return Promise.resolve(cachedData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
asyncData.pending.value = true
|
|
||||||
asyncData.status.value = 'pending'
|
asyncData.status.value = 'pending'
|
||||||
// TODO: Cancel previous promise
|
// TODO: Cancel previous promise
|
||||||
const promise = new Promise<ResT>(
|
const promise = new Promise<ResT>(
|
||||||
@ -322,8 +316,6 @@ export function useAsyncData<
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
if ((promise as any).cancelled) { return }
|
if ((promise as any).cancelled) { return }
|
||||||
|
|
||||||
asyncData.pending.value = false
|
|
||||||
|
|
||||||
delete nuxtApp._asyncDataPromises[key]
|
delete nuxtApp._asyncDataPromises[key]
|
||||||
})
|
})
|
||||||
nuxtApp._asyncDataPromises[key] = promise
|
nuxtApp._asyncDataPromises[key] = promise
|
||||||
@ -366,7 +358,6 @@ export function useAsyncData<
|
|||||||
|
|
||||||
if (fetchOnServer && nuxtApp.isHydrating && (asyncData.error.value || typeof initialCachedData !== 'undefined')) {
|
if (fetchOnServer && nuxtApp.isHydrating && (asyncData.error.value || typeof initialCachedData !== 'undefined')) {
|
||||||
// 1. Hydration (server: true): no fetch
|
// 1. Hydration (server: true): no fetch
|
||||||
asyncData.pending.value = false
|
|
||||||
asyncData.status.value = asyncData.error.value ? 'error' : 'success'
|
asyncData.status.value = asyncData.error.value ? 'error' : 'success'
|
||||||
} else if (instance && ((nuxtApp.payload.serverRendered && nuxtApp.isHydrating) || options.lazy) && options.immediate) {
|
} else if (instance && ((nuxtApp.payload.serverRendered && nuxtApp.isHydrating) || options.lazy) && options.immediate) {
|
||||||
// 2. Initial load (server: false): fetch on mounted
|
// 2. Initial load (server: false): fetch on mounted
|
||||||
@ -527,7 +518,6 @@ function clearNuxtDataByKey (nuxtApp: NuxtApp, key: string): void {
|
|||||||
if (nuxtApp._asyncData[key]) {
|
if (nuxtApp._asyncData[key]) {
|
||||||
nuxtApp._asyncData[key]!.data.value = nuxtApp._asyncData[key]!._default()
|
nuxtApp._asyncData[key]!.data.value = nuxtApp._asyncData[key]!._default()
|
||||||
nuxtApp._asyncData[key]!.error.value = undefined
|
nuxtApp._asyncData[key]!.error.value = undefined
|
||||||
nuxtApp._asyncData[key]!.pending.value = false
|
|
||||||
nuxtApp._asyncData[key]!.status.value = 'idle'
|
nuxtApp._asyncData[key]!.status.value = 'idle'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +126,6 @@ interface _NuxtApp {
|
|||||||
/** @internal */
|
/** @internal */
|
||||||
_asyncData: Record<string, {
|
_asyncData: Record<string, {
|
||||||
data: Ref<unknown>
|
data: Ref<unknown>
|
||||||
/**
|
|
||||||
* @deprecated This may be removed in a future major version.
|
|
||||||
*/
|
|
||||||
pending: Ref<boolean>
|
|
||||||
error: Ref<Error | undefined>
|
error: Ref<Error | undefined>
|
||||||
status: Ref<AsyncDataRequestStatus>
|
status: Ref<AsyncDataRequestStatus>
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -114,8 +114,8 @@ importers:
|
|||||||
specifier: 3.3.0
|
specifier: 3.3.0
|
||||||
version: 3.3.0
|
version: 3.3.0
|
||||||
eslint-plugin-perfectionist:
|
eslint-plugin-perfectionist:
|
||||||
specifier: 4.0.2
|
specifier: 4.0.3
|
||||||
version: 4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
version: 4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
||||||
eslint-typegen:
|
eslint-typegen:
|
||||||
specifier: 0.3.2
|
specifier: 0.3.2
|
||||||
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
|
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
|
||||||
@ -4373,8 +4373,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
|
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
|
||||||
engines: {node: '>=5.0.0'}
|
engines: {node: '>=5.0.0'}
|
||||||
|
|
||||||
eslint-plugin-perfectionist@4.0.2:
|
eslint-plugin-perfectionist@4.0.3:
|
||||||
resolution: {integrity: sha512-zWdgyg2SdHqhp/P9d9vKwo5qD9is28xMAGzBslHqkZz5mVIikjyz1qvuJ4yS7Wrsf4KlbGorORefb4Kbe7Puzg==}
|
resolution: {integrity: sha512-CyafnreF6boy4lf1XaF72U8NbkwrfjU/mOf1y6doaDMS9zGXhUU1DSk+ZPf/rVwCf1PL1m+rhHqFs+IcB8kDmA==}
|
||||||
engines: {node: ^18.0.0 || >=20.0.0}
|
engines: {node: ^18.0.0 || >=20.0.0}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
eslint: '>=8.0.0'
|
eslint: '>=8.0.0'
|
||||||
@ -11519,7 +11519,7 @@ snapshots:
|
|||||||
|
|
||||||
eslint-plugin-no-only-tests@3.3.0: {}
|
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:
|
dependencies:
|
||||||
'@typescript-eslint/types': 8.15.0
|
'@typescript-eslint/types': 8.15.0
|
||||||
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-if="!pending"
|
v-if="status !== 'pending'"
|
||||||
v-text="'resolved:' + data.resolved"
|
v-text="'resolved:' + data.resolved"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
@ -11,5 +11,5 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
useNuxtData('call')
|
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>
|
</script>
|
||||||
|
@ -17,7 +17,7 @@ const ComponentDefinedInSetup = computed(() => h({
|
|||||||
template: compTemplate.value,
|
template: compTemplate.value,
|
||||||
}) as Component)
|
}) as Component)
|
||||||
|
|
||||||
const { data, pending } = await useAsyncData('templates', async () => {
|
const { data, status } = await useAsyncData('templates', async () => {
|
||||||
const [interactiveComponent, templateString] = await Promise.all([
|
const [interactiveComponent, templateString] = await Promise.all([
|
||||||
$fetch('/api/full-component'),
|
$fetch('/api/full-component'),
|
||||||
$fetch('/api/template'),
|
$fetch('/api/template'),
|
||||||
@ -54,7 +54,7 @@ const Interactive = h({
|
|||||||
>
|
>
|
||||||
{{ count }}
|
{{ count }}
|
||||||
</button>
|
</button>
|
||||||
<template v-if="!pending">
|
<template v-if="status !== 'pending'">
|
||||||
<Name
|
<Name
|
||||||
id="name"
|
id="name"
|
||||||
template="<div>I am the Name.ts component</div>"
|
template="<div>I am the Name.ts component</div>"
|
||||||
|
@ -131,7 +131,6 @@ describe('useAsyncData', () => {
|
|||||||
expect(Object.keys(res)).toMatchInlineSnapshot(`
|
expect(Object.keys(res)).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
"data",
|
"data",
|
||||||
"pending",
|
|
||||||
"error",
|
"error",
|
||||||
"status",
|
"status",
|
||||||
"execute",
|
"execute",
|
||||||
@ -149,29 +148,25 @@ describe('useAsyncData', () => {
|
|||||||
const immediate = await useAsyncData(() => Promise.resolve('test'))
|
const immediate = await useAsyncData(() => Promise.resolve('test'))
|
||||||
expect(immediate.data.value).toBe('test')
|
expect(immediate.data.value).toBe('test')
|
||||||
expect(immediate.status.value).toBe('success')
|
expect(immediate.status.value).toBe('success')
|
||||||
expect(immediate.pending.value).toBe(false)
|
|
||||||
|
|
||||||
const nonimmediate = await useAsyncData(() => Promise.resolve('test'), { immediate: false })
|
const nonimmediate = await useAsyncData(() => Promise.resolve('test'), { immediate: false })
|
||||||
expect(nonimmediate.data.value).toBe(undefined)
|
expect(nonimmediate.data.value).toBe(undefined)
|
||||||
expect(nonimmediate.status.value).toBe('idle')
|
expect(nonimmediate.status.value).toBe('idle')
|
||||||
expect(nonimmediate.pending.value).toBe(true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should capture errors', async () => {
|
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(data.value).toMatchInlineSnapshot('"default"')
|
||||||
expect(error.value).toMatchInlineSnapshot('[Error: test]')
|
expect(error.value).toMatchInlineSnapshot('[Error: test]')
|
||||||
expect(status.value).toBe('error')
|
expect(status.value).toBe('error')
|
||||||
expect(pending.value).toBe(false)
|
|
||||||
expect(useNuxtApp().payload._errors['error-test']).toMatchInlineSnapshot('[Error: test]')
|
expect(useNuxtApp().payload._errors['error-test']).toMatchInlineSnapshot('[Error: test]')
|
||||||
|
|
||||||
// TODO: fix the below
|
// 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(syncedData.value).toEqual(null)
|
||||||
// expect(syncedError.value).toEqual(error.value)
|
// expect(syncedError.value).toEqual(error.value)
|
||||||
// expect(syncedStatus.value).toEqual('idle')
|
// expect(syncedStatus.value).toEqual('idle')
|
||||||
// expect(syncedPending.value).toEqual(true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// https://github.com/nuxt/nuxt/issues/23411
|
// https://github.com/nuxt/nuxt/issues/23411
|
||||||
@ -248,9 +243,9 @@ describe('useAsyncData', () => {
|
|||||||
|
|
||||||
it('should use default while pending', async () => {
|
it('should use default while pending', async () => {
|
||||||
const promise = useAsyncData(() => Promise.resolve('test'), { default: () => 'default' })
|
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"')
|
expect(data.value).toMatchInlineSnapshot('"default"')
|
||||||
|
|
||||||
await promise
|
await promise
|
||||||
|
Loading…
Reference in New Issue
Block a user