@depup/nuxt 4.2.2-depup.0 → 4.4.2-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +23 -105
  2. package/app.d.ts +1 -1
  3. package/dist/app/compat/capi.d.ts +1 -1
  4. package/dist/app/compat/interval.d.ts +1 -1
  5. package/dist/app/compat/interval.js +3 -3
  6. package/dist/app/components/client-fallback.client.js +5 -1
  7. package/dist/app/components/client-fallback.server.js +5 -1
  8. package/dist/app/components/error-404.d.vue.ts +6 -6
  9. package/dist/app/components/error-404.vue +4 -4
  10. package/dist/app/components/error-404.vue.d.ts +6 -6
  11. package/dist/app/components/error-500.d.vue.ts +6 -6
  12. package/dist/app/components/error-500.vue +4 -4
  13. package/dist/app/components/error-500.vue.d.ts +6 -6
  14. package/dist/app/components/island-renderer.js +2 -2
  15. package/dist/app/components/nuxt-announcer.d.ts +26 -0
  16. package/dist/app/components/nuxt-announcer.js +59 -0
  17. package/dist/app/components/nuxt-error-page.vue +4 -4
  18. package/dist/app/components/nuxt-island.js +8 -2
  19. package/dist/app/components/nuxt-layout.js +49 -23
  20. package/dist/app/components/nuxt-link.js +30 -16
  21. package/dist/app/components/nuxt-root.vue +1 -1
  22. package/dist/app/components/nuxt-route-announcer.js +11 -2
  23. package/dist/app/components/nuxt-stubs.d.ts +2 -2
  24. package/dist/app/components/nuxt-stubs.js +2 -2
  25. package/dist/app/components/nuxt-time.vue +13 -2
  26. package/dist/app/components/test-component-wrapper.js +10 -2
  27. package/dist/app/components/utils.d.ts +7 -1
  28. package/dist/app/components/utils.js +18 -0
  29. package/dist/app/components/welcome.vue +1 -1
  30. package/dist/app/composables/announcer.d.ts +23 -0
  31. package/dist/app/composables/announcer.js +47 -0
  32. package/dist/app/composables/asyncData.d.ts +24 -37
  33. package/dist/app/composables/asyncData.js +217 -184
  34. package/dist/app/composables/chunk.js +1 -2
  35. package/dist/app/composables/component.js +1 -2
  36. package/dist/app/composables/cookie.d.ts +14 -0
  37. package/dist/app/composables/cookie.js +68 -12
  38. package/dist/app/composables/error.d.ts +9 -6
  39. package/dist/app/composables/error.js +14 -1
  40. package/dist/app/composables/fetch.d.ts +11 -16
  41. package/dist/app/composables/fetch.js +79 -76
  42. package/dist/app/composables/index.d.ts +2 -0
  43. package/dist/app/composables/index.js +1 -0
  44. package/dist/app/composables/manifest.d.ts +4 -6
  45. package/dist/app/composables/manifest.js +6 -24
  46. package/dist/app/composables/pages.d.ts +2 -0
  47. package/dist/app/composables/pages.js +1 -0
  48. package/dist/app/composables/payload.d.ts +4 -0
  49. package/dist/app/composables/payload.js +44 -17
  50. package/dist/app/composables/preload.js +1 -1
  51. package/dist/app/composables/route-announcer.d.ts +2 -2
  52. package/dist/app/composables/route-announcer.js +6 -6
  53. package/dist/app/composables/router.d.ts +14 -3
  54. package/dist/app/composables/router.js +15 -6
  55. package/dist/app/composables/script-stubs.js +2 -2
  56. package/dist/app/composables/ssr.d.ts +2 -2
  57. package/dist/app/composables/ssr.js +1 -1
  58. package/dist/app/composables/state.d.ts +11 -1
  59. package/dist/app/composables/state.js +11 -2
  60. package/dist/app/composables/url.d.ts +1 -1
  61. package/dist/app/composables/url.js +1 -1
  62. package/dist/app/config.d.ts +1 -2
  63. package/dist/app/entry.async.d.ts +2 -2
  64. package/dist/app/entry.d.ts +3 -2
  65. package/dist/app/entry.js +2 -2
  66. package/dist/app/index.d.ts +3 -3
  67. package/dist/app/index.js +1 -1
  68. package/dist/app/middleware/{manifest-route-rule.js → route-rules.js} +2 -2
  69. package/dist/app/nuxt.d.ts +58 -40
  70. package/dist/app/nuxt.js +6 -2
  71. package/dist/app/plugins/dev-server-logs.js +1 -1
  72. package/dist/app/plugins/payload.client.js +0 -3
  73. package/dist/app/plugins/preload.server.js +3 -1
  74. package/dist/app/plugins/restore-state.client.js +1 -2
  75. package/dist/app/plugins/revive-payload.client.js +9 -3
  76. package/dist/app/plugins/router.js +17 -18
  77. package/dist/app/plugins/view-transitions.client.js +39 -4
  78. package/dist/app/types.d.ts +1 -1
  79. package/dist/app/utils.d.ts +6 -9
  80. package/dist/compiler/runtime/index.d.ts +14 -0
  81. package/dist/compiler/runtime/index.js +14 -0
  82. package/dist/components/runtime/lazy-hydrated-component.js +2 -1
  83. package/dist/components/runtime/server-component.js +0 -1
  84. package/dist/head/runtime/components.js +70 -26
  85. package/dist/index.d.mts +1 -1
  86. package/dist/index.d.ts +1 -1
  87. package/dist/index.mjs +2918 -1331
  88. package/dist/pages/runtime/composables.d.ts +10 -1
  89. package/dist/pages/runtime/index.d.ts +1 -1
  90. package/dist/pages/runtime/page.js +24 -24
  91. package/dist/pages/runtime/plugins/prerender.server.js +5 -10
  92. package/dist/pages/runtime/plugins/router.js +29 -20
  93. package/dist/pages/runtime/router.options.js +12 -6
  94. package/dist/pages/runtime/utils.d.ts +7 -0
  95. package/dist/pages/runtime/validate.js +4 -2
  96. package/meta.d.ts +1 -0
  97. package/meta.js +19 -0
  98. package/package.json +87 -66
  99. package/types.d.ts +1 -1
  100. /package/dist/app/middleware/{manifest-route-rule.d.ts → route-rules.d.ts} +0 -0
@@ -91,42 +91,24 @@ export interface _AsyncData<DataT, ErrorT> {
91
91
  status: Ref<AsyncDataRequestStatus>;
92
92
  }
93
93
  export type AsyncData<Data, Error> = _AsyncData<Data, Error> & Promise<_AsyncData<Data, Error>>;
94
- /**
95
- * Provides access to data that resolves asynchronously in an SSR-friendly composable.
96
- * See {@link https://nuxt.com/docs/4.x/api/composables/use-async-data}
97
- * @since 3.0.0
98
- * @param handler An asynchronous function that must return a truthy value (for example, it should not be `undefined` or `null`) or the request may be duplicated on the client side.
99
- * @param options customize the behavior of useAsyncData
100
- */
101
- export declare function useAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(handler: AsyncDataHandler<ResT>, options?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
102
- export declare function useAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(handler: AsyncDataHandler<ResT>, options?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
103
- /**
104
- * Provides access to data that resolves asynchronously in an SSR-friendly composable.
105
- * See {@link https://nuxt.com/docs/4.x/api/composables/use-async-data}
106
- * @param key A unique key to ensure that data fetching can be properly de-duplicated across requests.
107
- * @param handler An asynchronous function that must return a truthy value (for example, it should not be `undefined` or `null`) or the request may be duplicated on the client side.
108
- * @param options customize the behavior of useAsyncData
109
- */
110
- export declare function useAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, options?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
111
- export declare function useAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, options?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
112
- /**
113
- * Provides access to data that resolves asynchronously in an SSR-friendly composable.
114
- * See {@link https://nuxt.com/docs/4.x/api/composables/use-lazy-async-data}
115
- * @since 3.0.0
116
- * @param handler An asynchronous function that must return a truthy value (for example, it should not be `undefined` or `null`) or the request may be duplicated on the client side.
117
- * @param options customize the behavior of useLazyAsyncData
118
- */
119
- export declare function useLazyAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(handler: AsyncDataHandler<ResT>, options?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, 'lazy'>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
120
- export declare function useLazyAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(handler: AsyncDataHandler<ResT>, options?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, 'lazy'>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
121
- /**
122
- * Provides access to data that resolves asynchronously in an SSR-friendly composable.
123
- * See {@link https://nuxt.com/docs/4.x/api/composables/use-lazy-async-data}
124
- * @param key A unique key to ensure that data fetching can be properly de-duplicated across requests.
125
- * @param handler An asynchronous function that must return a truthy value (for example, it should not be `undefined` or `null`) or the request may be duplicated on the client side.
126
- * @param options customize the behavior of useLazyAsyncData
127
- */
128
- export declare function useLazyAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, options?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, 'lazy'>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
129
- export declare function useLazyAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, options?: Omit<AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>, 'lazy'>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
94
+ export declare const createUseAsyncData: <FResT, FDataT = FResT, FPickKeys extends KeysOf<FDataT> = KeysOf<FDataT>, FDefaultT = undefined>(options?: Partial<AsyncDataOptions<FResT, FDataT, FPickKeys, FDefaultT>> | ((currentOptions: AsyncDataOptions<unknown>) => Partial<AsyncDataOptions<FResT, FDataT, FPickKeys, FDefaultT>>)) => {
95
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
96
+ <ResT, NuxtErrorDataT_1 = unknown, DataT_1 = ResT, PickKeys_1 extends KeysOf<DataT_1> = KeysOf<DataT_1>, DefaultT_1 = DataT_1>(handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT_1, PickKeys_1, DefaultT_1>): AsyncData<PickFrom<DataT_1, PickKeys_1> | DefaultT_1, (NuxtErrorDataT_1 extends Error | NuxtError ? NuxtErrorDataT_1 : NuxtError<NuxtErrorDataT_1>) | undefined>;
97
+ <ResT, NuxtErrorDataT_2 = unknown, DataT_2 = ResT, PickKeys_2 extends KeysOf<DataT_2> = KeysOf<DataT_2>, DefaultT_2 = undefined>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT_2, PickKeys_2, DefaultT_2>): AsyncData<PickFrom<DataT_2, PickKeys_2> | DefaultT_2, (NuxtErrorDataT_2 extends Error | NuxtError ? NuxtErrorDataT_2 : NuxtError<NuxtErrorDataT_2>) | undefined>;
98
+ <ResT, NuxtErrorDataT_3 = unknown, DataT_3 = ResT, PickKeys_3 extends KeysOf<DataT_3> = KeysOf<DataT_3>, DefaultT_3 = DataT_3>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT_3, PickKeys_3, DefaultT_3>): AsyncData<PickFrom<DataT_3, PickKeys_3> | DefaultT_3, (NuxtErrorDataT_3 extends Error | NuxtError ? NuxtErrorDataT_3 : NuxtError<NuxtErrorDataT_3>) | undefined>;
99
+ };
100
+ export declare const useAsyncData: {
101
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
102
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
103
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
104
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
105
+ };
106
+ export declare const useLazyAsyncData: {
107
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
108
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
109
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
110
+ <ResT, NuxtErrorDataT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(key: MaybeRefOrGetter<string>, handler: AsyncDataHandler<ResT>, opts?: AsyncDataOptions<ResT, DataT, PickKeys, DefaultT> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError<unknown> ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined>;
111
+ };
130
112
  /** @since 3.1.0 */
131
113
  export declare function useNuxtData<DataT = any>(key: string): {
132
114
  data: Ref<DataT | undefined>;
@@ -135,12 +117,17 @@ export declare function useNuxtData<DataT = any>(key: string): {
135
117
  export declare function refreshNuxtData(keys?: string | string[]): Promise<void>;
136
118
  /** @since 3.0.0 */
137
119
  export declare function clearNuxtData(keys?: string | string[] | ((key: string) => boolean)): void;
120
+ export type DebouncedReturn<ArgumentsT extends unknown[], ReturnT> = ((...args: ArgumentsT) => Promise<ReturnT>) & {
121
+ cancel: () => void;
122
+ flush: () => Promise<ReturnT> | undefined;
123
+ isPending: () => boolean;
124
+ };
138
125
  export type CreatedAsyncData<ResT, NuxtErrorDataT = unknown, DataT = ResT, DefaultT = undefined> = Omit<_AsyncData<DataT | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>)>, 'clear' | 'refresh'> & {
139
126
  _off: () => void;
140
127
  _hash?: Record<string, string | undefined>;
141
128
  _default: () => unknown;
142
129
  _init: boolean;
143
130
  _deps: number;
144
- _execute: (opts?: AsyncDataExecuteOptions) => Promise<void>;
131
+ _execute: DebouncedReturn<[opts?: AsyncDataExecuteOptions | undefined], void>;
145
132
  _abortController?: AbortController;
146
133
  };
@@ -6,190 +6,234 @@ import { getUserCaller, toArray } from "../utils.js";
6
6
  import { clientOnlySymbol } from "../components/client-only.js";
7
7
  import { createError } from "./error.js";
8
8
  import { onNuxtReady } from "./ready.js";
9
+ import { defineKeyedFunctionFactory } from "../../compiler/runtime";
9
10
  import { asyncDataDefaults, granularCachedData, pendingWhenIdle, purgeCachedData } from "#build/nuxt.config.mjs";
10
- export function useAsyncData(...args) {
11
- const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
12
- if (_isAutoKeyNeeded(args[0], args[1])) {
13
- args.unshift(autoKey);
14
- }
15
- let [_key, _handler, options = {}] = args;
16
- let keyChanging = false;
17
- const key = computed(() => toValue(_key));
18
- if (typeof key.value !== "string") {
19
- throw new TypeError("[nuxt] [useAsyncData] key must be a string.");
20
- }
21
- if (typeof _handler !== "function") {
22
- throw new TypeError("[nuxt] [useAsyncData] handler must be a function.");
23
- }
24
- const nuxtApp = useNuxtApp();
25
- options.server ??= true;
26
- options.default ??= getDefault;
27
- options.getCachedData ??= getDefaultCachedData;
28
- options.lazy ??= false;
29
- options.immediate ??= true;
30
- options.deep ??= asyncDataDefaults.deep;
31
- options.dedupe ??= "cancel";
32
- const functionName = options._functionName || "useAsyncData";
33
- const currentData = nuxtApp._asyncData[key.value];
34
- if (import.meta.dev && currentData) {
35
- const warnings = [];
36
- const values = createHash(_handler, options);
37
- if (values.handler !== currentData._hash?.handler) {
38
- warnings.push(`different handler`);
39
- }
40
- for (const opt of ["transform", "pick", "getCachedData"]) {
41
- if (values[opt] !== currentData._hash[opt]) {
42
- warnings.push(`different \`${opt}\` option`);
11
+ export const createUseAsyncData = defineKeyedFunctionFactory({
12
+ name: "createUseAsyncData",
13
+ factory(options = {}) {
14
+ function useAsyncData2(...args) {
15
+ const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
16
+ if (_isAutoKeyNeeded(args[0], args[1])) {
17
+ args.unshift(autoKey);
43
18
  }
44
- }
45
- if (currentData._default.toString() !== options.default.toString()) {
46
- warnings.push(`different \`default\` value`);
47
- }
48
- if (options.deep && isShallow(currentData.data)) {
49
- warnings.push(`mismatching \`deep\` option`);
50
- }
51
- if (warnings.length) {
52
- const caller = getUserCaller();
53
- const explanation = caller ? ` (used at ${caller.source}:${caller.line}:${caller.column})` : "";
54
- console.warn(`[nuxt] [${functionName}] Incompatible options detected for "${key.value}"${explanation}:
55
- ${warnings.map((w) => `- ${w}`).join("\n")}
56
- You can use a different key or move the call to a composable to ensure the options are shared across calls.`);
57
- }
58
- }
59
- function createInitialFetch() {
60
- const initialFetchOptions = { cause: "initial", dedupe: options.dedupe };
61
- if (!nuxtApp._asyncData[key.value]?._init) {
62
- initialFetchOptions.cachedData = options.getCachedData(key.value, nuxtApp, { cause: "initial" });
63
- nuxtApp._asyncData[key.value] = createAsyncData(nuxtApp, key.value, _handler, options, initialFetchOptions.cachedData);
64
- }
65
- return () => nuxtApp._asyncData[key.value].execute(initialFetchOptions);
66
- }
67
- const initialFetch = createInitialFetch();
68
- const asyncData = nuxtApp._asyncData[key.value];
69
- asyncData._deps++;
70
- const fetchOnServer = options.server !== false && nuxtApp.payload.serverRendered;
71
- if (import.meta.server && fetchOnServer && options.immediate) {
72
- const promise = initialFetch();
73
- if (getCurrentInstance()) {
74
- onServerPrefetch(() => promise);
75
- } else {
76
- nuxtApp.hook("app:created", async () => {
77
- await promise;
78
- });
79
- }
80
- }
81
- if (import.meta.client) {
82
- let unregister = function(key2) {
83
- const data = nuxtApp._asyncData[key2];
84
- if (data?._deps) {
85
- data._deps--;
86
- if (data._deps === 0) {
87
- data?._off();
19
+ let [_key, _handler, opts = {}] = args;
20
+ let keyChanging = false;
21
+ const key = computed(() => toValue(_key));
22
+ if (typeof key.value !== "string") {
23
+ throw new TypeError("[nuxt] [useAsyncData] key must be a string.");
24
+ }
25
+ if (typeof _handler !== "function") {
26
+ throw new TypeError("[nuxt] [useAsyncData] handler must be a function.");
27
+ }
28
+ const shouldFactoryOptionsOverride = typeof options === "function";
29
+ const nuxtApp = useNuxtApp();
30
+ const factoryOptions = shouldFactoryOptionsOverride ? options(opts) : options;
31
+ if (!shouldFactoryOptionsOverride) {
32
+ for (const key2 in factoryOptions) {
33
+ if (factoryOptions[key2] === void 0) {
34
+ continue;
35
+ }
36
+ if (opts[key2] !== void 0) {
37
+ continue;
38
+ }
39
+ opts[key2] = factoryOptions[key2];
88
40
  }
89
41
  }
90
- };
91
- const instance = getCurrentInstance();
92
- if (instance && fetchOnServer && options.immediate && !instance.sp) {
93
- instance.sp = [];
94
- }
95
- if (import.meta.dev && !nuxtApp.isHydrating && !nuxtApp._processingMiddleware && (!instance || instance?.isMounted)) {
96
- console.warn(`[nuxt] [${functionName}] Component is already mounted, please use $fetch instead. See https://nuxt.com/docs/4.x/getting-started/data-fetching`);
97
- }
98
- if (instance && !instance._nuxtOnBeforeMountCbs) {
99
- instance._nuxtOnBeforeMountCbs = [];
100
- const cbs = instance._nuxtOnBeforeMountCbs;
101
- onBeforeMount(() => {
102
- cbs.forEach((cb) => {
103
- cb();
104
- });
105
- cbs.splice(0, cbs.length);
106
- });
107
- onUnmounted(() => cbs.splice(0, cbs.length));
108
- }
109
- const isWithinClientOnly = instance && (instance._nuxtClientOnly || inject(clientOnlySymbol, false));
110
- if (fetchOnServer && nuxtApp.isHydrating && (asyncData.error.value || asyncData.data.value !== void 0)) {
111
- if (pendingWhenIdle) {
112
- asyncData.pending.value = false;
42
+ opts.server ??= true;
43
+ opts.default ??= getDefault;
44
+ opts.getCachedData ??= getDefaultCachedData;
45
+ opts.lazy ??= false;
46
+ opts.immediate ??= true;
47
+ opts.deep ??= asyncDataDefaults.deep;
48
+ opts.dedupe ??= "cancel";
49
+ if (shouldFactoryOptionsOverride) {
50
+ for (const key2 in factoryOptions) {
51
+ if (factoryOptions[key2] === void 0) {
52
+ continue;
53
+ }
54
+ opts[key2] = factoryOptions[key2];
55
+ }
113
56
  }
114
- asyncData.status.value = asyncData.error.value ? "error" : "success";
115
- } else if (instance && (!isWithinClientOnly && nuxtApp.payload.serverRendered && nuxtApp.isHydrating || options.lazy) && options.immediate) {
116
- instance._nuxtOnBeforeMountCbs.push(initialFetch);
117
- } else if (options.immediate && asyncData.status.value !== "success") {
118
- initialFetch();
119
- }
120
- const hasScope = getCurrentScope();
121
- const unsubKeyWatcher = watch(key, (newKey, oldKey) => {
122
- if ((newKey || oldKey) && newKey !== oldKey) {
123
- keyChanging = true;
124
- const hadData = nuxtApp._asyncData[oldKey]?.data.value !== void 0;
125
- const wasRunning = nuxtApp._asyncDataPromises[oldKey] !== void 0;
126
- const initialFetchOptions = { cause: "initial", dedupe: options.dedupe };
127
- if (!nuxtApp._asyncData[newKey]?._init) {
128
- let initialValue;
129
- if (oldKey && hadData) {
130
- initialValue = nuxtApp._asyncData[oldKey].data.value;
131
- } else {
132
- initialValue = options.getCachedData(newKey, nuxtApp, { cause: "initial" });
133
- initialFetchOptions.cachedData = initialValue;
57
+ const functionName = import.meta.dev ? factoryOptions._functionName || "useAsyncData" : "";
58
+ const currentData = nuxtApp._asyncData[key.value];
59
+ if (import.meta.dev && currentData) {
60
+ const warnings = [];
61
+ const values = createHash(_handler, opts);
62
+ if (values.handler !== currentData._hash?.handler) {
63
+ warnings.push(`different handler`);
64
+ }
65
+ for (const opt of ["transform", "pick", "getCachedData"]) {
66
+ if (values[opt] !== currentData._hash[opt]) {
67
+ warnings.push(`different \`${opt}\` option`);
134
68
  }
135
- nuxtApp._asyncData[newKey] = createAsyncData(nuxtApp, newKey, _handler, options, initialValue);
136
69
  }
137
- nuxtApp._asyncData[newKey]._deps++;
138
- if (oldKey) {
139
- unregister(oldKey);
70
+ if (currentData._default.toString() !== opts.default.toString()) {
71
+ warnings.push(`different \`default\` value`);
140
72
  }
141
- if (options.immediate || hadData || wasRunning) {
142
- nuxtApp._asyncData[newKey].execute(initialFetchOptions);
73
+ if (opts.deep && isShallow(currentData.data)) {
74
+ warnings.push(`mismatching \`deep\` option`);
75
+ }
76
+ if (warnings.length) {
77
+ const caller = getUserCaller();
78
+ const explanation = caller ? ` (used at ${caller.source}:${caller.line}:${caller.column})` : "";
79
+ console.warn(`[nuxt] [${functionName}] Incompatible options detected for "${key.value}"${explanation}:
80
+ ${warnings.map((w) => `- ${w}`).join("\n")}
81
+ You can use a different key or move the call to a composable to ensure the options are shared across calls.`);
143
82
  }
144
- queuePostFlushCb(() => {
145
- keyChanging = false;
146
- });
147
83
  }
148
- }, { flush: "sync" });
149
- const unsubParamsWatcher = options.watch ? watch(options.watch, () => {
150
- if (keyChanging) {
151
- return;
84
+ function createInitialFetch() {
85
+ const initialFetchOptions = { cause: "initial", dedupe: opts.dedupe };
86
+ if (!nuxtApp._asyncData[key.value]?._init) {
87
+ initialFetchOptions.cachedData = opts.getCachedData(key.value, nuxtApp, { cause: "initial" });
88
+ nuxtApp._asyncData[key.value] = buildAsyncData(nuxtApp, key.value, _handler, opts, initialFetchOptions.cachedData);
89
+ }
90
+ return () => nuxtApp._asyncData[key.value].execute(initialFetchOptions);
152
91
  }
153
- nuxtApp._asyncData[key.value]?._execute({ cause: "watch", dedupe: options.dedupe });
154
- }) : () => {
155
- };
156
- if (hasScope) {
157
- onScopeDispose(() => {
158
- unsubKeyWatcher();
159
- unsubParamsWatcher();
160
- unregister(key.value);
161
- });
162
- }
163
- }
164
- const asyncReturn = {
165
- data: writableComputedRef(() => nuxtApp._asyncData[key.value]?.data),
166
- pending: writableComputedRef(() => nuxtApp._asyncData[key.value]?.pending),
167
- status: writableComputedRef(() => nuxtApp._asyncData[key.value]?.status),
168
- error: writableComputedRef(() => nuxtApp._asyncData[key.value]?.error),
169
- refresh: (...args2) => {
170
- if (!nuxtApp._asyncData[key.value]?._init) {
171
- const initialFetch2 = createInitialFetch();
172
- return initialFetch2();
92
+ const initialFetch = createInitialFetch();
93
+ const asyncData = nuxtApp._asyncData[key.value];
94
+ asyncData._deps++;
95
+ const fetchOnServer = opts.server !== false && nuxtApp.payload.serverRendered;
96
+ if (import.meta.server && fetchOnServer && opts.immediate) {
97
+ const promise = initialFetch();
98
+ if (getCurrentInstance()) {
99
+ onServerPrefetch(() => promise);
100
+ } else {
101
+ nuxtApp.hook("app:created", async () => {
102
+ await promise;
103
+ });
104
+ }
173
105
  }
174
- return nuxtApp._asyncData[key.value].execute(...args2);
175
- },
176
- execute: (...args2) => asyncReturn.refresh(...args2),
177
- clear: () => {
178
- const entry = nuxtApp._asyncData[key.value];
179
- if (entry?._abortController) {
180
- try {
181
- entry._abortController.abort(new DOMException("AsyncData aborted by user.", "AbortError"));
182
- } finally {
183
- entry._abortController = void 0;
106
+ if (import.meta.client) {
107
+ let unregister = function(key2) {
108
+ const data = nuxtApp._asyncData[key2];
109
+ if (data?._deps) {
110
+ data._deps--;
111
+ if (data._deps === 0) {
112
+ data?._off();
113
+ }
114
+ }
115
+ };
116
+ const instance = getCurrentInstance();
117
+ if (instance && fetchOnServer && opts.immediate && !instance.sp) {
118
+ instance.sp = [];
119
+ }
120
+ if (import.meta.dev && !nuxtApp.isHydrating && !nuxtApp._processingMiddleware && (!instance || instance?.isMounted)) {
121
+ console.warn(`[nuxt] [${functionName}] Component is already mounted, please use $fetch instead. See https://nuxt.com/docs/4.x/getting-started/data-fetching`);
122
+ }
123
+ if (instance && !instance._nuxtOnBeforeMountCbs) {
124
+ instance._nuxtOnBeforeMountCbs = [];
125
+ const cbs = instance._nuxtOnBeforeMountCbs;
126
+ onBeforeMount(() => {
127
+ cbs.forEach((cb) => {
128
+ cb();
129
+ });
130
+ cbs.splice(0, cbs.length);
131
+ });
132
+ onUnmounted(() => cbs.splice(0, cbs.length));
133
+ }
134
+ const isWithinClientOnly = instance && (instance._nuxtClientOnly || inject(clientOnlySymbol, false));
135
+ if (fetchOnServer && nuxtApp.isHydrating && (asyncData.error.value || asyncData.data.value !== void 0)) {
136
+ if (pendingWhenIdle) {
137
+ asyncData.pending.value = false;
138
+ }
139
+ asyncData.status.value = asyncData.error.value ? "error" : "success";
140
+ } else if (instance && (!isWithinClientOnly && nuxtApp.payload.serverRendered && nuxtApp.isHydrating || opts.lazy) && opts.immediate) {
141
+ instance._nuxtOnBeforeMountCbs.push(initialFetch);
142
+ } else if (opts.immediate && asyncData.status.value !== "success") {
143
+ initialFetch();
144
+ }
145
+ const hasScope = getCurrentScope();
146
+ const unsubKeyWatcher = watch(key, (newKey, oldKey) => {
147
+ if ((newKey || oldKey) && newKey !== oldKey) {
148
+ keyChanging = true;
149
+ const hadData = nuxtApp._asyncData[oldKey]?.data.value !== void 0;
150
+ const wasRunning = nuxtApp._asyncDataPromises[oldKey] !== void 0;
151
+ const initialFetchOptions = { cause: "initial", dedupe: opts.dedupe };
152
+ if (!nuxtApp._asyncData[newKey]?._init) {
153
+ let initialValue;
154
+ if (oldKey && hadData) {
155
+ initialValue = nuxtApp._asyncData[oldKey].data.value;
156
+ } else {
157
+ initialValue = opts.getCachedData(newKey, nuxtApp, { cause: "initial" });
158
+ initialFetchOptions.cachedData = initialValue;
159
+ }
160
+ nuxtApp._asyncData[newKey] = buildAsyncData(nuxtApp, newKey, _handler, opts, initialValue);
161
+ }
162
+ nuxtApp._asyncData[newKey]._deps++;
163
+ if (oldKey) {
164
+ unregister(oldKey);
165
+ }
166
+ if (opts.immediate || hadData || wasRunning) {
167
+ nuxtApp._asyncData[newKey].execute(initialFetchOptions);
168
+ }
169
+ queuePostFlushCb(() => {
170
+ keyChanging = false;
171
+ });
172
+ }
173
+ }, { flush: "sync" });
174
+ const unsubParamsWatcher = opts.watch ? watch(opts.watch, () => {
175
+ if (keyChanging) {
176
+ return;
177
+ }
178
+ if (nuxtApp._asyncData[key.value]?._execute.isPending()) {
179
+ queuePostFlushCb(() => {
180
+ nuxtApp._asyncData[key.value]?._execute.flush();
181
+ });
182
+ }
183
+ nuxtApp._asyncData[key.value]?._execute({ cause: "watch", dedupe: opts.dedupe });
184
+ }) : () => {
185
+ };
186
+ if (hasScope) {
187
+ onScopeDispose(() => {
188
+ unsubKeyWatcher();
189
+ unsubParamsWatcher();
190
+ unregister(key.value);
191
+ });
184
192
  }
185
193
  }
186
- clearNuxtDataByKey(nuxtApp, key.value);
194
+ const asyncReturn = {
195
+ data: writableComputedRef(() => nuxtApp._asyncData[key.value]?.data),
196
+ pending: writableComputedRef(() => nuxtApp._asyncData[key.value]?.pending),
197
+ status: writableComputedRef(() => nuxtApp._asyncData[key.value]?.status),
198
+ error: writableComputedRef(() => nuxtApp._asyncData[key.value]?.error),
199
+ refresh: (...args2) => {
200
+ if (!nuxtApp._asyncData[key.value]?._init) {
201
+ const initialFetch2 = createInitialFetch();
202
+ return initialFetch2();
203
+ }
204
+ return nuxtApp._asyncData[key.value].execute(...args2);
205
+ },
206
+ execute: (...args2) => asyncReturn.refresh(...args2),
207
+ clear: () => {
208
+ const entry = nuxtApp._asyncData[key.value];
209
+ if (entry?._abortController) {
210
+ try {
211
+ entry._abortController.abort(new DOMException("AsyncData aborted by user.", "AbortError"));
212
+ } finally {
213
+ entry._abortController = void 0;
214
+ }
215
+ }
216
+ clearNuxtDataByKey(nuxtApp, key.value);
217
+ }
218
+ };
219
+ const asyncDataPromise = Promise.resolve(nuxtApp._asyncDataPromises[key.value]).then(() => asyncReturn);
220
+ Object.assign(asyncDataPromise, asyncReturn);
221
+ Object.defineProperties(asyncDataPromise, {
222
+ then: { enumerable: true, value: asyncDataPromise.then.bind(asyncDataPromise) },
223
+ catch: { enumerable: true, value: asyncDataPromise.catch.bind(asyncDataPromise) },
224
+ finally: { enumerable: true, value: asyncDataPromise.finally.bind(asyncDataPromise) }
225
+ });
226
+ return asyncDataPromise;
187
227
  }
188
- };
189
- const asyncDataPromise = Promise.resolve(nuxtApp._asyncDataPromises[key.value]).then(() => asyncReturn);
190
- Object.assign(asyncDataPromise, asyncReturn);
191
- return asyncDataPromise;
192
- }
228
+ return useAsyncData2;
229
+ }
230
+ });
231
+ export const useAsyncData = createUseAsyncData.__nuxt_factory();
232
+ export const useLazyAsyncData = createUseAsyncData.__nuxt_factory({
233
+ lazy: true,
234
+ // @ts-expect-error private property
235
+ _functionName: "useLazyAsyncData"
236
+ });
193
237
  function writableComputedRef(getter) {
194
238
  return computed({
195
239
  get() {
@@ -203,17 +247,6 @@ function writableComputedRef(getter) {
203
247
  }
204
248
  });
205
249
  }
206
- export function useLazyAsyncData(...args) {
207
- const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
208
- if (_isAutoKeyNeeded(args[0], args[1])) {
209
- args.unshift(autoKey);
210
- }
211
- const [key, handler, options = {}] = args;
212
- if (import.meta.dev) {
213
- options._functionName ||= "useLazyAsyncData";
214
- }
215
- return useAsyncData(key, handler, { ...options, lazy: true }, null);
216
- }
217
250
  function _isAutoKeyNeeded(keyOrFetcher, fetcher) {
218
251
  if (typeof keyOrFetcher === "string") {
219
252
  return false;
@@ -300,16 +333,16 @@ function pick(obj, keys) {
300
333
  }
301
334
  return newObj;
302
335
  }
303
- function createAsyncData(nuxtApp, key, _handler, options, initialCachedData) {
336
+ function buildAsyncData(nuxtApp, key, _handler, options, initialCachedData) {
304
337
  nuxtApp.payload._errors[key] ??= void 0;
305
338
  const hasCustomGetCachedData = options.getCachedData !== getDefaultCachedData;
306
- const handler = import.meta.client || !import.meta.prerender || !nuxtApp.ssrContext?._sharedPrerenderCache ? _handler : (nuxtApp2, options2) => {
307
- const value = nuxtApp2.ssrContext._sharedPrerenderCache.get(key);
339
+ const handler = import.meta.client || !import.meta.prerender || !nuxtApp.ssrContext?.["~sharedPrerenderCache"] ? _handler : (nuxtApp2, options2) => {
340
+ const value = nuxtApp2.ssrContext["~sharedPrerenderCache"].get(key);
308
341
  if (value) {
309
342
  return value;
310
343
  }
311
344
  const promise = Promise.resolve().then(() => nuxtApp2.runWithContext(() => _handler(nuxtApp2, options2)));
312
- nuxtApp2.ssrContext._sharedPrerenderCache.set(key, promise);
345
+ nuxtApp2.ssrContext["~sharedPrerenderCache"].set(key, promise);
313
346
  return promise;
314
347
  };
315
348
  const _ref = options.deep ? ref : shallowRef;
@@ -1,4 +1,3 @@
1
- import destr from "destr";
2
1
  import { useNuxtApp } from "../nuxt.js";
3
2
  export function reloadNuxtApp(options = {}) {
4
3
  if (import.meta.server) {
@@ -7,7 +6,7 @@ export function reloadNuxtApp(options = {}) {
7
6
  const path = options.path || window.location.pathname;
8
7
  let handledPath = {};
9
8
  try {
10
- handledPath = destr(sessionStorage.getItem("nuxt:reload") || "{}");
9
+ handledPath = JSON.parse(sessionStorage.getItem("nuxt:reload") || "{}");
11
10
  } catch {
12
11
  }
13
12
  if (options.force || handledPath?.path !== path || handledPath?.expires < Date.now()) {
@@ -32,8 +32,7 @@ async function runLegacyAsyncData(res, fn) {
32
32
  _res[key2] = computed({
33
33
  get: () => data.value?.[key2],
34
34
  set(v) {
35
- data.value ||= {};
36
- data.value[key2] = v;
35
+ data.value = data.value ? { ...data.value, [key2]: v } : { [key2]: v };
37
36
  }
38
37
  });
39
38
  }
@@ -7,6 +7,20 @@ export interface CookieOptions<T = any> extends _CookieOptions {
7
7
  default?: () => T | Ref<T>;
8
8
  watch?: boolean | 'shallow';
9
9
  readonly?: boolean;
10
+ /**
11
+ * Refresh cookie expiration even when the value remains unchanged.
12
+ *
13
+ * By default, a cookie is only rewritten when its value changes.
14
+ * When `refresh` is set to `true`, the cookie will be re-written
15
+ * on every explicit assignment (e.g. `cookie.value = cookie.value`),
16
+ * extending its expiration even if the value is the same.
17
+ *
18
+ * Note: the expiration is not refreshed automatically — you must
19
+ * assign to `cookie.value` to trigger the refresh.
20
+ *
21
+ * @default false
22
+ */
23
+ refresh?: boolean;
10
24
  }
11
25
  export interface CookieRef<T> extends Ref<T> {
12
26
  }