@depup/nuxt 4.3.0-depup.0 → 4.4.2-depup.1
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.
- package/README.md +24 -107
- package/dist/app/components/nuxt-announcer.d.ts +26 -0
- package/dist/app/components/nuxt-announcer.js +59 -0
- package/dist/app/components/nuxt-island.js +7 -1
- package/dist/app/components/nuxt-layout.js +44 -21
- package/dist/app/components/nuxt-link.js +29 -15
- package/dist/app/components/nuxt-root.vue +1 -1
- package/dist/app/components/nuxt-route-announcer.js +11 -2
- package/dist/app/components/nuxt-time.vue +13 -2
- package/dist/app/components/test-component-wrapper.js +10 -2
- package/dist/app/components/utils.d.ts +7 -1
- package/dist/app/components/utils.js +18 -0
- package/dist/app/components/welcome.vue +1 -1
- package/dist/app/composables/announcer.d.ts +23 -0
- package/dist/app/composables/announcer.js +47 -0
- package/dist/app/composables/asyncData.d.ts +18 -36
- package/dist/app/composables/asyncData.js +214 -186
- package/dist/app/composables/chunk.js +1 -2
- package/dist/app/composables/cookie.d.ts +14 -0
- package/dist/app/composables/cookie.js +66 -17
- package/dist/app/composables/error.d.ts +2 -2
- package/dist/app/composables/error.js +11 -1
- package/dist/app/composables/fetch.d.ts +11 -16
- package/dist/app/composables/fetch.js +79 -76
- package/dist/app/composables/index.d.ts +2 -0
- package/dist/app/composables/index.js +1 -0
- package/dist/app/composables/manifest.d.ts +1 -1
- package/dist/app/composables/manifest.js +1 -4
- package/dist/app/composables/pages.d.ts +2 -0
- package/dist/app/composables/pages.js +1 -0
- package/dist/app/composables/payload.js +14 -5
- package/dist/app/composables/preload.js +1 -1
- package/dist/app/composables/route-announcer.d.ts +2 -2
- package/dist/app/composables/route-announcer.js +6 -6
- package/dist/app/composables/router.d.ts +7 -0
- package/dist/app/composables/router.js +8 -3
- package/dist/app/composables/ssr.d.ts +1 -1
- package/dist/app/composables/ssr.js +1 -1
- package/dist/app/composables/state.d.ts +11 -1
- package/dist/app/composables/state.js +11 -2
- package/dist/app/composables/url.d.ts +1 -1
- package/dist/app/composables/url.js +1 -1
- package/dist/app/config.d.ts +1 -2
- package/dist/app/index.d.ts +2 -2
- package/dist/app/index.js +1 -1
- package/dist/app/nuxt.d.ts +46 -31
- package/dist/app/nuxt.js +6 -2
- package/dist/app/plugins/restore-state.client.js +1 -2
- package/dist/app/plugins/revive-payload.client.js +9 -3
- package/dist/app/plugins/router.js +2 -2
- package/dist/app/plugins/view-transitions.client.js +39 -4
- package/dist/compiler/runtime/index.d.ts +14 -0
- package/dist/compiler/runtime/index.js +14 -0
- package/dist/index.mjs +2592 -1365
- package/dist/pages/runtime/page.js +11 -21
- package/dist/pages/runtime/plugins/router.js +20 -8
- package/dist/pages/runtime/router.options.js +12 -6
- package/meta.js +2 -1
- package/package.json +77 -37
|
@@ -6,195 +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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
args
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
unregister(oldKey);
|
|
70
|
+
if (currentData._default.toString() !== opts.default.toString()) {
|
|
71
|
+
warnings.push(`different \`default\` value`);
|
|
140
72
|
}
|
|
141
|
-
if (
|
|
142
|
-
|
|
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
|
-
}
|
|
148
|
-
}, { flush: "sync" });
|
|
149
|
-
const unsubParamsWatcher = options.watch ? watch(options.watch, () => {
|
|
150
|
-
if (keyChanging) {
|
|
151
|
-
return;
|
|
152
83
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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);
|
|
157
91
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
pending: writableComputedRef(() => nuxtApp._asyncData[key.value]?.pending),
|
|
172
|
-
status: writableComputedRef(() => nuxtApp._asyncData[key.value]?.status),
|
|
173
|
-
error: writableComputedRef(() => nuxtApp._asyncData[key.value]?.error),
|
|
174
|
-
refresh: (...args2) => {
|
|
175
|
-
if (!nuxtApp._asyncData[key.value]?._init) {
|
|
176
|
-
const initialFetch2 = createInitialFetch();
|
|
177
|
-
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
|
+
}
|
|
178
105
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
});
|
|
189
192
|
}
|
|
190
193
|
}
|
|
191
|
-
|
|
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;
|
|
192
227
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
});
|
|
198
237
|
function writableComputedRef(getter) {
|
|
199
238
|
return computed({
|
|
200
239
|
get() {
|
|
@@ -208,17 +247,6 @@ function writableComputedRef(getter) {
|
|
|
208
247
|
}
|
|
209
248
|
});
|
|
210
249
|
}
|
|
211
|
-
export function useLazyAsyncData(...args) {
|
|
212
|
-
const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
|
|
213
|
-
if (_isAutoKeyNeeded(args[0], args[1])) {
|
|
214
|
-
args.unshift(autoKey);
|
|
215
|
-
}
|
|
216
|
-
const [key, handler, options = {}] = args;
|
|
217
|
-
if (import.meta.dev) {
|
|
218
|
-
options._functionName ||= "useLazyAsyncData";
|
|
219
|
-
}
|
|
220
|
-
return useAsyncData(key, handler, { ...options, lazy: true }, null);
|
|
221
|
-
}
|
|
222
250
|
function _isAutoKeyNeeded(keyOrFetcher, fetcher) {
|
|
223
251
|
if (typeof keyOrFetcher === "string") {
|
|
224
252
|
return false;
|
|
@@ -305,7 +333,7 @@ function pick(obj, keys) {
|
|
|
305
333
|
}
|
|
306
334
|
return newObj;
|
|
307
335
|
}
|
|
308
|
-
function
|
|
336
|
+
function buildAsyncData(nuxtApp, key, _handler, options, initialCachedData) {
|
|
309
337
|
nuxtApp.payload._errors[key] ??= void 0;
|
|
310
338
|
const hasCustomGetCachedData = options.getCachedData !== getDefaultCachedData;
|
|
311
339
|
const handler = import.meta.client || !import.meta.prerender || !nuxtApp.ssrContext?.["~sharedPrerenderCache"] ? _handler : (nuxtApp2, options2) => {
|
|
@@ -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 =
|
|
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()) {
|
|
@@ -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
|
}
|
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
import { customRef, getCurrentScope, nextTick, onScopeDispose, ref, watch } from "vue";
|
|
2
2
|
import { parse, serialize } from "cookie-es";
|
|
3
|
-
import { deleteCookie, getCookie, getRequestHeader, setCookie } from "h3";
|
|
4
|
-
import destr from "destr";
|
|
3
|
+
import { deleteCookie, getCookie, getRequestHeader, setCookie } from "@nuxt/nitro-server/h3";
|
|
5
4
|
import { isEqual } from "ohash";
|
|
6
5
|
import { klona } from "klona";
|
|
7
6
|
import { useNuxtApp } from "../nuxt.js";
|
|
8
7
|
import { useRequestEvent } from "./ssr.js";
|
|
9
8
|
import { cookieStore } from "#build/nuxt.config.mjs";
|
|
9
|
+
function parseCookieValue(value) {
|
|
10
|
+
if (value === "undefined") {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(value);
|
|
15
|
+
if (typeof parsed === "number" && String(parsed) !== value) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return parsed;
|
|
19
|
+
} catch {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
10
23
|
const CookieDefaults = {
|
|
11
24
|
path: "/",
|
|
12
25
|
watch: true,
|
|
13
|
-
decode: (val) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return decoded;
|
|
26
|
+
decode: (val) => parseCookieValue(decodeURIComponent(val)),
|
|
27
|
+
encode: (val) => {
|
|
28
|
+
if (typeof val !== "string" || val === "undefined") {
|
|
29
|
+
return encodeURIComponent(JSON.stringify(val));
|
|
18
30
|
}
|
|
19
|
-
|
|
31
|
+
try {
|
|
32
|
+
if (typeof JSON.parse(val) !== "string") {
|
|
33
|
+
return encodeURIComponent(JSON.stringify(val));
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
return encodeURIComponent(val);
|
|
20
38
|
},
|
|
21
|
-
|
|
39
|
+
refresh: false
|
|
22
40
|
};
|
|
23
41
|
const store = import.meta.client && cookieStore ? globalThis.cookieStore : void 0;
|
|
24
42
|
export function useCookie(name, _opts) {
|
|
@@ -34,7 +52,7 @@ export function useCookie(name, _opts) {
|
|
|
34
52
|
const hasExpired = delay !== void 0 && delay <= 0;
|
|
35
53
|
const shouldSetInitialClientCookie = import.meta.client && (hasExpired || cookies[name] === void 0 || cookies[name] === null);
|
|
36
54
|
const cookieValue = klona(hasExpired ? void 0 : cookies[name] ?? opts.default?.());
|
|
37
|
-
const cookie = import.meta.client && delay && !hasExpired ? cookieRef(cookieValue, delay, opts.watch && opts.watch !== "shallow") : ref(cookieValue);
|
|
55
|
+
const cookie = import.meta.client && delay && !hasExpired ? cookieRef(cookieValue, delay, opts.watch && opts.watch !== "shallow") : import.meta.server ? cookieServerRef(name, cookieValue) : ref(cookieValue);
|
|
38
56
|
if (import.meta.dev && hasExpired) {
|
|
39
57
|
console.warn(`[nuxt] not setting cookie \`${name}\` as it has already expired.`);
|
|
40
58
|
}
|
|
@@ -99,7 +117,7 @@ export function useCookie(name, _opts) {
|
|
|
99
117
|
if (watchPaused) {
|
|
100
118
|
return;
|
|
101
119
|
}
|
|
102
|
-
callback();
|
|
120
|
+
callback(opts.refresh);
|
|
103
121
|
},
|
|
104
122
|
{ deep: opts.watch !== "shallow" }
|
|
105
123
|
);
|
|
@@ -110,7 +128,12 @@ export function useCookie(name, _opts) {
|
|
|
110
128
|
} else if (import.meta.server) {
|
|
111
129
|
const nuxtApp = useNuxtApp();
|
|
112
130
|
const writeFinalCookieValue = () => {
|
|
113
|
-
|
|
131
|
+
const valueIsSame = isEqual(cookie.value, cookies[name]);
|
|
132
|
+
if (opts.readonly || valueIsSame && !opts.refresh) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
nuxtApp._cookiesChanged ||= {};
|
|
136
|
+
if (valueIsSame && opts.refresh && !nuxtApp._cookiesChanged[name]) {
|
|
114
137
|
return;
|
|
115
138
|
}
|
|
116
139
|
nuxtApp._cookies ||= {};
|
|
@@ -137,7 +160,12 @@ export function refreshCookie(name) {
|
|
|
137
160
|
if (import.meta.server || store || typeof BroadcastChannel === "undefined") {
|
|
138
161
|
return;
|
|
139
162
|
}
|
|
140
|
-
|
|
163
|
+
try {
|
|
164
|
+
const channel = new BroadcastChannel(`nuxt:cookies:${name}`);
|
|
165
|
+
channel.postMessage({ refresh: true });
|
|
166
|
+
channel.close();
|
|
167
|
+
} catch {
|
|
168
|
+
}
|
|
141
169
|
}
|
|
142
170
|
function readRawCookies(opts = {}) {
|
|
143
171
|
if (import.meta.server) {
|
|
@@ -183,20 +211,23 @@ function cookieRef(value, delay, shouldWatch) {
|
|
|
183
211
|
if (shouldWatch) {
|
|
184
212
|
unsubscribe = watch(internalRef, trigger);
|
|
185
213
|
}
|
|
186
|
-
function
|
|
187
|
-
elapsed = 0;
|
|
188
|
-
clearTimeout(timeout);
|
|
214
|
+
function scheduleTimeout() {
|
|
189
215
|
const timeRemaining = delay - elapsed;
|
|
190
216
|
const timeoutLength = timeRemaining < MAX_TIMEOUT_DELAY ? timeRemaining : MAX_TIMEOUT_DELAY;
|
|
191
217
|
timeout = setTimeout(() => {
|
|
192
218
|
elapsed += timeoutLength;
|
|
193
219
|
if (elapsed < delay) {
|
|
194
|
-
return
|
|
220
|
+
return scheduleTimeout();
|
|
195
221
|
}
|
|
196
222
|
internalRef.value = void 0;
|
|
197
223
|
trigger();
|
|
198
224
|
}, timeoutLength);
|
|
199
225
|
}
|
|
226
|
+
function createExpirationTimeout() {
|
|
227
|
+
elapsed = 0;
|
|
228
|
+
clearTimeout(timeout);
|
|
229
|
+
scheduleTimeout();
|
|
230
|
+
}
|
|
200
231
|
return {
|
|
201
232
|
get() {
|
|
202
233
|
track();
|
|
@@ -210,3 +241,21 @@ function cookieRef(value, delay, shouldWatch) {
|
|
|
210
241
|
};
|
|
211
242
|
});
|
|
212
243
|
}
|
|
244
|
+
function cookieServerRef(name, value) {
|
|
245
|
+
const internalRef = ref(value);
|
|
246
|
+
const nuxtApp = useNuxtApp();
|
|
247
|
+
return customRef((track, trigger) => {
|
|
248
|
+
return {
|
|
249
|
+
get() {
|
|
250
|
+
track();
|
|
251
|
+
return internalRef.value;
|
|
252
|
+
},
|
|
253
|
+
set(newValue) {
|
|
254
|
+
nuxtApp._cookiesChanged ||= {};
|
|
255
|
+
nuxtApp._cookiesChanged[name] = true;
|
|
256
|
+
internalRef.value = newValue;
|
|
257
|
+
trigger();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { H3Error } from 'h3';
|
|
1
|
+
import type { H3Error } from '@nuxt/nitro-server/h3';
|
|
2
2
|
import type { Ref } from 'vue';
|
|
3
3
|
import type { NuxtPayload } from '../nuxt.js';
|
|
4
4
|
export declare const NUXT_ERROR_SIGNATURE = "__nuxt_error";
|
|
5
5
|
/** @since 3.0.0 */
|
|
6
6
|
export declare const useError: () => Ref<NuxtPayload["error"]>;
|
|
7
|
-
export interface NuxtError<DataT = unknown> extends Omit<H3Error<DataT>, 'statusCode' | 'statusMessage'
|
|
7
|
+
export interface NuxtError<DataT = unknown> extends Omit<H3Error<DataT>, 'statusCode' | 'statusMessage'>, Error {
|
|
8
8
|
error?: true;
|
|
9
9
|
status?: number;
|
|
10
10
|
statusText?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createError as createH3Error } from "h3";
|
|
1
|
+
import { createError as createH3Error } from "@nuxt/nitro-server/h3";
|
|
2
2
|
import { toRef } from "vue";
|
|
3
3
|
import { useNuxtApp } from "../nuxt.js";
|
|
4
4
|
import { useRouter } from "./router.js";
|
|
@@ -38,5 +38,15 @@ export const createError = (error) => {
|
|
|
38
38
|
configurable: false,
|
|
39
39
|
writable: false
|
|
40
40
|
});
|
|
41
|
+
Object.defineProperty(nuxtError, "status", {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
43
|
+
get: () => nuxtError.statusCode,
|
|
44
|
+
configurable: true
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(nuxtError, "statusText", {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
48
|
+
get: () => nuxtError.statusMessage,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
41
51
|
return nuxtError;
|
|
42
52
|
};
|