nuxt-custom-fetch 4.5.0 → 4.6.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.
- package/README.md +12 -6
- package/dist/module.json +5 -2
- package/dist/module.mjs +3 -1
- package/dist/runtime/ajax.js +29 -4
- package/package.json +26 -29
package/README.md
CHANGED
|
@@ -14,9 +14,11 @@ Use `CustomFetch` when you specifically need an extra request layer on top of th
|
|
|
14
14
|
|
|
15
15
|
## Compatibility
|
|
16
16
|
|
|
17
|
-
- `v4`: Nuxt
|
|
17
|
+
- `v4`: Nuxt `^4.5.0` (Nuxt 4 only)
|
|
18
18
|
- `v2`: Nuxt `3.0.0` to `3.16.x`
|
|
19
19
|
|
|
20
|
+
The development playground targets Nuxt `4.6.2` and Vue `3.5.44`. Nuxt `4.6.2` requires Node.js `^22.22.3 || ^24.15.0 || >=26.0.0`. Nuxt 5 is still in development and is not included in this module's compatibility range.
|
|
21
|
+
|
|
20
22
|
## Current Maintenance Summary
|
|
21
23
|
|
|
22
24
|
The current implementation is maintained around these guarantees:
|
|
@@ -26,8 +28,9 @@ The current implementation is maintained around these guarantees:
|
|
|
26
28
|
- reactive `key`, `baseURL`, `params`, `query`, `headers`, `body`, and `cache` values are resolved before each request
|
|
27
29
|
- generated keys are derived with Nuxt's `hashKey` (the same digest `useFetch` uses) and include both `params` and `query`, which avoids stale client reuse when only one side changes
|
|
28
30
|
- same-key client compatibility requests share one async-data bucket, so `dedupe: 'cancel'` can abort the previous pending request
|
|
29
|
-
- the client compatibility path mirrors Nuxt 4 async-data behavior: `pending` follows the `pendingWhenIdle` config, `refreshNuxtData()` (the `app:data:refresh` hook) re-runs fallback requests, `getCachedData` is honored and successful data is written back to `nuxtApp.payload.data`
|
|
31
|
+
- the client compatibility path mirrors Nuxt 4 async-data behavior: `pending` follows the `pendingWhenIdle` config, `refreshNuxtData()` (the `app:data:refresh` hook) re-runs fallback requests, `getCachedData` is honored and successful data is written back to `nuxtApp.payload.data` unless `serialize: false` is set
|
|
30
32
|
- the client compatibility path honors Nuxt 4.5's `enabled` option (a reactive `enabled` turning `false` cancels the in-flight request) and cancels an in-flight request when its owning scope is disposed
|
|
33
|
+
- on Nuxt 4.6, the client compatibility path also honors async-data `middleware` (first entry outermost, before `transform`/`pick`) and `serialize: false`, including cached results
|
|
31
34
|
- timeouts and external abort signals are merged into one request signal (via `AbortSignal.timeout`/`AbortSignal.any` semantics), key watchers are only created for reactive keys, and a key change re-runs the request when `immediate`, prior data, or an in-flight request is present
|
|
32
35
|
- Vitest runtime tests and TypeScript type tests cover the wrapper behavior
|
|
33
36
|
|
|
@@ -41,7 +44,7 @@ The current implementation is maintained around these guarantees:
|
|
|
41
44
|
- param or query preprocessing through `handler`
|
|
42
45
|
- one request API that still works after mount on the client
|
|
43
46
|
|
|
44
|
-
If all you need is a typed composable with shared defaults, prefer Nuxt's official factories:
|
|
47
|
+
If all you need is a typed composable with shared defaults, prefer Nuxt's official factories. Nuxt 4.6 also adds `defineUseFetchAddon` and `defineUseAsyncDataAddon` for reusable options, middleware, and return-value extensions:
|
|
45
48
|
|
|
46
49
|
```ts
|
|
47
50
|
export const useAPI = createUseFetch({
|
|
@@ -60,7 +63,7 @@ export const useCachedData = createUseAsyncData({
|
|
|
60
63
|
- After hydration on the client, calls made outside component setup (event handlers, lifecycle hooks such as `onMounted`, watchers) fall back to a compatibility mode. This is the same condition under which Nuxt warns "Component is already mounted".
|
|
61
64
|
- The compatibility mode still exposes `data`, `error`, `status`, `pending`, `refresh`, `execute`, and `clear`.
|
|
62
65
|
- The compatibility mode is not a full SSR payload or cache replacement.
|
|
63
|
-
- Calls that intentionally share the same `key` should keep `handler`, `deep`, `transform`, `pick`, `getCachedData`, and `default` consistent, matching Nuxt's keyed async-data rules.
|
|
66
|
+
- Calls that intentionally share the same `key` should keep `handler`, `deep`, `transform`, `pick`, `getCachedData`, and `default` consistent, matching Nuxt's keyed async-data rules. On Nuxt 4.6, keep `middleware` and `serialize` consistent too.
|
|
64
67
|
|
|
65
68
|
## Installation
|
|
66
69
|
|
|
@@ -165,7 +168,7 @@ The remaining helper names follow the same rule: `getPageList` is the plain non-
|
|
|
165
168
|
|
|
166
169
|
## Upgrading From 4.4.x
|
|
167
170
|
|
|
168
|
-
- Nuxt
|
|
171
|
+
- Nuxt `^4.5.0` is required.
|
|
169
172
|
- Calls made in `setup` during client-side navigation now go through `useAsyncData`, so `lazy: true` no longer blocks navigation and `server`/`enabled` follow Nuxt's rules. Calls from event handlers, `onMounted`, or watchers still use the compatibility mode.
|
|
170
173
|
- Errors thrown by `useAsyncData` are no longer swallowed and turned into a fallback.
|
|
171
174
|
- Requests are sent with `query` only; `params` is merged into it. Interceptors still see `options.params`, which ofetch mirrors from `query`.
|
|
@@ -227,7 +230,7 @@ Available methods:
|
|
|
227
230
|
- `ajax.post(url, config?, asyncDataOptions?)`
|
|
228
231
|
- `ajax.request(url, { method, ...config }, asyncDataOptions?)`
|
|
229
232
|
|
|
230
|
-
The return value follows Nuxt's `AsyncData<...>` shape and can use the same `default`, `pick`, `transform`, `watch`, `dedupe`, `timeout`, and `enabled` options you already know from `useAsyncData`.
|
|
233
|
+
The return value follows Nuxt's `AsyncData<...>` shape and can use the same `default`, `pick`, `transform`, `watch`, `dedupe`, `timeout`, and `enabled` options you already know from `useAsyncData`. Nuxt 4.6 additionally provides `serialize` and `middleware`.
|
|
231
234
|
|
|
232
235
|
`showLogs` defaults to `true` in development and prints each client request with `console.info` (real problems such as an unserializable body still use `console.warn`). Set `showLogs: false` to silence it.
|
|
233
236
|
|
|
@@ -256,6 +259,9 @@ The return value follows Nuxt's `AsyncData<...>` shape and can use the same `def
|
|
|
256
259
|
|
|
257
260
|
## References
|
|
258
261
|
|
|
262
|
+
- https://github.com/nuxt/nuxt/releases/tag/v4.6.0
|
|
263
|
+
- https://github.com/nuxt/nuxt/releases/tag/v4.6.2
|
|
264
|
+
- https://nuxt.com/docs/4.x/api/utils/define-use-fetch-addon
|
|
259
265
|
- https://nuxt.com/docs/4.x/api/composables/create-use-async-data
|
|
260
266
|
- https://nuxt.com/docs/4.x/api/composables/create-use-fetch
|
|
261
267
|
- https://nuxt.com/docs/4.x/api/composables/use-async-data
|
package/dist/module.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-custom-fetch",
|
|
3
3
|
"configKey": "customFetch",
|
|
4
|
-
"
|
|
4
|
+
"compatibility": {
|
|
5
|
+
"nuxt": "^4.5.0"
|
|
6
|
+
},
|
|
7
|
+
"version": "4.6.0",
|
|
5
8
|
"builder": {
|
|
6
|
-
"@nuxt/module-builder": "1.0.
|
|
9
|
+
"@nuxt/module-builder": "1.0.3",
|
|
7
10
|
"unbuild": "unknown"
|
|
8
11
|
}
|
|
9
12
|
}
|
package/dist/module.mjs
CHANGED
package/dist/runtime/ajax.js
CHANGED
|
@@ -259,6 +259,7 @@ export class CustomFetch {
|
|
|
259
259
|
};
|
|
260
260
|
const nuxtApp = useNuxtApp();
|
|
261
261
|
const createClientAsyncDataFallback = () => {
|
|
262
|
+
const fallbackOptions = options;
|
|
262
263
|
const _ref = options.deep ? ref : shallowRef;
|
|
263
264
|
const usePendingRef = pendingWhenIdle;
|
|
264
265
|
const getDefaultValue = () => {
|
|
@@ -280,7 +281,7 @@ export class CustomFetch {
|
|
|
280
281
|
return void 0;
|
|
281
282
|
};
|
|
282
283
|
const writePayloadData = (value) => {
|
|
283
|
-
if (nuxtApp.payload?.data) {
|
|
284
|
+
if (fallbackOptions.serialize !== false && nuxtApp.payload?.data) {
|
|
284
285
|
nuxtApp.payload.data[key.value] = value;
|
|
285
286
|
}
|
|
286
287
|
};
|
|
@@ -368,10 +369,33 @@ export class CustomFetch {
|
|
|
368
369
|
setPending(true);
|
|
369
370
|
asyncData.status.value = "pending";
|
|
370
371
|
asyncData.error.value = asyncDataDefaults.errorValue;
|
|
371
|
-
|
|
372
|
+
const signal = createMergedSignal([controller?.signal], executeOptions?.timeout ?? options.timeout);
|
|
373
|
+
let run = () => executeRequest({
|
|
372
374
|
...executeOptions,
|
|
373
|
-
signal
|
|
374
|
-
})
|
|
375
|
+
signal
|
|
376
|
+
});
|
|
377
|
+
for (let i = (fallbackOptions.middleware?.length ?? 0) - 1; i >= 0; i--) {
|
|
378
|
+
const middleware = fallbackOptions.middleware[i];
|
|
379
|
+
const next = run;
|
|
380
|
+
run = () => Promise.resolve(middleware(next, { signal }));
|
|
381
|
+
}
|
|
382
|
+
let request;
|
|
383
|
+
let removeAbortListener;
|
|
384
|
+
try {
|
|
385
|
+
request = fallbackOptions.middleware?.length ? new Promise((resolve, reject) => {
|
|
386
|
+
const onAbort = () => reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
387
|
+
if (signal?.aborted) {
|
|
388
|
+
onAbort();
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
392
|
+
removeAbortListener = () => signal?.removeEventListener("abort", onAbort);
|
|
393
|
+
Promise.resolve(run()).then(resolve, reject);
|
|
394
|
+
}) : run();
|
|
395
|
+
} catch (error) {
|
|
396
|
+
request = Promise.reject(error);
|
|
397
|
+
}
|
|
398
|
+
activeRequest = request.then(async (result) => {
|
|
375
399
|
if (currentRequestId !== requestId) {
|
|
376
400
|
return;
|
|
377
401
|
}
|
|
@@ -398,6 +422,7 @@ export class CustomFetch {
|
|
|
398
422
|
asyncData.data.value = getDefaultValue();
|
|
399
423
|
asyncData.status.value = "error";
|
|
400
424
|
}).finally(() => {
|
|
425
|
+
removeAbortListener?.();
|
|
401
426
|
if (currentRequestId !== requestId) {
|
|
402
427
|
return;
|
|
403
428
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-custom-fetch",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
5
|
-
"packageManager": "pnpm@11.7.0",
|
|
4
|
+
"version": "4.6.0",
|
|
6
5
|
"license": "MIT",
|
|
7
6
|
"repository": {
|
|
8
7
|
"type": "git",
|
|
@@ -18,43 +17,26 @@
|
|
|
18
17
|
"files": [
|
|
19
18
|
"dist"
|
|
20
19
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"prepack": "nuxt-module-build build",
|
|
23
|
-
"dev": "nuxi dev playground",
|
|
24
|
-
"dev:build": "nuxi build playground",
|
|
25
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
26
|
-
"echo:husky": "echo 'npx nano-staged' > .husky/pre-commit && echo 'npx --no-install commitlint --edit \"$1\"' > .husky/commit-msg",
|
|
27
|
-
"lint": "eslint .",
|
|
28
|
-
"lint:fix": "eslint . --fix",
|
|
29
|
-
"test": "vitest run",
|
|
30
|
-
"test:watch": "vitest",
|
|
31
|
-
"test:coverage": "vitest run --coverage",
|
|
32
|
-
"test:types": "tsc -p tsconfig.json --noEmit",
|
|
33
|
-
"prepare": "husky",
|
|
34
|
-
"commit": "git-cz",
|
|
35
|
-
"release:alpha": "changelogen --release --prerelease && pnpm prepack && npm publish --tag alpha && git push --follow-tags",
|
|
36
|
-
"release": "changelogen --release && pnpm prepack && npm publish && git push --follow-tags"
|
|
37
|
-
},
|
|
38
20
|
"config": {
|
|
39
21
|
"commitizen": {
|
|
40
22
|
"path": "node_modules/cz-git"
|
|
41
23
|
}
|
|
42
24
|
},
|
|
43
25
|
"peerDependencies": {
|
|
44
|
-
"nuxt": "
|
|
26
|
+
"nuxt": "^4.5.0",
|
|
45
27
|
"vue": "^3.5.30"
|
|
46
28
|
},
|
|
47
29
|
"dependencies": {
|
|
48
|
-
"@vue/shared": "^3.5.
|
|
49
|
-
"ohash": "^2.0.
|
|
30
|
+
"@vue/shared": "^3.5.44",
|
|
31
|
+
"ohash": "^2.0.12"
|
|
50
32
|
},
|
|
51
33
|
"devDependencies": {
|
|
52
34
|
"@antfu/eslint-config": "^9.0.0",
|
|
53
35
|
"@commitlint/cli": "^21.0.2",
|
|
54
36
|
"@commitlint/config-conventional": "^21.0.2",
|
|
55
|
-
"@nuxt/kit": "4.
|
|
56
|
-
"@nuxt/module-builder": "^1.0.
|
|
57
|
-
"@nuxt/schema": "4.
|
|
37
|
+
"@nuxt/kit": "4.6.2",
|
|
38
|
+
"@nuxt/module-builder": "^1.0.3",
|
|
39
|
+
"@nuxt/schema": "4.6.2",
|
|
58
40
|
"@types/node": "^25.5.0",
|
|
59
41
|
"@vitest/coverage-v8": "^4.1.9",
|
|
60
42
|
"changelogen": "^0.6.2",
|
|
@@ -63,11 +45,11 @@
|
|
|
63
45
|
"eslint": "^10.0.3",
|
|
64
46
|
"husky": "^9.1.7",
|
|
65
47
|
"nano-staged": "^1.0.2",
|
|
66
|
-
"nitropack": "^2.13.
|
|
67
|
-
"nuxt": "4.
|
|
48
|
+
"nitropack": "^2.13.5",
|
|
49
|
+
"nuxt": "4.6.2",
|
|
68
50
|
"typescript": "6.0.3",
|
|
69
51
|
"vitest": "^4.1.9",
|
|
70
|
-
"vue": "^3.5.
|
|
52
|
+
"vue": "^3.5.44"
|
|
71
53
|
},
|
|
72
54
|
"husky": {
|
|
73
55
|
"hooks": {
|
|
@@ -76,5 +58,20 @@
|
|
|
76
58
|
},
|
|
77
59
|
"nano-staged": {
|
|
78
60
|
"*": "eslint --fix"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "nuxi dev playground",
|
|
64
|
+
"dev:build": "nuxi build playground",
|
|
65
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
66
|
+
"echo:husky": "echo 'npx nano-staged' > .husky/pre-commit && echo 'npx --no-install commitlint --edit \"$1\"' > .husky/commit-msg",
|
|
67
|
+
"lint": "eslint .",
|
|
68
|
+
"lint:fix": "eslint . --fix",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"test:watch": "vitest",
|
|
71
|
+
"test:coverage": "vitest run --coverage",
|
|
72
|
+
"test:types": "tsc -p tsconfig.json --noEmit",
|
|
73
|
+
"commit": "git-cz",
|
|
74
|
+
"release:alpha": "changelogen --release --prerelease && pnpm prepack && npm publish --tag alpha && git push --follow-tags",
|
|
75
|
+
"release": "changelogen --release && pnpm prepack && npm publish && git push --follow-tags"
|
|
79
76
|
}
|
|
80
|
-
}
|
|
77
|
+
}
|