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
Retain tab data across recovery and patrol revisits
rcourtman3a5f36da1940
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.history.test.tsx b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.history.test.tsxindex 0f14ab62f9..1a77227469 100644--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.history.test.tsx+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.history.test.tsx@@ -215,8 +215,9 @@ describe('ResourceDetailDrawer change history section', () => {'const modeLabel = formatSourceType(resource.sourceType);',);expect(resourceDetailDrawerOverviewSource).not.toContain('<span class="text-muted">Mode</span>');+ expect(createNonSuspendingQuerySource).toContain('const retainedQueryCache = new Map<');expect(createNonSuspendingQuerySource).toContain(- 'const [resolvedOnce, setResolvedOnce] = createSignal(false);',+ 'export function resetCreateNonSuspendingQueryCacheForTest()',);expect(createNonSuspendingQuerySource).toContain('setResolvedOnce(true);');expect(createNonSuspendingQuerySource).toContain('setResolvedOnce(false);');diff --git a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.tsindex 685a65f9e9..c0877f436e 100644--- a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts+++ b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts@@ -109,6 +109,7 @@ export function usePatrolIntelligenceState() {const patrolStatusState = createNonSuspendingQuery<PatrolStatus | null, string>({source: () => 'patrol-status',+ cacheKey: () => 'patrol-status',fetcher: async () => {try {return await getPatrolStatus();@@ -345,6 +346,7 @@ export function usePatrolIntelligenceState() {const patrolRunHistory = createNonSuspendingQuery<PatrolRunRecord[], number>({source: activityRefreshTrigger,+ cacheKey: () => 'patrol-run-history',fetcher: async () => {try {return await getPatrolRunHistory(30);diff --git a/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsx b/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsxnew file mode 100644index 0000000000..d33e04a059--- /dev/null+++ b/frontend-modern/src/hooks/__tests__/createNonSuspendingQuery.test.tsx@@ -0,0 +1,57 @@+import { afterEach, describe, expect, it, vi } from 'vitest';+import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';+import {+ createNonSuspendingQuery,+ resetCreateNonSuspendingQueryCacheForTest,+} from '@/hooks/createNonSuspendingQuery';++afterEach(() => {+ resetCreateNonSuspendingQueryCacheForTest();+ cleanup();+});++function QueryProbe(props: {+ cacheNamespace: string;+ fetcher: (key: string) => Promise<string>;+}) {+ const state = createNonSuspendingQuery<string, string>({+ source: () => 'stable-key',+ cacheKey: (key) => `${props.cacheNamespace}:${key}`,+ fetcher: props.fetcher,+ initialValue: 'initial',+ });++ return (+ <div data-testid="query-probe">{`${state.value()}|resolved:${String(state.resolvedOnce())}|loading:${String(state.loading())}`}</div>+ );+}++describe('createNonSuspendingQuery', () => {+ it('reuses the last fulfilled value when the same query remounts', async () => {+ const cacheNamespace = `query-cache-${Date.now()}`;+ const firstFetcher = vi.fn(async () => 'loaded');+ const secondFetcher = vi.fn(() => new Promise<string>(() => {}));++ const firstRender = render(() => (+ <QueryProbe cacheNamespace={cacheNamespace} fetcher={firstFetcher} />+ ));++ await waitFor(() => {+ expect(screen.getByTestId('query-probe').textContent).toContain('loaded');+ expect(screen.getByTestId('query-probe').textContent).toContain('resolved:true');+ });++ firstRender.unmount();++ render(() => <QueryProbe cacheNamespace={cacheNamespace} fetcher={secondFetcher} />);++ await waitFor(() => {+ expect(secondFetcher).toHaveBeenCalledWith('stable-key');+ });++ expect(screen.getByTestId('query-probe').textContent).toContain('loaded');+ expect(screen.getByTestId('query-probe').textContent).toContain('resolved:true');+ expect(screen.getByTestId('query-probe').textContent).toContain('loading:false');+ expect(screen.getByTestId('query-probe').textContent).not.toContain('initial');+ });+});diff --git a/frontend-modern/src/hooks/createNonSuspendingQuery.ts b/frontend-modern/src/hooks/createNonSuspendingQuery.tsindex 80f5f4cdf5..c34f8791bc 100644--- a/frontend-modern/src/hooks/createNonSuspendingQuery.ts+++ b/frontend-modern/src/hooks/createNonSuspendingQuery.ts@@ -4,6 +4,7 @@ interface CreateNonSuspendingQueryOptions<T, K> {source: Accessor<K | null>;fetcher: (key: K) => Promise<T>;initialValue: T;+ cacheKey?: (key: K) => string | null;pollMs?: number;}@@ -15,11 +16,47 @@ interface QueryRunOptions {* Keep query-backed surfaces out of the app-level Suspense boundary by* retaining the last fulfilled value while the next request is in flight.*/+const retainedQueryCache = new Map<+ string,+ { error: unknown; resolvedOnce: boolean; value: unknown }+>();++export function resetCreateNonSuspendingQueryCacheForTest() {+ retainedQueryCache.clear();+}+export function createNonSuspendingQuery<T, K>(options: CreateNonSuspendingQueryOptions<T, K>) {- const [value, setValue] = createSignal<T>(options.initialValue);+ const getRetainedCacheKey = (key: K | null): string | null => {+ if (key === null || !options.cacheKey) {+ return null;+ }+ return options.cacheKey(key);+ };++ const readRetainedValue = (key: K | null) => {+ const cacheKey = getRetainedCacheKey(key);+ if (!cacheKey) {+ return null;+ }+ const cached = retainedQueryCache.get(cacheKey);+ if (!cached) {+ return null;+ }+ return cached as { error: unknown; resolvedOnce: boolean; value: T };+ };++ const applyRetainedValue = (cached: { error: unknown; resolvedOnce: boolean; value: T }) => {+ setValue(() => cached.value);+ setError(cached.error);+ setResolvedOnce(cached.resolvedOnce);+ };++ const initialCached = readRetainedValue(options.source());++ const [value, setValue] = createSignal<T>(initialCached?.value ?? options.initialValue);const [loading, setLoading] = createSignal(false);- const [error, setError] = createSignal<unknown>(null);- const [resolvedOnce, setResolvedOnce] = createSignal(false);+ const [error, setError] = createSignal<unknown>(initialCached?.error ?? null);+ const [resolvedOnce, setResolvedOnce] = createSignal(initialCached?.resolvedOnce ?? false);let latestRequestId = 0;@@ -34,6 +71,7 @@ export function createNonSuspendingQuery<T, K>(options: CreateNonSuspendingQueryconst run = async (key: K, runOptions: QueryRunOptions = {}): Promise<T> => {const requestId = ++latestRequestId;+ const retainedCacheKey = getRetainedCacheKey(key);if (!runOptions.background) {setLoading(true);}@@ -54,6 +92,13 @@ export function createNonSuspendingQuery<T, K>(options: CreateNonSuspendingQuery} finally {if (requestId === latestRequestId) {setResolvedOnce(true);+ if (retainedCacheKey) {+ retainedQueryCache.set(retainedCacheKey, {+ error: error(),+ resolvedOnce: true,+ value: value(),+ });+ }if (!runOptions.background) {setLoading(false);}@@ -67,7 +112,11 @@ export function createNonSuspendingQuery<T, K>(options: CreateNonSuspendingQueryreset();return;}- void run(key);+ const cached = readRetainedValue(key);+ if (cached) {+ applyRetainedValue(cached);+ }+ void run(key, { background: Boolean(cached) });});const refetch = async (runOptions: QueryRunOptions = {}): Promise<T> => {diff --git a/frontend-modern/src/hooks/useRecoveryPoints.ts b/frontend-modern/src/hooks/useRecoveryPoints.tsindex bfabb91956..9afe7b3390 100644--- a/frontend-modern/src/hooks/useRecoveryPoints.ts+++ b/frontend-modern/src/hooks/useRecoveryPoints.ts@@ -134,6 +134,7 @@ export function useRecoveryPoints(query?: Accessor<RecoveryPointsQuery | null |const state = createNonSuspendingQuery<RecoveryPointsResponse, string>({source,+ cacheKey: (key) => `recovery-points:${key}`,fetcher: async (key) => fetchRecoveryPointsResponse(parseSerializedQuery(key)),initialValue: {data: [],diff --git a/frontend-modern/src/hooks/useRecoveryPointsFacets.ts b/frontend-modern/src/hooks/useRecoveryPointsFacets.tsindex eea2d98a4d..101d16f3cd 100644--- a/frontend-modern/src/hooks/useRecoveryPointsFacets.ts+++ b/frontend-modern/src/hooks/useRecoveryPointsFacets.ts@@ -126,6 +126,7 @@ export function useRecoveryPointsFacets(query?: Accessor<RecoveryFacetsQuery | nconst state = createNonSuspendingQuery<RecoveryPointsFacetsResponse, string>({source,+ cacheKey: (key) => `recovery-facets:${key}`,fetcher: async (key) => fetchFacets(parseSerializedQuery(key)),initialValue: { data: {} },pollMs: REFRESH_MS,diff --git a/frontend-modern/src/hooks/useRecoveryPointsSeries.ts b/frontend-modern/src/hooks/useRecoveryPointsSeries.tsindex 19beac4d8a..2b4d10e180 100644--- a/frontend-modern/src/hooks/useRecoveryPointsSeries.ts+++ b/frontend-modern/src/hooks/useRecoveryPointsSeries.ts@@ -112,6 +112,7 @@ export function useRecoveryPointsSeries(query?: Accessor<RecoverySeriesQuery | nconst state = createNonSuspendingQuery<RecoveryPointsSeriesResponse, string>({source,+ cacheKey: (key) => `recovery-series:${key}`,fetcher: async (key) => fetchSeries(parseSerializedQuery(key)),initialValue: { data: [] },pollMs: REFRESH_MS,diff --git a/frontend-modern/src/hooks/useRecoveryRollups.ts b/frontend-modern/src/hooks/useRecoveryRollups.tsindex 3f3b668ad3..9165fd279d 100644--- a/frontend-modern/src/hooks/useRecoveryRollups.ts+++ b/frontend-modern/src/hooks/useRecoveryRollups.ts@@ -115,6 +115,7 @@ export function useRecoveryRollups(query?: () => RecoveryRollupsQuery | null | uconst state = createNonSuspendingQuery<ProtectionRollup[], string>({source,+ cacheKey: (key) => `recovery-rollups:${key}`,fetcher: async (key) => fetchRecoveryRollups(parseSerializedQuery(key)),initialValue: [],pollMs: REFRESH_MS,diff --git a/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx b/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsxindex f917987daa..ad6292469a 100644--- a/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx+++ b/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx@@ -1,6 +1,7 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';import { Suspense, createSignal } from 'solid-js';+import { resetCreateNonSuspendingQueryCacheForTest } from '@/hooks/createNonSuspendingQuery';import { resetAIRuntimeState } from '@/stores/aiRuntimeState';import { getPublicPricingUrl } from '@/utils/pricingHandoff';@@ -323,6 +324,7 @@ const defaultAISettings = {describe('AIIntelligence entitlement gating', () => {beforeEach(() => {+ resetCreateNonSuspendingQueryCacheForTest();resetAIRuntimeState();getPatrolStatusMock.mockReset();getPatrolAutonomySettingsMock.mockReset();