Skip to content

Commit 91bfe0d

Browse files
fix: align Channels queryFn return shape with Dashboard
Both Dashboard.tsx and Channels.tsx used the same React Query key qk.channels.list({}) but returned different data shapes: Dashboard returned the raw {items, total} object while Channels returned just the items array. When Dashboard loaded first, React Query cached the raw object, and Channels' for...of on the cached object threw 'g is not iterable'. Fix: Channels queryFn now returns the raw API response (matching Dashboard), and channels extraction uses data?.items ?? []. Added regression test that pre-seeds the cache with the Dashboard shape.
1 parent 7b399a5 commit 91bfe0d

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/meshcore_hub/web/static/js/spa-react/pages/Channels.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { screen, waitFor } from "@testing-library/react";
22
import { describe, expect, it, vi } from "vitest";
33

44
import { Channels } from "@/pages/Channels";
5-
import { renderWithProviders } from "@/test/renderWithProviders";
5+
import { renderWithProviders, createTestQueryClient } from "@/test/renderWithProviders";
66
import { makeConfig } from "@/test/makeConfig";
77
import * as api from "@/utils/api";
88

@@ -69,4 +69,15 @@ describe("Channels", () => {
6969
expect(screen.queryByText("Public")).not.toBeInTheDocument();
7070
});
7171
});
72+
73+
it("renders correctly when cache was pre-populated by Dashboard (raw object shape)", async () => {
74+
mockChannelsApi();
75+
const client = createTestQueryClient();
76+
client.setQueryData(["channels", "list", {}], CHANNELS);
77+
renderWithProviders(<Channels />, { client });
78+
await waitFor(() => {
79+
expect(screen.getByText("Public")).toBeInTheDocument();
80+
expect(screen.getByText("Ops")).toBeInTheDocument();
81+
});
82+
});
7283
});

src/meshcore_hub/web/static/js/spa-react/pages/Channels.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,10 @@ export function Channels() {
293293
error: queryError,
294294
} = useQuery({
295295
queryKey: qk.channels.list({}),
296-
queryFn: async ({ signal }) => {
297-
const resp = await apiGet<ChannelListResponse>(
298-
"/api/v1/channels",
299-
{},
300-
{ signal },
301-
);
302-
return resp.items || [];
303-
},
296+
queryFn: ({ signal }) =>
297+
apiGet<ChannelListResponse>("/api/v1/channels", {}, { signal }),
304298
});
305-
const channels = data ?? [];
299+
const channels = data?.items ?? [];
306300
const error = queryError ? queryError.message : null;
307301
const [modal, setModal] = useState<ModalState | null>(null);
308302

0 commit comments

Comments
 (0)