@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.
Files changed (59) hide show
  1. package/README.md +24 -107
  2. package/dist/app/components/nuxt-announcer.d.ts +26 -0
  3. package/dist/app/components/nuxt-announcer.js +59 -0
  4. package/dist/app/components/nuxt-island.js +7 -1
  5. package/dist/app/components/nuxt-layout.js +44 -21
  6. package/dist/app/components/nuxt-link.js +29 -15
  7. package/dist/app/components/nuxt-root.vue +1 -1
  8. package/dist/app/components/nuxt-route-announcer.js +11 -2
  9. package/dist/app/components/nuxt-time.vue +13 -2
  10. package/dist/app/components/test-component-wrapper.js +10 -2
  11. package/dist/app/components/utils.d.ts +7 -1
  12. package/dist/app/components/utils.js +18 -0
  13. package/dist/app/components/welcome.vue +1 -1
  14. package/dist/app/composables/announcer.d.ts +23 -0
  15. package/dist/app/composables/announcer.js +47 -0
  16. package/dist/app/composables/asyncData.d.ts +18 -36
  17. package/dist/app/composables/asyncData.js +214 -186
  18. package/dist/app/composables/chunk.js +1 -2
  19. package/dist/app/composables/cookie.d.ts +14 -0
  20. package/dist/app/composables/cookie.js +66 -17
  21. package/dist/app/composables/error.d.ts +2 -2
  22. package/dist/app/composables/error.js +11 -1
  23. package/dist/app/composables/fetch.d.ts +11 -16
  24. package/dist/app/composables/fetch.js +79 -76
  25. package/dist/app/composables/index.d.ts +2 -0
  26. package/dist/app/composables/index.js +1 -0
  27. package/dist/app/composables/manifest.d.ts +1 -1
  28. package/dist/app/composables/manifest.js +1 -4
  29. package/dist/app/composables/pages.d.ts +2 -0
  30. package/dist/app/composables/pages.js +1 -0
  31. package/dist/app/composables/payload.js +14 -5
  32. package/dist/app/composables/preload.js +1 -1
  33. package/dist/app/composables/route-announcer.d.ts +2 -2
  34. package/dist/app/composables/route-announcer.js +6 -6
  35. package/dist/app/composables/router.d.ts +7 -0
  36. package/dist/app/composables/router.js +8 -3
  37. package/dist/app/composables/ssr.d.ts +1 -1
  38. package/dist/app/composables/ssr.js +1 -1
  39. package/dist/app/composables/state.d.ts +11 -1
  40. package/dist/app/composables/state.js +11 -2
  41. package/dist/app/composables/url.d.ts +1 -1
  42. package/dist/app/composables/url.js +1 -1
  43. package/dist/app/config.d.ts +1 -2
  44. package/dist/app/index.d.ts +2 -2
  45. package/dist/app/index.js +1 -1
  46. package/dist/app/nuxt.d.ts +46 -31
  47. package/dist/app/nuxt.js +6 -2
  48. package/dist/app/plugins/restore-state.client.js +1 -2
  49. package/dist/app/plugins/revive-payload.client.js +9 -3
  50. package/dist/app/plugins/router.js +2 -2
  51. package/dist/app/plugins/view-transitions.client.js +39 -4
  52. package/dist/compiler/runtime/index.d.ts +14 -0
  53. package/dist/compiler/runtime/index.js +14 -0
  54. package/dist/index.mjs +2592 -1365
  55. package/dist/pages/runtime/page.js +11 -21
  56. package/dist/pages/runtime/plugins/router.js +20 -8
  57. package/dist/pages/runtime/router.options.js +12 -6
  58. package/meta.js +2 -1
  59. package/package.json +77 -37
@@ -17,21 +17,16 @@ export interface UseFetchOptions<ResT, DataT = ResT, PickKeys extends KeysOf<Dat
17
17
  watch?: MultiWatchSources | false;
18
18
  }
19
19
  /**
20
- * Fetch data from an API endpoint with an SSR-friendly composable.
21
- * See {@link https://nuxt.com/docs/4.x/api/composables/use-fetch}
22
- * @since 3.0.0
23
- * @param request The URL to fetch
24
- * @param opts extends $fetch options and useAsyncData options
20
+ * A factory function to create a custom `useFetch` composable with pre-defined default options.
21
+ * @since 4.2.0
25
22
  */
26
- export declare function useFetch<ResT = void, ErrorT = FetchError, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? FetchResult<ReqT, Method> : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, ErrorT | undefined>;
27
- export declare function useFetch<ResT = void, ErrorT = FetchError, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? FetchResult<ReqT, Method> : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, ErrorT | undefined>;
28
- /**
29
- * Fetch data from an API endpoint with an SSR-friendly composable.
30
- * See {@link https://nuxt.com/docs/4.x/api/composables/use-lazy-fetch}
31
- * @since 3.0.0
32
- * @param request The URL to fetch
33
- * @param opts extends $fetch options and useAsyncData options
34
- */
35
- export declare function useLazyFetch<ResT = void, ErrorT = FetchError, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? FetchResult<ReqT, Method> : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: Omit<UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method>, 'lazy'>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, ErrorT | undefined>;
36
- export declare function useLazyFetch<ResT = void, ErrorT = FetchError, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? 'get' extends AvailableRouterMethod<ReqT> ? 'get' : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? FetchResult<ReqT, Method> : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: Omit<UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method>, 'lazy'>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, ErrorT | undefined>;
23
+ export declare const createUseFetch: <FResT = void, FReqT extends NitroFetchRequest = NitroFetchRequest, FMethod extends AvailableRouterMethod<FReqT> = FResT extends void ? "get" extends AvailableRouterMethod<FReqT> ? "get" : AvailableRouterMethod<FReqT> : AvailableRouterMethod<FReqT>, F_ResT = FResT extends void ? FReqT extends string ? import("nitropack/types").MiddlewareOf<FReqT, Lowercase<FMethod>> extends never ? import("nitropack/types").MiddlewareOf<FReqT, "default"> extends never ? unknown : import("nitropack/types").MiddlewareOf<FReqT, "default"> : import("nitropack/types").MiddlewareOf<FReqT, Lowercase<FMethod>> : unknown : FResT, FDataT = F_ResT, FPickKeys extends KeysOf<FDataT> = KeysOf<FDataT>, FDefaultT = undefined>(options?: Partial<UseFetchOptions<F_ResT, FDataT, FPickKeys, FDefaultT, FReqT, FMethod>> | ((currentOptions: UseFetchOptions<unknown>) => Partial<UseFetchOptions<F_ResT, FDataT, FPickKeys, FDefaultT, FReqT, FMethod>>)) => {
24
+ <ResT = void, ErrorT = FetchError<any>, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? "get" extends AvailableRouterMethod<ReqT> ? "get" : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? ReqT extends string ? import("nitropack/types").MiddlewareOf<ReqT, Lowercase<Method>> extends never ? import("nitropack/types").MiddlewareOf<ReqT, "default"> extends never ? unknown : import("nitropack/types").MiddlewareOf<ReqT, "default"> : import("nitropack/types").MiddlewareOf<ReqT, Lowercase<Method>> : unknown : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, ErrorT | undefined>;
25
+ <ResT = void, ErrorT_1 = FetchError<any>, ReqT_1 extends NitroFetchRequest = NitroFetchRequest, Method_1 extends AvailableRouterMethod<ReqT_1> = ResT extends void ? "get" extends AvailableRouterMethod<ReqT_1> ? "get" : AvailableRouterMethod<ReqT_1> : AvailableRouterMethod<ReqT_1>, _ResT_1 = ResT extends void ? ReqT_1 extends string ? import("nitropack/types").MiddlewareOf<ReqT_1, Lowercase<Method_1>> extends never ? import("nitropack/types").MiddlewareOf<ReqT_1, "default"> extends never ? unknown : import("nitropack/types").MiddlewareOf<ReqT_1, "default"> : import("nitropack/types").MiddlewareOf<ReqT_1, Lowercase<Method_1>> : unknown : ResT, DataT_1 = _ResT_1, PickKeys_1 extends KeysOf<DataT_1> = KeysOf<DataT_1>, DefaultT_1 = DataT_1>(request: Ref<ReqT_1> | ReqT_1 | (() => ReqT_1), opts?: UseFetchOptions<_ResT_1, DataT_1, PickKeys_1, DefaultT_1, ReqT_1, Method_1>): AsyncData<PickFrom<DataT_1, PickKeys_1> | DefaultT_1, ErrorT_1 | undefined>;
26
+ };
27
+ export declare const useFetch: {
28
+ <ResT = void, ErrorT = FetchError<any>, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? "get" extends AvailableRouterMethod<ReqT> ? AvailableRouterMethod<ReqT> & "get" : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? ReqT extends string ? import("nitropack/types").MiddlewareOf<ReqT, Lowercase<Method>> extends never ? import("nitropack/types").MiddlewareOf<ReqT, "default"> extends never ? unknown : import("nitropack/types").MiddlewareOf<ReqT, "default"> : import("nitropack/types").MiddlewareOf<ReqT, Lowercase<Method>> : unknown : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = undefined>(request: ReqT | Ref<ReqT, ReqT> | (() => ReqT), opts?: UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, ErrorT | undefined>;
29
+ <ResT = void, ErrorT = FetchError<any>, ReqT extends NitroFetchRequest = NitroFetchRequest, Method extends AvailableRouterMethod<ReqT> = ResT extends void ? "get" extends AvailableRouterMethod<ReqT> ? AvailableRouterMethod<ReqT> & "get" : AvailableRouterMethod<ReqT> : AvailableRouterMethod<ReqT>, _ResT = ResT extends void ? ReqT extends string ? import("nitropack/types").MiddlewareOf<ReqT, Lowercase<Method>> extends never ? import("nitropack/types").MiddlewareOf<ReqT, "default"> extends never ? unknown : import("nitropack/types").MiddlewareOf<ReqT, "default"> : import("nitropack/types").MiddlewareOf<ReqT, Lowercase<Method>> : unknown : ResT, DataT = _ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = DataT>(request: ReqT | Ref<ReqT, ReqT> | (() => ReqT), opts?: UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method> | undefined): AsyncData<DefaultT | PickFrom<DataT, PickKeys>, ErrorT | undefined>;
30
+ };
31
+ export declare const useLazyFetch: ReturnType<typeof createUseFetch>;
37
32
  export {};
@@ -3,83 +3,8 @@ import { hash } from "ohash";
3
3
  import { isPlainObject } from "@vue/shared";
4
4
  import { useRequestFetch } from "./ssr.js";
5
5
  import { useAsyncData } from "./asyncData.js";
6
+ import { defineKeyedFunctionFactory } from "../../compiler/runtime";
6
7
  import { alwaysRunFetchOnKeyChange, fetchDefaults } from "#build/nuxt.config.mjs";
7
- export function useFetch(request, arg1, arg2) {
8
- const [opts = {}, autoKey] = typeof arg1 === "string" ? [{}, arg1] : [arg1, arg2];
9
- const _request = computed(() => toValue(request));
10
- const key = computed(() => toValue(opts.key) || "$f" + hash([autoKey, typeof _request.value === "string" ? _request.value : "", ...generateOptionSegments(opts)]));
11
- if (!opts.baseURL && typeof _request.value === "string" && (_request.value[0] === "/" && _request.value[1] === "/")) {
12
- throw new Error('[nuxt] [useFetch] the request URL must not start with "//".');
13
- }
14
- const {
15
- server,
16
- lazy,
17
- default: defaultFn,
18
- transform,
19
- pick,
20
- watch: watchSources,
21
- immediate,
22
- getCachedData,
23
- deep,
24
- dedupe,
25
- timeout,
26
- ...fetchOptions
27
- } = opts;
28
- const _fetchOptions = reactive({
29
- ...fetchDefaults,
30
- ...fetchOptions,
31
- cache: typeof opts.cache === "boolean" ? void 0 : opts.cache
32
- });
33
- const _asyncDataOptions = {
34
- server,
35
- lazy,
36
- default: defaultFn,
37
- transform,
38
- pick,
39
- immediate,
40
- getCachedData,
41
- deep,
42
- dedupe,
43
- timeout,
44
- watch: watchSources === false ? [] : [...watchSources || [], _fetchOptions]
45
- };
46
- if (import.meta.dev) {
47
- _asyncDataOptions._functionName ||= "useFetch";
48
- }
49
- if (alwaysRunFetchOnKeyChange && !immediate) {
50
- let setImmediate = function() {
51
- _asyncDataOptions.immediate = true;
52
- };
53
- watch(key, setImmediate, { flush: "sync", once: true });
54
- watch([...watchSources || [], _fetchOptions], setImmediate, { flush: "sync", once: true });
55
- }
56
- const asyncData = useAsyncData(watchSources === false ? key.value : key, (_, { signal }) => {
57
- let _$fetch = opts.$fetch || globalThis.$fetch;
58
- if (import.meta.server && !opts.$fetch) {
59
- const isLocalFetch = typeof _request.value === "string" && _request.value[0] === "/" && (!toValue(opts.baseURL) || toValue(opts.baseURL)[0] === "/");
60
- if (isLocalFetch) {
61
- _$fetch = useRequestFetch();
62
- }
63
- }
64
- return _$fetch(_request.value, { signal, ..._fetchOptions });
65
- }, _asyncDataOptions);
66
- return asyncData;
67
- }
68
- export function useLazyFetch(request, arg1, arg2) {
69
- const [opts = {}, autoKey] = typeof arg1 === "string" ? [{}, arg1] : [arg1, arg2];
70
- if (import.meta.dev) {
71
- opts._functionName ||= "useLazyFetch";
72
- }
73
- return useFetch(
74
- request,
75
- {
76
- ...opts,
77
- lazy: true
78
- },
79
- // @ts-expect-error we pass an extra argument with the resolved auto-key to prevent another from being injected
80
- autoKey
81
- );
82
- }
83
8
  function generateOptionSegments(opts) {
84
9
  const segments = [
85
10
  toValue(opts.method)?.toUpperCase() || "GET",
@@ -121,3 +46,81 @@ function generateOptionSegments(opts) {
121
46
  }
122
47
  return segments;
123
48
  }
49
+ export const createUseFetch = defineKeyedFunctionFactory({
50
+ name: "createUseFetch",
51
+ factory(options = {}) {
52
+ function useFetch2(request, arg1, arg2) {
53
+ const [opts = {}, autoKey] = typeof arg1 === "string" ? [{}, arg1] : [arg1, arg2];
54
+ const _request = computed(() => toValue(request));
55
+ const key = computed(() => toValue(opts.key) || "$f" + hash([autoKey, typeof _request.value === "string" ? _request.value : "", ...generateOptionSegments(opts)]));
56
+ if (!opts.baseURL && typeof _request.value === "string" && (_request.value[0] === "/" && _request.value[1] === "/")) {
57
+ throw new Error('[nuxt] [useFetch] the request URL must not start with "//".');
58
+ }
59
+ const factoryOptions = typeof options === "function" ? options(opts) : options;
60
+ const {
61
+ server,
62
+ lazy,
63
+ default: defaultFn,
64
+ transform,
65
+ pick,
66
+ watch: watchSources,
67
+ immediate,
68
+ getCachedData,
69
+ deep,
70
+ dedupe,
71
+ timeout,
72
+ ...fetchOptions
73
+ } = {
74
+ ...typeof options === "function" ? {} : factoryOptions,
75
+ ...opts,
76
+ ...typeof options === "function" ? factoryOptions : {}
77
+ };
78
+ const _fetchOptions = reactive({
79
+ ...fetchDefaults,
80
+ ...fetchOptions,
81
+ cache: typeof fetchOptions.cache === "boolean" ? void 0 : fetchOptions.cache
82
+ });
83
+ const _asyncDataOptions = {
84
+ server,
85
+ lazy,
86
+ default: defaultFn,
87
+ transform,
88
+ pick,
89
+ immediate,
90
+ getCachedData,
91
+ deep,
92
+ dedupe,
93
+ timeout,
94
+ watch: watchSources === false ? [] : [...watchSources || [], _fetchOptions]
95
+ };
96
+ if (import.meta.dev) {
97
+ _asyncDataOptions._functionName ||= factoryOptions._functionName || "useFetch";
98
+ }
99
+ if (alwaysRunFetchOnKeyChange && !immediate) {
100
+ let setImmediate = function() {
101
+ _asyncDataOptions.immediate = true;
102
+ };
103
+ watch(key, setImmediate, { flush: "sync", once: true });
104
+ watch([...watchSources || [], _fetchOptions], setImmediate, { flush: "sync", once: true });
105
+ }
106
+ const asyncData = useAsyncData(watchSources === false ? key.value : key, (_, { signal }) => {
107
+ let _$fetch = opts.$fetch || globalThis.$fetch;
108
+ if (import.meta.server && !opts.$fetch) {
109
+ const isLocalFetch = typeof _request.value === "string" && _request.value[0] === "/" && (!toValue(opts.baseURL) || toValue(opts.baseURL)[0] === "/");
110
+ if (isLocalFetch) {
111
+ _$fetch = useRequestFetch();
112
+ }
113
+ }
114
+ return _$fetch(_request.value, { signal, ..._fetchOptions });
115
+ }, _asyncDataOptions);
116
+ return asyncData;
117
+ }
118
+ return useFetch2;
119
+ }
120
+ });
121
+ export const useFetch = createUseFetch.__nuxt_factory();
122
+ export const useLazyFetch = createUseFetch.__nuxt_factory({
123
+ lazy: true,
124
+ // @ts-expect-error private property
125
+ _functionName: "useLazyFetch"
126
+ });
@@ -25,5 +25,7 @@ export { usePreviewMode } from './preview.js';
25
25
  export { useId } from './id.js';
26
26
  export { useRouteAnnouncer } from './route-announcer.js';
27
27
  export type { Politeness } from './route-announcer.js';
28
+ export { useAnnouncer } from './announcer.js';
29
+ export type { AnnouncerPoliteness, NuxtAnnouncer, NuxtAnnouncerOpts } from './announcer.js';
28
30
  export { useRuntimeHook } from './runtime-hook.js';
29
31
  export { injectHead, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta } from './head.js';
@@ -17,5 +17,6 @@ export { useRequestURL } from "./url.js";
17
17
  export { usePreviewMode } from "./preview.js";
18
18
  export { useId } from "./id.js";
19
19
  export { useRouteAnnouncer } from "./route-announcer.js";
20
+ export { useAnnouncer } from "./announcer.js";
20
21
  export { useRuntimeHook } from "./runtime-hook.js";
21
22
  export { injectHead, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta } from "./head.js";
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '@nuxt/nitro-server/h3';
2
2
  import type { NitroRouteRules } from 'nitropack/types';
3
3
  export interface NuxtAppManifestMeta {
4
4
  id: string;
@@ -1,4 +1,4 @@
1
- import { useNuxtApp, useRuntimeConfig } from "../nuxt.js";
1
+ import { useRuntimeConfig } from "../nuxt.js";
2
2
  import { appManifest as isAppManifestEnabled } from "#build/nuxt.config.mjs";
3
3
  import { buildAssetsURL } from "#internal/nuxt/paths";
4
4
  import _routeRulesMatcher from "#build/route-rules.mjs";
@@ -28,9 +28,6 @@ export function getAppManifest() {
28
28
  if (!isAppManifestEnabled) {
29
29
  throw new Error("[nuxt] app manifest should be enabled with `experimental.appManifest`");
30
30
  }
31
- if (import.meta.server) {
32
- useNuxtApp().ssrContext["~preloadManifest"] = true;
33
- }
34
31
  return manifest || fetchManifest();
35
32
  }
36
33
  export function getRouteRules(arg) {
@@ -0,0 +1,2 @@
1
+ export type { PageMeta } from '#pages/composables';
2
+ export { definePageMeta, defineRouteRules } from '#pages/composables';
@@ -0,0 +1 @@
1
+ export { definePageMeta, defineRouteRules } from "#pages/composables";
@@ -30,7 +30,11 @@ function detectLinkRelType() {
30
30
  }
31
31
  export function preloadPayload(url, opts = {}) {
32
32
  const nuxtApp = useNuxtApp();
33
- const promise = _getPayloadURL(url, opts).then((payloadURL) => {
33
+ const promise = shouldLoadPayload(url).then(async (shouldPreload) => {
34
+ if (!shouldPreload) {
35
+ return;
36
+ }
37
+ const payloadURL = await _getPayloadURL(url, opts);
34
38
  const link = renderJsonPayloads ? { rel: detectLinkRelType(), as: "fetch", crossorigin: "anonymous", href: payloadURL } : { rel: "modulepreload", crossorigin: "", href: payloadURL };
35
39
  if (import.meta.server) {
36
40
  nuxtApp.runWithContext(() => useHead({ link: [link] }));
@@ -58,7 +62,7 @@ async function _getPayloadURL(url, opts = {}) {
58
62
  throw new Error("Payload URL must not include hostname: " + url);
59
63
  }
60
64
  const config = useRuntimeConfig();
61
- const hash = opts.hash || (opts.fresh ? Date.now() : config.app.buildId);
65
+ const hash = opts.hash || (opts.fresh || import.meta.dev ? Date.now() : config.app.buildId);
62
66
  const cdnURL = config.app.cdnURL;
63
67
  const baseOrCdnURL = cdnURL && await isPrerendered(url) ? cdnURL : config.app.baseURL;
64
68
  return joinURL(baseOrCdnURL, u.pathname, filename + (hash ? `?${hash}` : ""));
@@ -67,7 +71,7 @@ async function _importPayload(payloadURL) {
67
71
  if (import.meta.server || !payloadExtraction) {
68
72
  return null;
69
73
  }
70
- const payloadPromise = renderJsonPayloads ? fetch(payloadURL, { cache: "force-cache" }).then((res) => res.text().then(parsePayload)) : import(
74
+ const payloadPromise = renderJsonPayloads ? fetch(payloadURL, import.meta.dev ? {} : { cache: "force-cache" }).then((res) => res.text().then(parsePayload)) : import(
71
75
  /* webpackIgnore: true */
72
76
  /* @vite-ignore */
73
77
  payloadURL
@@ -97,6 +101,9 @@ async function _isPrerenderedInManifest(url) {
97
101
  }
98
102
  export async function shouldLoadPayload(url = useRoute().path) {
99
103
  const rules = getRouteRules({ path: url });
104
+ if (rules.ssr === false) {
105
+ return false;
106
+ }
100
107
  const res = _shouldLoadPrerenderedPayload(rules);
101
108
  if (res !== void 0) {
102
109
  return res;
@@ -104,14 +111,16 @@ export async function shouldLoadPayload(url = useRoute().path) {
104
111
  if (rules.payload) {
105
112
  return true;
106
113
  }
107
- return await _isPrerenderedInManifest(url);
114
+ const prerendered = await _isPrerenderedInManifest(url);
115
+ return prerendered;
108
116
  }
109
117
  export async function isPrerendered(url = useRoute().path) {
110
118
  const res = _shouldLoadPrerenderedPayload(getRouteRules({ path: url }));
111
119
  if (res !== void 0) {
112
120
  return res;
113
121
  }
114
- return await _isPrerenderedInManifest(url);
122
+ const prerendered = await _isPrerenderedInManifest(url);
123
+ return prerendered;
115
124
  }
116
125
  let payloadCache = null;
117
126
  export async function getNuxtClientPayload() {
@@ -48,7 +48,7 @@ export async function preloadRouteComponents(to, router = useRouter()) {
48
48
  continue;
49
49
  }
50
50
  const promise = Promise.resolve(component()).catch(() => {
51
- }).finally(() => promises.splice(promises.indexOf(promise)));
51
+ }).finally(() => promises.splice(promises.indexOf(promise), 1));
52
52
  promises.push(promise);
53
53
  }
54
54
  await Promise.all(promises);
@@ -7,7 +7,7 @@ export type NuxtRouteAnnouncerOpts = {
7
7
  export type RouteAnnouncer = {
8
8
  message: Ref<string>;
9
9
  politeness: Ref<Politeness>;
10
- set: (message: string, politeness: Politeness) => void;
10
+ set: (message: string, politeness?: Politeness) => void;
11
11
  polite: (message: string) => void;
12
12
  assertive: (message: string) => void;
13
13
  _cleanup: () => void;
@@ -16,4 +16,4 @@ export type RouteAnnouncer = {
16
16
  * composable to handle the route announcer
17
17
  * @since 3.12.0
18
18
  */
19
- export declare function useRouteAnnouncer(opts?: Partial<NuxtRouteAnnouncerOpts>): Omit<RouteAnnouncer, '_cleanup'>;
19
+ export declare function useRouteAnnouncer(opts?: NuxtRouteAnnouncerOpts): Omit<RouteAnnouncer, '_cleanup'>;
@@ -9,11 +9,11 @@ function createRouteAnnouncer(opts = {}) {
9
9
  message.value = messageValue;
10
10
  politeness.value = politenessSetting;
11
11
  }
12
- function polite(message2) {
13
- return set(message2, "polite");
12
+ function polite(msg) {
13
+ set(msg, "polite");
14
14
  }
15
- function assertive(message2) {
16
- return set(message2, "assertive");
15
+ function assertive(msg) {
16
+ set(msg, "assertive");
17
17
  }
18
18
  function _updateMessageWithPageHeading() {
19
19
  set(document?.title?.trim(), politeness.value);
@@ -37,8 +37,8 @@ function createRouteAnnouncer(opts = {}) {
37
37
  export function useRouteAnnouncer(opts = {}) {
38
38
  const nuxtApp = useNuxtApp();
39
39
  const announcer = nuxtApp._routeAnnouncer ||= createRouteAnnouncer(opts);
40
- if (opts.politeness !== announcer.politeness.value) {
41
- announcer.politeness.value = opts.politeness || "polite";
40
+ if (opts.politeness && opts.politeness !== announcer.politeness.value) {
41
+ announcer.politeness.value = opts.politeness;
42
42
  }
43
43
  if (import.meta.client && getCurrentScope()) {
44
44
  nuxtApp._routeAnnouncerDeps ||= 0;
@@ -97,4 +97,11 @@ export declare function resolveRouteObject(to: Exclude<RouteLocationRaw, string>
97
97
  * @internal
98
98
  */
99
99
  export declare function encodeURL(location: string, isExternalHost?: boolean): string;
100
+ /**
101
+ * Encode the pathname of a route location string. Ensures decoded paths like
102
+ * `/café` are percent-encoded to match vue-router's encoded route records.
103
+ * Already-encoded paths are not double-encoded.
104
+ * @internal
105
+ */
106
+ export declare function encodeRoutePath(url: string): string;
100
107
  export {};
@@ -1,6 +1,6 @@
1
1
  import { getCurrentInstance, hasInjectionContext, inject, onScopeDispose } from "vue";
2
- import { sanitizeStatusCode } from "h3";
3
- import { hasProtocol, isScriptProtocol, joinURL, parseQuery, parseURL, withQuery } from "ufo";
2
+ import { sanitizeStatusCode } from "@nuxt/nitro-server/h3";
3
+ import { decodePath, encodePath, hasProtocol, isScriptProtocol, joinURL, parseQuery, parseURL, withQuery } from "ufo";
4
4
  import { useNuxtApp, useRuntimeConfig } from "../nuxt.js";
5
5
  import { PageRouteSymbol } from "../components/injections.js";
6
6
  import { createError, showError } from "./error.js";
@@ -145,7 +145,8 @@ export const navigateTo = (to, options) => {
145
145
  }
146
146
  return Promise.resolve();
147
147
  }
148
- return options?.replace ? router.replace(to) : router.push(to);
148
+ const encodedTo = typeof to === "string" ? encodeRoutePath(to) : to;
149
+ return options?.replace ? router.replace(encodedTo) : router.push(encodedTo);
149
150
  };
150
151
  export const abortNavigation = (err) => {
151
152
  if (import.meta.dev && !isProcessingMiddleware()) {
@@ -199,3 +200,7 @@ export function encodeURL(location2, isExternalHost = false) {
199
200
  }
200
201
  return url.toString();
201
202
  }
203
+ export function encodeRoutePath(url) {
204
+ const parsed = parseURL(url);
205
+ return encodePath(decodePath(parsed.pathname)) + parsed.search + parsed.hash;
206
+ }
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { H3Event } from '@nuxt/nitro-server/h3';
2
2
  import type { H3Event$Fetch } from 'nitropack/types';
3
3
  import type { NuxtApp } from '../nuxt.js';
4
4
  /** @since 3.0.0 */
@@ -1,4 +1,4 @@
1
- import { setResponseStatus as _setResponseStatus, appendHeader, getRequestHeader, getRequestHeaders, getResponseHeader, removeResponseHeader, setResponseHeader } from "h3";
1
+ import { setResponseStatus as _setResponseStatus, appendHeader, getRequestHeader, getRequestHeaders, getResponseHeader, removeResponseHeader, setResponseHeader } from "@nuxt/nitro-server/h3";
2
2
  import { computed, getCurrentInstance, ref } from "vue";
3
3
  import { useNuxtApp } from "../nuxt.js";
4
4
  import { toArray } from "../utils.js";
@@ -7,5 +7,15 @@ import type { Ref } from 'vue';
7
7
  */
8
8
  export declare function useState<T>(key?: string, init?: (() => T | Ref<T>)): Ref<T>;
9
9
  export declare function useState<T>(init?: (() => T | Ref<T>)): Ref<T>;
10
+ export interface ClearNuxtStateOptions {
11
+ /**
12
+ * Reset the state to the initial value provided by the `init` function of `useState`
13
+ * instead of setting it to `undefined`.
14
+ *
15
+ * When not specified, this defaults to the value of `experimental.defaults.useState.resetOnClear`
16
+ * in your Nuxt config (which defaults to `true` with `compatibilityVersion: 5`).
17
+ */
18
+ reset?: boolean;
19
+ }
10
20
  /** @since 3.6.0 */
11
- export declare function clearNuxtState(keys?: string | string[] | ((key: string) => boolean)): void;
21
+ export declare function clearNuxtState(keys?: string | string[] | ((key: string) => boolean), opts?: ClearNuxtStateOptions): void;
@@ -1,6 +1,7 @@
1
1
  import { isRef, toRef } from "vue";
2
2
  import { useNuxtApp } from "../nuxt.js";
3
3
  import { toArray } from "../utils.js";
4
+ import { useStateDefaults } from "#build/nuxt.config.mjs";
4
5
  const useStateKeyPrefix = "$s";
5
6
  export function useState(...args) {
6
7
  const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
@@ -17,6 +18,9 @@ export function useState(...args) {
17
18
  const key = useStateKeyPrefix + _key;
18
19
  const nuxtApp = useNuxtApp();
19
20
  const state = toRef(nuxtApp.payload.state, key);
21
+ if (init) {
22
+ nuxtApp._state[key] ??= { _default: init };
23
+ }
20
24
  if (state.value === void 0 && init) {
21
25
  const initialValue = init();
22
26
  if (isRef(initialValue)) {
@@ -27,14 +31,19 @@ export function useState(...args) {
27
31
  }
28
32
  return state;
29
33
  }
30
- export function clearNuxtState(keys) {
34
+ export function clearNuxtState(keys, opts) {
35
+ const reset = opts?.reset ?? useStateDefaults.resetOnClear;
31
36
  const nuxtApp = useNuxtApp();
32
37
  const _allKeys = Object.keys(nuxtApp.payload.state).map((key) => key.substring(useStateKeyPrefix.length));
33
38
  const _keys = !keys ? _allKeys : typeof keys === "function" ? _allKeys.filter(keys) : toArray(keys);
34
39
  for (const _key of _keys) {
35
40
  const key = useStateKeyPrefix + _key;
36
41
  if (key in nuxtApp.payload.state) {
37
- nuxtApp.payload.state[key] = void 0;
42
+ if (reset && nuxtApp._state[key]) {
43
+ nuxtApp.payload.state[key] = nuxtApp._state[key]._default();
44
+ } else {
45
+ nuxtApp.payload.state[key] = void 0;
46
+ }
38
47
  }
39
48
  }
40
49
  }
@@ -1,3 +1,3 @@
1
- import { getRequestURL } from 'h3';
1
+ import { getRequestURL } from '@nuxt/nitro-server/h3';
2
2
  /** @since 3.5.0 */
3
3
  export declare function useRequestURL(opts?: Parameters<typeof getRequestURL>[1]): URL;
@@ -1,4 +1,4 @@
1
- import { getRequestURL } from "h3";
1
+ import { getRequestURL } from "@nuxt/nitro-server/h3";
2
2
  import { useRequestEvent } from "./ssr.js";
3
3
  export function useRequestURL(opts) {
4
4
  if (import.meta.server) {
@@ -1,5 +1,5 @@
1
1
  import type { AppConfig } from 'nuxt/schema';
2
- type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? {
2
+ export type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? {
3
3
  [P in keyof T]?: DeepPartial<T[P]>;
4
4
  } : T;
5
5
  export declare const _getAppConfig: () => AppConfig;
@@ -11,4 +11,3 @@ export declare function _replaceAppConfig(newConfig: AppConfig): void;
11
11
  * Will preserve existing properties.
12
12
  */
13
13
  export declare function updateAppConfig(appConfig: DeepPartial<AppConfig>): void;
14
- export {};
@@ -1,8 +1,8 @@
1
1
  import '../../dist/app/types/augments.js';
2
2
  export { applyPlugin, applyPlugins, callWithNuxt, createNuxtApp, defineAppConfig, defineNuxtPlugin, definePayloadPlugin, isNuxtPlugin, registerPluginHooks, tryUseNuxtApp, useNuxtApp, useRuntimeConfig } from './nuxt.js';
3
3
  export type { CreateOptions, NuxtApp, NuxtPayload, NuxtPluginIndicator, NuxtSSRContext, ObjectPlugin, Plugin, PluginEnvContext, PluginMeta, ResolvedPluginMeta, RuntimeNuxtHooks } from './nuxt.js';
4
- export { defineNuxtComponent, useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, useHydration, callOnce, useState, clearNuxtState, clearError, createError, isNuxtError, showError, useError, useFetch, useLazyFetch, useCookie, refreshCookie, onPrehydrate, prerenderRoutes, useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus, useResponseHeader, onNuxtReady, abortNavigation, addRouteMiddleware, defineNuxtRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter, preloadComponents, prefetchComponents, preloadRouteComponents, isPrerendered, loadPayload, preloadPayload, definePayloadReducer, definePayloadReviver, getAppManifest, getRouteRules, reloadNuxtApp, useRequestURL, usePreviewMode, useId, useRouteAnnouncer, useHead, useHeadSafe, useServerSeoMeta, useServerHeadSafe, useServerHead, useSeoMeta, injectHead, useRuntimeHook } from './composables/index.js';
5
- export type { AddRouteMiddlewareOptions, AsyncData, AsyncDataOptions, AsyncDataRequestStatus, CookieOptions, CookieRef, FetchResult, NuxtAppManifest, NuxtAppManifestMeta, NuxtError, Politeness, ReloadNuxtAppOptions, RouteMiddleware, UseFetchOptions } from './composables/index.js';
4
+ export { defineNuxtComponent, useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, useHydration, callOnce, useState, clearNuxtState, clearError, createError, isNuxtError, showError, useError, useFetch, useLazyFetch, useCookie, refreshCookie, onPrehydrate, prerenderRoutes, useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus, useResponseHeader, onNuxtReady, abortNavigation, addRouteMiddleware, defineNuxtRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter, preloadComponents, prefetchComponents, preloadRouteComponents, isPrerendered, loadPayload, preloadPayload, definePayloadReducer, definePayloadReviver, getAppManifest, getRouteRules, reloadNuxtApp, useRequestURL, usePreviewMode, useId, useRouteAnnouncer, useAnnouncer, useHead, useHeadSafe, useServerSeoMeta, useServerHeadSafe, useServerHead, useSeoMeta, injectHead, useRuntimeHook } from './composables/index.js';
5
+ export type { AddRouteMiddlewareOptions, AnnouncerPoliteness, AsyncData, AsyncDataOptions, AsyncDataRequestStatus, CookieOptions, CookieRef, FetchResult, NuxtAnnouncer, NuxtAnnouncerOpts, NuxtAppManifest, NuxtAppManifestMeta, NuxtError, Politeness, ReloadNuxtAppOptions, RouteMiddleware, UseFetchOptions } from './composables/index.js';
6
6
  export { defineNuxtLink } from './components/index.js';
7
7
  export type { NuxtLinkOptions, NuxtLinkProps, NuxtTimeProps } from './components/index.js';
8
8
  export { _getAppConfig, updateAppConfig, useAppConfig } from './config.js';
package/dist/app/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "../../dist/app/types/augments";
2
2
  export { applyPlugin, applyPlugins, callWithNuxt, createNuxtApp, defineAppConfig, defineNuxtPlugin, definePayloadPlugin, isNuxtPlugin, registerPluginHooks, tryUseNuxtApp, useNuxtApp, useRuntimeConfig } from "./nuxt.js";
3
- export { defineNuxtComponent, useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, useHydration, callOnce, useState, clearNuxtState, clearError, createError, isNuxtError, showError, useError, useFetch, useLazyFetch, useCookie, refreshCookie, onPrehydrate, prerenderRoutes, useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus, useResponseHeader, onNuxtReady, abortNavigation, addRouteMiddleware, defineNuxtRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter, preloadComponents, prefetchComponents, preloadRouteComponents, isPrerendered, loadPayload, preloadPayload, definePayloadReducer, definePayloadReviver, getAppManifest, getRouteRules, reloadNuxtApp, useRequestURL, usePreviewMode, useId, useRouteAnnouncer, useHead, useHeadSafe, useServerSeoMeta, useServerHeadSafe, useServerHead, useSeoMeta, injectHead, useRuntimeHook } from "./composables/index.js";
3
+ export { defineNuxtComponent, useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, useHydration, callOnce, useState, clearNuxtState, clearError, createError, isNuxtError, showError, useError, useFetch, useLazyFetch, useCookie, refreshCookie, onPrehydrate, prerenderRoutes, useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus, useResponseHeader, onNuxtReady, abortNavigation, addRouteMiddleware, defineNuxtRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter, preloadComponents, prefetchComponents, preloadRouteComponents, isPrerendered, loadPayload, preloadPayload, definePayloadReducer, definePayloadReviver, getAppManifest, getRouteRules, reloadNuxtApp, useRequestURL, usePreviewMode, useId, useRouteAnnouncer, useAnnouncer, useHead, useHeadSafe, useServerSeoMeta, useServerHeadSafe, useServerHead, useSeoMeta, injectHead, useRuntimeHook } from "./composables/index.js";
4
4
  export { defineNuxtLink } from "./components/index.js";
5
5
  export { _getAppConfig, updateAppConfig, useAppConfig } from "./config.js";
6
6
  export { cancelIdleCallback, requestIdleCallback } from "./compat/idle-callback.js";