@tanstack/svelte-query 6.2.2 → 6.2.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.svelte.d.ts","sourceRoot":"","sources":["../src/createBaseQuery.svelte.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createBaseQuery.svelte.d.ts","sourceRoot":"","sources":["../src/createBaseQuery.svelte.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EACV,QAAQ,EACR,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,QAAQ,CACf,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAC3E,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAkGtC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onDestroy } from 'svelte';
|
|
1
2
|
import { useIsRestoring } from './useIsRestoring.js';
|
|
2
3
|
import { useQueryClient } from './useQueryClient.js';
|
|
3
4
|
import { createRawRef } from './containers.svelte.js';
|
|
@@ -32,13 +33,30 @@ export function createBaseQuery(options, Observer, queryClient) {
|
|
|
32
33
|
const [query, update] = createRawRef(
|
|
33
34
|
// svelte-ignore state_referenced_locally - intentional, initial value
|
|
34
35
|
createResult());
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
// The following is convoluted but necessary:
|
|
37
|
+
// Call eagerly so subscription happens on the server and on suspended branches in the client...
|
|
38
|
+
let unsubscribe = isRestoring.current && typeof window !== 'undefined'
|
|
39
|
+
? () => undefined
|
|
40
|
+
: observer.subscribe(() => update(createResult()));
|
|
41
|
+
// ...but also watch for state changes to resubscribe, and because Svelte right now doesn't
|
|
42
|
+
// run onDestroy on components with pending work that are destroyed again before they are resolved...
|
|
43
|
+
watchChanges(() => [isRestoring.current, observer], 'pre', () => {
|
|
44
|
+
unsubscribe();
|
|
45
|
+
unsubscribe = isRestoring.current
|
|
37
46
|
? () => undefined
|
|
38
47
|
: observer.subscribe(() => update(createResult()));
|
|
39
48
|
observer.updateResult();
|
|
40
49
|
return unsubscribe;
|
|
41
50
|
});
|
|
51
|
+
// ...and finally also cleanup via onDestroy because that one runs on the server whereas $effect.pre does not.
|
|
52
|
+
// (in a try-catch because it theoretically can be called in a non-component context - that should not happen
|
|
53
|
+
// but it would be a breaking change technically to error out here. SSR-safe because this wouldn't be called during SSR if it was not in a component)
|
|
54
|
+
try {
|
|
55
|
+
onDestroy(() => {
|
|
56
|
+
unsubscribe();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (e) { }
|
|
42
60
|
watchChanges(() => resolvedOptions, 'pre', () => {
|
|
43
61
|
observer.setOptions(resolvedOptions);
|
|
44
62
|
});
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onDestroy } from 'svelte'
|
|
1
2
|
import { useIsRestoring } from './useIsRestoring.js'
|
|
2
3
|
import { useQueryClient } from './useQueryClient.js'
|
|
3
4
|
import { createRawRef } from './containers.svelte.js'
|
|
@@ -71,13 +72,34 @@ export function createBaseQuery<
|
|
|
71
72
|
createResult(),
|
|
72
73
|
)
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
// The following is convoluted but necessary:
|
|
76
|
+
// Call eagerly so subscription happens on the server and on suspended branches in the client...
|
|
77
|
+
let unsubscribe =
|
|
78
|
+
isRestoring.current && typeof window !== 'undefined'
|
|
76
79
|
? () => undefined
|
|
77
80
|
: observer.subscribe(() => update(createResult()))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
// ...but also watch for state changes to resubscribe, and because Svelte right now doesn't
|
|
82
|
+
// run onDestroy on components with pending work that are destroyed again before they are resolved...
|
|
83
|
+
watchChanges(
|
|
84
|
+
() => [isRestoring.current, observer] as const,
|
|
85
|
+
'pre',
|
|
86
|
+
() => {
|
|
87
|
+
unsubscribe()
|
|
88
|
+
unsubscribe = isRestoring.current
|
|
89
|
+
? () => undefined
|
|
90
|
+
: observer.subscribe(() => update(createResult()))
|
|
91
|
+
observer.updateResult()
|
|
92
|
+
return unsubscribe
|
|
93
|
+
},
|
|
94
|
+
)
|
|
95
|
+
// ...and finally also cleanup via onDestroy because that one runs on the server whereas $effect.pre does not.
|
|
96
|
+
// (in a try-catch because it theoretically can be called in a non-component context - that should not happen
|
|
97
|
+
// but it would be a breaking change technically to error out here. SSR-safe because this wouldn't be called during SSR if it was not in a component)
|
|
98
|
+
try {
|
|
99
|
+
onDestroy(() => {
|
|
100
|
+
unsubscribe()
|
|
101
|
+
})
|
|
102
|
+
} catch (e) {}
|
|
81
103
|
|
|
82
104
|
watchChanges(
|
|
83
105
|
() => resolvedOptions,
|