@wpnuxt/core 2.0.0-alpha.5 → 2.0.0-alpha.7
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/dist/module.json
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { getRelativeImagePath } from "../util/images.js";
|
|
2
2
|
import { computed, ref, watch as vueWatch, useAsyncGraphqlQuery } from "#imports";
|
|
3
|
-
function defaultGetCachedData(key, nuxtApp, ctx) {
|
|
4
|
-
if (nuxtApp.isHydrating) {
|
|
5
|
-
return nuxtApp.payload.data[key];
|
|
6
|
-
}
|
|
7
|
-
if (ctx.cause === "refresh:manual" || ctx.cause === "refresh:hook") {
|
|
8
|
-
return void 0;
|
|
9
|
-
}
|
|
10
|
-
return nuxtApp.payload.data[key] ?? nuxtApp.static.data[key];
|
|
11
|
-
}
|
|
12
3
|
export const useWPContent = (queryName, nodes, fixImagePaths, params, options) => {
|
|
13
4
|
const {
|
|
14
5
|
clientCache,
|
|
15
|
-
cacheKey,
|
|
16
6
|
getCachedData: userGetCachedData,
|
|
17
7
|
retry: retryOption,
|
|
18
8
|
retryDelay: retryDelayOption,
|
|
@@ -23,12 +13,7 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
|
|
|
23
13
|
const baseRetryDelay = retryDelayOption ?? 1e3;
|
|
24
14
|
const retryCount = ref(0);
|
|
25
15
|
const isRetrying = ref(false);
|
|
26
|
-
const timeoutMs = timeoutOption ??
|
|
27
|
-
const graphqlCaching = clientCache === false ? { client: false } : restOptions.graphqlCaching ?? { client: true };
|
|
28
|
-
const paramsKey = params ? JSON.stringify(params) : "{}";
|
|
29
|
-
const baseKey = `wpnuxt-${String(queryName)}-${paramsKey}`;
|
|
30
|
-
const finalKey = cacheKey ? `${baseKey}-${cacheKey}` : baseKey;
|
|
31
|
-
const effectiveGetCachedData = userGetCachedData ?? (clientCache === false ? () => void 0 : defaultGetCachedData);
|
|
16
|
+
const timeoutMs = timeoutOption ?? 0;
|
|
32
17
|
let abortController;
|
|
33
18
|
let timeoutId;
|
|
34
19
|
if (timeoutMs > 0) {
|
|
@@ -40,12 +25,21 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
|
|
|
40
25
|
}
|
|
41
26
|
}, timeoutMs);
|
|
42
27
|
}
|
|
43
|
-
const
|
|
28
|
+
const ssgGetCachedData = userGetCachedData ?? (clientCache === false ? () => void 0 : (key, app, ctx) => {
|
|
29
|
+
if (app.isHydrating) {
|
|
30
|
+
return app.payload.data[key];
|
|
31
|
+
}
|
|
32
|
+
if (ctx.cause === "refresh:manual" || ctx.cause === "refresh:hook") {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
return app.static?.data?.[key] ?? app.payload.data[key] ?? app.$graphqlCache?.get(key);
|
|
36
|
+
});
|
|
37
|
+
const asyncDataOptions = {
|
|
44
38
|
...restOptions,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
// Our getCachedData that properly checks static.data for SSG
|
|
40
|
+
getCachedData: ssgGetCachedData,
|
|
41
|
+
// Enable graphql caching so the LRU cache is populated for subsequent navigations
|
|
42
|
+
graphqlCaching: { client: clientCache !== false },
|
|
49
43
|
// Pass abort signal for timeout support
|
|
50
44
|
...abortController && {
|
|
51
45
|
fetchOptions: {
|
|
@@ -55,9 +49,9 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
|
|
|
55
49
|
}
|
|
56
50
|
};
|
|
57
51
|
const { data, pending, refresh, execute, clear, error, status } = useAsyncGraphqlQuery(
|
|
58
|
-
queryName,
|
|
52
|
+
String(queryName),
|
|
59
53
|
params ?? {},
|
|
60
|
-
|
|
54
|
+
asyncDataOptions
|
|
61
55
|
);
|
|
62
56
|
const transformError = ref(null);
|
|
63
57
|
if (timeoutId !== void 0) {
|
|
@@ -66,7 +60,7 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
|
|
|
66
60
|
clearTimeout(timeoutId);
|
|
67
61
|
timeoutId = void 0;
|
|
68
62
|
}
|
|
69
|
-
});
|
|
63
|
+
}, { immediate: true });
|
|
70
64
|
}
|
|
71
65
|
if (maxRetries > 0) {
|
|
72
66
|
vueWatch(error, async (newError) => {
|