@quvel-kit/core 1.3.11 → 1.3.14
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.
|
@@ -10,11 +10,11 @@ import { type Ref } from 'vue';
|
|
|
10
10
|
*
|
|
11
11
|
* @param key - Unique key for this data (used for serialization)
|
|
12
12
|
* @param fetcher - Async function that fetches the data
|
|
13
|
-
* @returns Reactive data ref
|
|
13
|
+
* @returns Reactive data ref and error state
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* const { data: household,
|
|
17
|
+
* const { data: household, error } = useSSRData(
|
|
18
18
|
* `household-${route.params.id}`,
|
|
19
19
|
* () => householdService.get(route.params.id)
|
|
20
20
|
* );
|
|
@@ -22,7 +22,6 @@ import { type Ref } from 'vue';
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function useSSRData<T>(key: string, fetcher: () => Promise<T>): {
|
|
24
24
|
data: Ref<T | null>;
|
|
25
|
-
isLoading: Ref<boolean>;
|
|
26
25
|
error: Ref<Error | null>;
|
|
27
26
|
};
|
|
28
27
|
//# sourceMappingURL=useSSRData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSSRData.d.ts","sourceRoot":"","sources":["../../src/composables/useSSRData.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"useSSRData.d.ts","sourceRoot":"","sources":["../../src/composables/useSSRData.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAMjE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB;IACD,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAC1B,CAkDA"}
|
|
@@ -8,25 +8,16 @@ import { ref, onMounted, onServerPrefetch } from 'vue';
|
|
|
8
8
|
import { useQuvel } from './useQuvel.js';
|
|
9
9
|
const SSR_DATA_PREFIX = '__SSR_DATA_';
|
|
10
10
|
const SSR_ERROR_PREFIX = '__SSR_ERROR_';
|
|
11
|
-
/**
|
|
12
|
-
* Check if SSR data exists in window (for initial state)
|
|
13
|
-
*/
|
|
14
|
-
function hasSSRData(key) {
|
|
15
|
-
if (typeof window === 'undefined')
|
|
16
|
-
return false;
|
|
17
|
-
const win = window;
|
|
18
|
-
return win[`${SSR_DATA_PREFIX}${key}`] !== undefined;
|
|
19
|
-
}
|
|
20
11
|
/**
|
|
21
12
|
* SSR data loading composable
|
|
22
13
|
*
|
|
23
14
|
* @param key - Unique key for this data (used for serialization)
|
|
24
15
|
* @param fetcher - Async function that fetches the data
|
|
25
|
-
* @returns Reactive data ref
|
|
16
|
+
* @returns Reactive data ref and error state
|
|
26
17
|
*
|
|
27
18
|
* @example
|
|
28
19
|
* ```typescript
|
|
29
|
-
* const { data: household,
|
|
20
|
+
* const { data: household, error } = useSSRData(
|
|
30
21
|
* `household-${route.params.id}`,
|
|
31
22
|
* () => householdService.get(route.params.id)
|
|
32
23
|
* );
|
|
@@ -37,9 +28,24 @@ export function useSSRData(key, fetcher) {
|
|
|
37
28
|
const container = useQuvel();
|
|
38
29
|
const dataKey = `${SSR_DATA_PREFIX}${key}`;
|
|
39
30
|
const errorKey = `${SSR_ERROR_PREFIX}${key}`;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
let initialData = null;
|
|
32
|
+
let initialError = null;
|
|
33
|
+
if (!isSSR) {
|
|
34
|
+
const win = window;
|
|
35
|
+
const ssrData = win[dataKey];
|
|
36
|
+
const ssrError = win[errorKey];
|
|
37
|
+
if (ssrError) {
|
|
38
|
+
initialError = new Error(ssrError.message);
|
|
39
|
+
initialError.name = ssrError.name;
|
|
40
|
+
delete win[errorKey];
|
|
41
|
+
}
|
|
42
|
+
else if (ssrData !== undefined) {
|
|
43
|
+
initialData = ssrData;
|
|
44
|
+
delete win[dataKey];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const data = ref(initialData);
|
|
48
|
+
const error = ref(initialError);
|
|
43
49
|
if (isSSR) {
|
|
44
50
|
onServerPrefetch(async () => {
|
|
45
51
|
try {
|
|
@@ -52,40 +58,17 @@ export function useSSRData(key, fetcher) {
|
|
|
52
58
|
error.value = err;
|
|
53
59
|
container.windowBag?.set(errorKey, { message: err.message, name: err.name });
|
|
54
60
|
}
|
|
55
|
-
finally {
|
|
56
|
-
isLoading.value = false;
|
|
57
|
-
}
|
|
58
61
|
});
|
|
59
62
|
}
|
|
60
|
-
else {
|
|
63
|
+
else if (initialData === null && initialError === null) {
|
|
61
64
|
onMounted(async () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const ssrError = win[errorKey];
|
|
65
|
-
delete win[dataKey];
|
|
66
|
-
delete win[errorKey];
|
|
67
|
-
if (ssrError) {
|
|
68
|
-
const err = new Error(ssrError.message);
|
|
69
|
-
err.name = ssrError.name;
|
|
70
|
-
error.value = err;
|
|
71
|
-
isLoading.value = false;
|
|
72
|
-
}
|
|
73
|
-
else if (ssrData !== undefined) {
|
|
74
|
-
data.value = ssrData;
|
|
75
|
-
isLoading.value = false;
|
|
65
|
+
try {
|
|
66
|
+
data.value = await fetcher();
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
data.value = await fetcher();
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
error.value = e instanceof Error ? e : new Error(String(e));
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
isLoading.value = false;
|
|
86
|
-
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
error.value = e instanceof Error ? e : new Error(String(e));
|
|
87
70
|
}
|
|
88
71
|
});
|
|
89
72
|
}
|
|
90
|
-
return { data,
|
|
73
|
+
return { data, error };
|
|
91
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../src/utils/axios.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,aAAa,EAAqB,MAAM,OAAO,CAAC;AAE7D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAsCrD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CASnE;AAoBD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../src/utils/axios.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,aAAa,EAAqB,MAAM,OAAO,CAAC;AAE7D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAsCrD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CASnE;AAoBD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,aAAa,CA+D1G"}
|
package/dist/utils/axios.js
CHANGED
|
@@ -89,7 +89,6 @@ export function createApiInstance(ssrContext, appConfig) {
|
|
|
89
89
|
const instance = axios.create(axiosConfig);
|
|
90
90
|
let hasSessionCookie = false;
|
|
91
91
|
if (ssrContext) {
|
|
92
|
-
// Set Origin header so Sanctum recognizes SSR requests as stateful
|
|
93
92
|
const frontendUrl = appConfig?.frontend?.url || ssrContext.req?.headers?.origin;
|
|
94
93
|
if (frontendUrl) {
|
|
95
94
|
instance.defaults.headers.common['Origin'] = frontendUrl;
|