@wpnuxt/core 2.0.0-alpha.3 → 2.0.0-alpha.4
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,9 +1,27 @@
|
|
|
1
1
|
import { getRelativeImagePath } from "../util/images.js";
|
|
2
2
|
import { computed, 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
|
+
}
|
|
3
12
|
export const useWPContent = (queryName, nodes, fixImagePaths, params, options) => {
|
|
13
|
+
const { clientCache, cacheKey, getCachedData: userGetCachedData, ...restOptions } = options ?? {};
|
|
14
|
+
const graphqlCaching = clientCache === false ? { client: false } : restOptions.graphqlCaching ?? { client: true };
|
|
15
|
+
const paramsKey = params ? JSON.stringify(params) : "{}";
|
|
16
|
+
const baseKey = `wpnuxt-${String(queryName)}-${paramsKey}`;
|
|
17
|
+
const finalKey = cacheKey ? `${baseKey}-${cacheKey}` : baseKey;
|
|
18
|
+
const effectiveGetCachedData = userGetCachedData ?? (clientCache === false ? () => void 0 : defaultGetCachedData);
|
|
4
19
|
const mergedOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
20
|
+
...restOptions,
|
|
21
|
+
graphqlCaching,
|
|
22
|
+
// Explicit key ensures consistent cache lookups
|
|
23
|
+
key: finalKey,
|
|
24
|
+
getCachedData: effectiveGetCachedData
|
|
7
25
|
};
|
|
8
26
|
const { data, pending, refresh, execute, clear, error, status } = useAsyncGraphqlQuery(
|
|
9
27
|
queryName,
|