Skip to content

Commit 57fef62

Browse files
committed
refetch resourceNames
1 parent 4cba1bb commit 57fef62

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

.changeset/floppy-hats-say.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@viamrobotics/svelte-sdk': patch
3+
---
4+
5+
Refetch resourceNames if list is empty and connection established

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@ export default ts.config(
3535
svelteConfig,
3636
},
3737
},
38+
},
39+
{
40+
rules: {
41+
// Currently has false positives
42+
'svelte/prefer-svelte-reactivity': 'off',
43+
},
3844
}
3945
);

src/lib/hooks/resource-names.svelte.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ export const provideResourceNamesContext = () => {
7676
const clients = useRobotClients();
7777

7878
const partIDs = $derived(Object.keys(clients.current));
79-
const options = $derived(
80-
partIDs.map((partID) => {
81-
const client = clients.current[partID];
79+
const options = $derived.by(() => {
80+
const results = [];
8281

83-
return queryOptions({
82+
for (const partID of partIDs) {
83+
const client = clients.current[partID];
84+
const options = queryOptions({
8485
enabled: client !== undefined,
8586
queryKey: [
8687
'viam-svelte-sdk',
@@ -100,8 +101,12 @@ export const provideResourceNamesContext = () => {
100101
return resourceNames;
101102
},
102103
});
103-
})
104-
);
104+
105+
results.push(options);
106+
}
107+
108+
return results;
109+
});
105110

106111
const queries = fromStore(
107112
createQueries({
@@ -114,6 +119,18 @@ export const provideResourceNamesContext = () => {
114119
})
115120
);
116121

122+
/**
123+
* ResourceNames are not guaranteed on first fetch,
124+
*/
125+
$effect(() => {
126+
for (const partID of partIDs) {
127+
const query = queries.current[partID];
128+
if (query?.isFetched && !query.isLoading && query.data?.length === 0) {
129+
query.refetch();
130+
}
131+
}
132+
});
133+
117134
/**
118135
* Individually refetch part resource names based on revision
119136
*/

0 commit comments

Comments
 (0)