Skip to content

Commit 42ebfd0

Browse files
committed
fix(vue): show content no matter what if fallback us provided
1 parent 07e90cc commit 42ebfd0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/components-vue/src/components/loader/ContentFetch.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v-bind="{
55
content: !!content && patchedIsContent(content) && firstLoad,
66
errors,
7-
loading: loading,
7+
loading,
88
refresh,
99
unwrap,
1010
theme,
@@ -38,6 +38,7 @@
3838
import type { iVuePluginOptions } from "../../types/plugin";
3939
import { useAsyncDataFn } from "../../composables/async";
4040
import { useHelpers } from "../../composables/utils";
41+
import useFetchUtils from "../../composables/fetch";
4142
4243
export interface iLoaderContentFetchProps<Ti, Pi extends any[]> extends iUseThemeProps {
4344
noContentMessage?: string;
@@ -102,6 +103,7 @@
102103
const emit = defineEmits(["refresh"]);
103104
104105
const { logger } = useHelpers(useUtils);
106+
const { useFetch } = useFetchUtils();
105107
const { internals } = inject<iVuePluginOptions>("xamu") || {};
106108
const useAsyncData: typeof useAsyncDataFn = internals?.useAsyncData ?? useAsyncDataFn;
107109
@@ -144,6 +146,7 @@
144146
let newData: T | null = null;
145147
146148
try {
149+
if (props.fallback) firstLoad.value = true; // use fallback while the real content loads
147150
if (!props.promise && !props.hydratablePromise && !props.url) return null;
148151
if (props.preventAutoload) {
149152
// is promise like
@@ -152,7 +155,6 @@
152155
// Prevent on first load or if url is used as key
153156
if (!firstLoad.value || (!!props.url && pl)) return null;
154157
}
155-
if (props.fallback) firstLoad.value = true; // use fallback while the real content loads
156158
if (props.promise || props.hydratablePromise) {
157159
const payload = <P>(props.payload || []);
158160
@@ -165,7 +167,7 @@
165167
)(...payload);
166168
}
167169
} else if (props.url) {
168-
const response = await (await fetch(props.url)).json();
170+
const response = await useFetch<any>(props.url);
169171
const data = "data" in response ? response.data : response;
170172
171173
if (response.error) throw new Error(response.error);
@@ -202,7 +204,7 @@
202204
*/
203205
const possibleSamePromise = !!newPromise && !!oldPromise;
204206
205-
// prevent muntiple requests
207+
// prevent multiple requests
206208
if (newPromise === oldPromise || !!possibleSamePromise) return;
207209
208210
// refresh

packages/components-vue/src/composables/fetch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function useFetchUtils() {
2121

2222
if (ofetch) return ofetch(url, { cache: "force-cache" });
2323

24+
// Fallback to default fetch
2425
return (await fetch(url, { cache: "force-cache" })).json();
2526
}
2627

0 commit comments

Comments
 (0)