Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Refetch live queries after an org switch
rcourtman115d9522486f
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex 30a0fe8018..ffe9b1c21f 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -2440,6 +2440,19 @@ verification.redaction boundary` in`frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts`.+44. An org switch must leave every live query surface with data for the+ new org, not merely cleared of the old org's data. Clearing state is+ not sufficient in `createNonSuspendingQuery`, because the reset writes+ signals the source effect does not track, so a consumer with a+ constant source and no polling would sit empty until it remounted.+ The org-switch handler therefore refetches, matching the clear-and-+ refetch shape every other org-switch handler in the app already uses.+ Stale pre-switch responses are still discarded by request generation.+ Regression coverage: `refetches a constant-source query after an org+ switch` and `does not repopulate the cache when an old-org request+ resolves late` in+ `frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsx`.+## Current Statediff --git a/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsx b/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsxindex 76c01a6da5..161a19db5c 100644--- a/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsx+++ b/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsx@@ -108,23 +108,27 @@ describe('createNonSuspendingQuery', () => {});it('does not repopulate the cache when an old-org request resolves late', async () => {- let resolveFetch: ((value: string) => void) | undefined;+ // The org switch itself now issues a fresh request, so keep every+ // resolver and settle the pre-switch one specifically. Resolving the+ // latest would prove nothing about stale responses.+ const resolvers: ((value: string) => void)[] = [];render(() => (<QueryProbecacheNamespace={`late-query-cache-${Date.now()}`}fetcher={() =>new Promise<string>((resolve) => {- resolveFetch = resolve;+ resolvers.push(resolve);})}/>));await waitFor(() => {- expect(resolveFetch).toBeTypeOf('function');+ expect(resolvers).toHaveLength(1);});+ const resolveOldOrgFetch = resolvers[0];eventBus.emit('org_switched', 'org-b');- resolveFetch?.('late-org-a-value');+ resolveOldOrgFetch('late-org-a-value');await waitFor(() => {expect(screen.getByTestId('query-probe').textContent).toContain('initial');@@ -151,4 +155,31 @@ describe('createNonSuspendingQuery', () => {expect(getCreateNonSuspendingQueryCacheDiagnosticsForTest().size).toBe(0);});++ it('refetches a constant-source query after an org switch', async () => {+ // c77571685 added an org_switched handler that only called reset().+ // reset() writes signals the source effect does not track, so for a+ // consumer with a constant source and no polling (connectionsSnapshot,+ // patrol-status) the panel emptied and stayed empty until remount.+ const fetcher = vi.fn(async (key: string) => `value-for-${key}`);++ render(() => (+ <QueryProbe cacheNamespace={`org-refetch-${Date.now()}`} fetcher={fetcher} />+ ));++ await waitFor(() => {+ expect(screen.getByTestId('query-probe').textContent).toContain('value-for-stable-key');+ });+ expect(fetcher).toHaveBeenCalledTimes(1);++ eventBus.emit('org_switched', 'org-b');++ await waitFor(() => {+ expect(fetcher).toHaveBeenCalledTimes(2);+ });+ await waitFor(() => {+ expect(screen.getByTestId('query-probe').textContent).toContain('value-for-stable-key');+ expect(screen.getByTestId('query-probe').textContent).toContain('resolved:true');+ });+ });});diff --git a/frontend-modern/src/hooks/createNonSuspendingQuery.ts b/frontend-modern/src/hooks/createNonSuspendingQuery.tsindex b85b4e418b..661f995aca 100644--- a/frontend-modern/src/hooks/createNonSuspendingQuery.ts+++ b/frontend-modern/src/hooks/createNonSuspendingQuery.ts@@ -188,6 +188,15 @@ export function createNonSuspendingQuery<T, K>(options: CreateNonSuspendingQueryconst unsubscribeLiveQueryOrgSwitch = eventBus.on('org_switched', () => {reset();+ // reset() only writes signals the source effect does not track, so it+ // cannot re-run the query on its own. A consumer with a constant source+ // and no polling would otherwise sit empty until it remounted. Refetch+ // here, matching every other org-switch handler in the app.+ const key = options.source();+ if (key === null) {+ return;+ }+ void run(key);});onCleanup(unsubscribeLiveQueryOrgSwitch);