fix: explore page loses remote instance spaces on reload
fetchSpaces() now awaits _autoConnectDone before reading the instance list, preventing a race where it would fetch with an empty/incomplete set of connected instances during page reload.
This commit is contained in:
@@ -50,6 +50,24 @@ export const useExploreStore = create<ExploreState>((set, get) => ({
|
|||||||
fetchSpaces: async (query?: string) => {
|
fetchSpaces: async (query?: string) => {
|
||||||
set({ isLoading: true, error: null });
|
set({ isLoading: true, error: null });
|
||||||
|
|
||||||
|
// Wait for autoConnectAll to finish if it hasn't yet.
|
||||||
|
// This prevents fetching with an incomplete/empty instance list on page reload.
|
||||||
|
if (!useInstanceStore.getState()._autoConnectDone) {
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
const unsub = useInstanceStore.subscribe((state) => {
|
||||||
|
if (state._autoConnectDone) {
|
||||||
|
unsub();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Re-check after subscribing to avoid TOCTOU race
|
||||||
|
if (useInstanceStore.getState()._autoConnectDone) {
|
||||||
|
unsub();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const instances = useInstanceStore.getState().instances;
|
const instances = useInstanceStore.getState().instances;
|
||||||
const connectedInstances = instances.filter(i => i.status === 'connected');
|
const connectedInstances = instances.filter(i => i.status === 'connected');
|
||||||
|
|||||||
Reference in New Issue
Block a user