@quvel-kit/core 1.3.13 → 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.
@@ -4,17 +4,17 @@
4
4
  * Fetches data during SSR, serializes to client, and hydrates on mount.
5
5
  * Eliminates the need for a Pinia store per page for SSR data loading.
6
6
  */
7
- import { type Ref, type ComputedRef } from 'vue';
7
+ import { type Ref } from 'vue';
8
8
  /**
9
9
  * SSR data loading composable
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, loading state, and error state
13
+ * @returns Reactive data ref and error state
14
14
  *
15
15
  * @example
16
16
  * ```typescript
17
- * const { data: household, isLoading, error } = useSSRData(
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, type ComputedRef } from 'vue';
22
22
  */
23
23
  export declare function useSSRData<T>(key: string, fetcher: () => Promise<T>): {
24
24
  data: Ref<T | null>;
25
- isLoading: ComputedRef<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,EAA8C,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAM7F;;;;;;;;;;;;;;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,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAChC,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAC1B,CAgDA"}
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"}
@@ -4,7 +4,7 @@
4
4
  * Fetches data during SSR, serializes to client, and hydrates on mount.
5
5
  * Eliminates the need for a Pinia store per page for SSR data loading.
6
6
  */
7
- import { ref, computed, onMounted, onServerPrefetch } from 'vue';
7
+ 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_';
@@ -13,11 +13,11 @@ const SSR_ERROR_PREFIX = '__SSR_ERROR_';
13
13
  *
14
14
  * @param key - Unique key for this data (used for serialization)
15
15
  * @param fetcher - Async function that fetches the data
16
- * @returns Reactive data ref, loading state, and error state
16
+ * @returns Reactive data ref and error state
17
17
  *
18
18
  * @example
19
19
  * ```typescript
20
- * const { data: household, isLoading, error } = useSSRData(
20
+ * const { data: household, error } = useSSRData(
21
21
  * `household-${route.params.id}`,
22
22
  * () => householdService.get(route.params.id)
23
23
  * );
@@ -28,9 +28,24 @@ export function useSSRData(key, fetcher) {
28
28
  const container = useQuvel();
29
29
  const dataKey = `${SSR_DATA_PREFIX}${key}`;
30
30
  const errorKey = `${SSR_ERROR_PREFIX}${key}`;
31
- const data = ref(null);
32
- const error = ref(null);
33
- const isLoading = computed(() => data.value === null && error.value === null);
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);
34
49
  if (isSSR) {
35
50
  onServerPrefetch(async () => {
36
51
  try {
@@ -45,30 +60,15 @@ export function useSSRData(key, fetcher) {
45
60
  }
46
61
  });
47
62
  }
48
- else {
63
+ else if (initialData === null && initialError === null) {
49
64
  onMounted(async () => {
50
- const win = window;
51
- const ssrData = win[dataKey];
52
- const ssrError = win[errorKey];
53
- delete win[dataKey];
54
- delete win[errorKey];
55
- if (ssrError) {
56
- const err = new Error(ssrError.message);
57
- err.name = ssrError.name;
58
- error.value = err;
59
- }
60
- else if (ssrData !== undefined) {
61
- data.value = ssrData;
65
+ try {
66
+ data.value = await fetcher();
62
67
  }
63
- else {
64
- try {
65
- data.value = await fetcher();
66
- }
67
- catch (e) {
68
- error.value = e instanceof Error ? e : new Error(String(e));
69
- }
68
+ catch (e) {
69
+ error.value = e instanceof Error ? e : new Error(String(e));
70
70
  }
71
71
  });
72
72
  }
73
- return { data, isLoading, error };
73
+ return { data, error };
74
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quvel-kit/core",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "Core utilities for Quvel UI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",