Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Pause a guest's disk charts while Manage hides its Overview

rcourtmanc94aec835faa
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index fea003582d..1bd4086ad3 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -9185,6 +9185,11 @@ remain separate errors. No polling frequency, request or access policy changes.
and selection changes; `browser-tests/history-status.cjs` checks actual chart
states in desktop Chromium and phone WebKit with synthetic transport failures.
These checks do not establish native collection or released availability.
+`HistoryChart` takes `enabled` (default true) for a chart mounted inside a
+hidden drawer tab: false aborts its read and stops polling but keeps the
+readings it shows, and resuming the same selection reads at once without a
+loading state before polling again. A selection changed while paused still
+starts from nothing. The hook and mounted chart tests pin both paths.
### Shared History single observations
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index 8a46d63109..7190f9c1f1 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -3669,6 +3669,11 @@ The drawer judges those disks' heat under the guest agent's alert overrides:
its `agentId`, which `useWorkloads` copies from `resource.agent.agentId` onto
the workload row, then the guest's own override keys. That reads the alert
configuration already loaded and adds no query, poll or per-row work.
+While Manage hides the Overview, the drawer's `historyEnabled` also pauses
+these disks: an expanded disk's charts stop polling (they polled every 10-30
+seconds behind the hidden tab) and the list's realtime refresh is held
+through `useUnifiedResources`' `realtimeEnabled`; returning to Overview reads
+once and resumes. `browser-tests/guest-storage-2263.cjs` counts the reads.
### Configuration transfer authorization stays off persistence hot paths
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 55ffbee399..5368b5471a 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -2883,6 +2883,9 @@ canonical pre-handler authorization proof covering both transfer routes.
same names the resource drawers use. The range picker keeps the shared
filter-select presentation; storage must not restore the retired
storage-local range-selector classes and inline SVG select decoration.
+ A disk detail mounted where it can be hidden (a guest drawer's Overview
+ behind Manage) takes `historyEnabled` and passes it to every chart,
+ history and live I/O alike, so a hidden disk reads nothing.
Storage-page pool growth readouts belong to that same contract: the table
may derive per-pool used-capacity deltas from the shared
`/api/storage-charts` summary payload, but it must not fan out row-local
diff --git a/frontend-modern/browser-tests/guest-storage-2263.cjs b/frontend-modern/browser-tests/guest-storage-2263.cjs
index 422f2d8eda..3b0afb683d 100644
--- a/frontend-modern/browser-tests/guest-storage-2263.cjs
+++ b/frontend-modern/browser-tests/guest-storage-2263.cjs
@@ -24,6 +24,7 @@ const { chromium } = require('playwright');
});
const requests = [];
const detailRequests = [];
+ const historyReads = [];
const pageErrors = [];
const disk = {
id: 'disk-guest-101',
@@ -81,6 +82,28 @@ const { chromium } = require('playwright');
},
});
}
+ if (url.pathname === '/api/metrics-store/history') {
+ const q = url.searchParams;
+ historyReads.push({ width, metric: q.get('metric'), range: q.get('range') });
+ const end = Date.now();
+ return route.fulfill({
+ json: {
+ resourceType: q.get('resourceType'),
+ resourceId: q.get('resourceId'),
+ metric: q.get('metric'),
+ range: q.get('range'),
+ start: end - 600_000,
+ end,
+ source: 'store',
+ points: [0, 1, 2].map((i) => ({
+ timestamp: end - (2 - i) * 300_000,
+ value: 40 + i,
+ min: 40 + i,
+ max: 40 + i,
+ })),
+ },
+ });
+ }
if (url.pathname.startsWith('/api/')) return route.fulfill({ json: {} });
return route.continue();
});
@@ -91,6 +114,8 @@ const { chromium } = require('playwright');
});
await route.continue();
});
+ // Disk charts poll every 10-30 seconds; the clock drives that here.
+ await page.clock.install();
await page.goto('http://127.0.0.1:5199/browser-tests/guest-storage-2263.html', {
waitUntil: 'domcontentloaded',
timeout: 120_000,
@@ -165,6 +190,35 @@ const { chromium } = require('playwright');
1,
'reopening a disk does not reload the SMART module',
);
+ // A hidden Overview (another drawer tab) must stop the open disk's reads.
+ const reads = () => historyReads.filter((read) => read.width === width).length;
+ await page.clock.runFor(30_000);
+ await page.waitForTimeout(200);
+ const whileShown = reads();
+ await page.clock.runFor(30_000);
+ await page.waitForTimeout(200);
+ assert.ok(reads() > whileShown, 'an open disk polls while its Overview is shown');
+ await page.getByRole('button', { name: 'Hide overview' }).click();
+ await page.waitForTimeout(200);
+ const whileHidden = reads();
+ await page.clock.runFor(120_000);
+ await page.waitForTimeout(200);
+ assert.equal(reads(), whileHidden, 'a hidden Overview reads no disk history');
+ const resumed = page.waitForRequest((request) =>
+ request.url().includes('/api/metrics-store/history'),
+ );
+ await page.getByRole('button', { name: 'Show overview' }).click();
+ await resumed;
+ await page.getByText('Reallocated Sectors').first().waitFor();
+ assert.ok(
+ await page.locator('[data-testid="disk-detail-history"] canvas').first().isVisible(),
+ 'charts return with their readings',
+ );
+ // An element capture: a full-page capture resizes the page, which
+ // re-reads charts at a new point cap and would show their spinners.
+ await page.locator('[data-testid="guest-physical-disks"]').screenshot({
+ path: path.join(artifacts, `guest-storage-2263-resumed-${width}.png`),
+ });
const beforeNoAgent = requests.length;
await page.getByRole('button', { name: 'No agent' }).click();
assert.equal(await page.locator('[data-testid="guest-physical-disks"]').count(), 0);
@@ -212,6 +266,7 @@ const { chromium } = require('playwright');
route: '/browser-tests/guest-storage-2263.html',
requests,
detailRequests,
+ historyReads: historyReads.length,
pageErrors,
}),
);
diff --git a/frontend-modern/browser-tests/guest-storage-2263.tsx b/frontend-modern/browser-tests/guest-storage-2263.tsx
index a9853a5a6a..74bb59741f 100644
--- a/frontend-modern/browser-tests/guest-storage-2263.tsx
+++ b/frontend-modern/browser-tests/guest-storage-2263.tsx
@@ -7,6 +7,8 @@ import '../src/index.css';
type Mode = 'linked' | 'none' | 'error';
const [mode, setMode] = createSignal<Mode>('linked');
+// Mirrors a drawer tab switch: the Overview stays mounted but hidden.
+const [shown, setShown] = createSignal(true);
const baseGuest = {
id: 'vm-table-101',
canonicalResourceId: 'vm-resource-101',
@@ -61,9 +63,13 @@ render(() => (
<button type="button" onClick={() => setMode('linked')}>Linked guest</button>
<button type="button" onClick={() => setMode('none')}>No agent</button>
<button type="button" onClick={() => setMode('error')}>Unavailable query</button>
+ <button type="button" onClick={() => setShown(false)}>Hide overview</button>
+ <button type="button" onClick={() => setShown(true)}>Show overview</button>
</nav>
<Show when={mode() === 'linked'}>
- <GuestDrawerOverview {...overviewProps} guest={linkedGuest as any} />
+ <div class={shown() ? '' : 'hidden'}>
+ <GuestDrawerOverview {...overviewProps} guest={linkedGuest as any} historyEnabled={shown()} />
+ </div>
</Show>
<Show when={mode() === 'none'}>
<GuestDrawerOverview {...overviewProps} guest={baseGuest as any} />
diff --git a/frontend-modern/browser-verification/192edcc9aa494b40.json b/frontend-modern/browser-verification/192edcc9aa494b40.json
new file mode 100644
index 0000000000..5c2018368e
--- /dev/null
+++ b/frontend-modern/browser-verification/192edcc9aa494b40.json
@@ -0,0 +1,46 @@
+{
+ "version": 1,
+ "base_sha": "8342a35332f22b6bee5f9821ca0f02d3a895d33f",
+ "verified_at": "2026-10-14T10:46:52Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/components/Storage/DiskDetail.tsx",
+ "frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx",
+ "frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx",
+ "frontend-modern/src/components/shared/historyChartModel.ts",
+ "frontend-modern/src/components/shared/useHistoryChartState.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/components/Storage/DiskDetail.tsx": "3f5b207b3610158ad2a604f3d59b064473829529acf9b305e6570a42a46326eb",
+ "frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx": "1df9dd5c45a117d2fde84bc6cf7fb3b140b4e190007c496232d55956d696e38c",
+ "frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx": "d67cfc7c291018b147ffccebc24a9ebe72b2593145dd53e7d2bd887bb5ccee56",
+ "frontend-modern/src/components/shared/historyChartModel.ts": "2ea62b7b72011e336acc5eb6f2bdda162925bbfda7b5622f7abca4931f8358d0",
+ "frontend-modern/src/components/shared/useHistoryChartState.ts": "9d88eb4250f3c6b52adafd94d7c8c3484fc2379bae454d6ca5bd4e6c63752bbc"
+ },
+ "routes": [
+ "/browser-tests/guest-storage-2263.html (production GuestDrawerOverview with GuestPhysicalDisks and DiskDetail, Chromium via Playwright 1.56.1 on pulse-dev)"
+ ],
+ "viewports": [
+ {
+ "width": 1440,
+ "height": 900
+ },
+ {
+ "width": 390,
+ "height": 844
+ }
+ ],
+ "states": [
+ "linked guest Overview with one physical disk collapsed",
+ "disk expanded: SMART facts, 24h History charts and Live I/O charts loaded",
+ "Overview shown: the open disk polls on its 10-30s interval",
+ "Overview hidden (as behind Manage): no disk history reads across 120s of clock time",
+ "Overview shown again: one catch-up read per chart, same chart nodes, readings kept with no loading spinner",
+ "no-agent guest and unavailable disk query states"
+ ],
+ "interactions": [
+ "Enter on the disk summary expands it; pointer closes and reopens it",
+ "Hide overview / Show overview buttons toggle the mounted Overview like a drawer tab switch",
+ "page clock advanced 30s, 30s and 120s to drive polling"
+ ]
+}
diff --git a/frontend-modern/src/components/Storage/DiskDetail.tsx b/frontend-modern/src/components/Storage/DiskDetail.tsx
index 93dee13ebb..a68b196aaf 100644
--- a/frontend-modern/src/components/Storage/DiskDetail.tsx
+++ b/frontend-modern/src/components/Storage/DiskDetail.tsx
@@ -48,6 +48,8 @@ interface DiskDetailProps {
nodes: Resource[];
/** Alert override keys of the machine whose agent reports the disk. */
alertResourceIds?: string[];
+ /** False pauses this disk's chart reads, e.g. while a drawer tab is hidden. */
+ historyEnabled?: boolean;
}
export const DiskDetail: Component<DiskDetailProps> = (props) => {
@@ -184,6 +186,7 @@ export const DiskDetail: Component<DiskDetailProps> = (props) => {
hideSelector={true}
compact={true}
hideLock={true}
+ enabled={props.historyEnabled}
/>
</div>
)}
@@ -223,6 +226,7 @@ export const DiskDetail: Component<DiskDetailProps> = (props) => {
hideLock
height={120}
compact={true}
+ enabled={props.historyEnabled}
/>
</div>
)}
diff --git a/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx b/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx
index ccd04f7f21..39fe0e0cf3 100644
--- a/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx
+++ b/frontend-modern/src/components/Storage/__tests__/DiskDetail.test.tsx
@@ -13,8 +13,9 @@ vi.mock('@/components/shared/HistoryChart', () => ({
resourceId: string;
metric: string;
range?: string;
+ enabled?: boolean;
}) => (
- <div data-testid="history-chart">
+ <div data-testid="history-chart" data-enabled={String(props.enabled !== false)}>
{props.resourceType}:{props.resourceId}:{props.metric}:{props.range}
</div>
),
@@ -51,6 +52,16 @@ const buildDisk = (): Resource =>
}) as unknown as Resource;
describe('DiskDetail', () => {
+ it('pauses every disk chart when its holder is hidden', () => {
+ const [shown, setShown] = createSignal(true);
+ render(() => <DiskDetail disk={buildDisk()} nodes={[]} historyEnabled={shown()} />);
+ const states = () => screen.getAllByTestId('history-chart').map((c) => c.dataset.enabled);
+ expect(states().length).toBeGreaterThan(0);
+ expect(new Set(states())).toEqual(new Set(['true']));
+ setShown(false);
+ expect(new Set(states())).toEqual(new Set(['false']));
+ });
+
it('keeps disk detail range choices inside the current history entitlement', () => {
render(() => <DiskDetail disk={buildDisk()} nodes={[]} />);
diff --git a/frontend-modern/src/components/Workloads/GuestDrawer.test.tsx b/frontend-modern/src/components/Workloads/GuestDrawer.test.tsx
index f7e88c8f51..e35bfe6414 100644
--- a/frontend-modern/src/components/Workloads/GuestDrawer.test.tsx
+++ b/frontend-modern/src/components/Workloads/GuestDrawer.test.tsx
@@ -60,6 +60,16 @@ vi.mock('@/stores/license', () => ({
maxHistoryDays: () => 90,
}));
+// Records whether the guest's physical disks may read, without their own
+// resource query; GuestPhysicalDisks.test covers what they render.
+vi.mock('./GuestPhysicalDisks', () => ({
+ GuestPhysicalDisks: (props: { historyEnabled?: boolean }) => (
+ <div
+ data-testid="guest-physical-disks-stub"
+ data-history-enabled={String(props.historyEnabled)}
+ />
+ ),
+}));
vi.mock('@/components/shared/WebInterfaceUrlField', () => ({
WebInterfaceUrlField: (props: {
metadataKind: string;
@@ -769,6 +779,23 @@ describe('GuestDrawer', () => {
expect(utilizationChart).toHaveTextContent('40.0%');
});
+ it('pauses the physical disk charts while Manage hides Overview', async () => {
+ render(() => (
+ <GuestDrawer
+ guest={makeGuest({ agentVersion: '6.2.0', agentKind: 'pulse' })}
+ onClose={vi.fn()}
+ />
+ ));
+ // The drawer remembers its last tab, so start from Overview explicitly.
+ await fireEvent.click(screen.getByRole('tab', { name: 'Overview' }));
+ const disks = await screen.findByTestId('guest-physical-disks-stub');
+ expect(disks).toHaveAttribute('data-history-enabled', 'true');
+ await fireEvent.click(screen.getByRole('tab', { name: 'Manage' }));
+ expect(disks).toHaveAttribute('data-history-enabled', 'false');
+ await fireEvent.click(screen.getByRole('tab', { name: 'Overview' }));
+ expect(disks).toHaveAttribute('data-history-enabled', 'true');
+ });
+
it('switches back to Overview tab', async () => {
const { container } = render(() => (
<GuestDrawer guest={makeGuestWithDiscoveryTarget()} onClose={vi.fn()} />
diff --git a/frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx b/frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx
index 719ec17018..8020e227eb 100644
--- a/frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx
+++ b/frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx
@@ -495,6 +495,7 @@ export function GuestDrawerOverview(props: GuestDrawerOverviewProps) {
...(props.guest.canonicalResourceId ? [props.guest.canonicalResourceId] : []),
...getWorkloadAlertResourceIdCandidates(props.guest),
]}
+ historyEnabled={props.historyEnabled ?? true}
/>
</Suspense>
</Show>
diff --git a/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx b/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx
index fa6f2877d7..f26fc9cb82 100644
--- a/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx
+++ b/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx
@@ -19,7 +19,11 @@ const LazyDiskDetail = lazy(() =>
import('@/components/Storage/DiskDetail').then(({ DiskDetail }) => ({ default: DiskDetail })),
);
-const GuestPhysicalDiskRow: Component<{ disk: Resource; alertResourceIds: string[] }> = (props) => {
+const GuestPhysicalDiskRow: Component<{
+ disk: Resource;
+ alertResourceIds: string[];
+ historyEnabled: boolean;
+}> = (props) => {
const [expanded, setExpanded] = createSignal(false);
const { getDiskTemperatureThresholds } = useAlertsActivation();
const data = () =>
@@ -77,6 +81,7 @@ const GuestPhysicalDiskRow: Component<{ disk: Resource; alertResourceIds: string
disk={props.disk}
nodes={[]}
alertResourceIds={props.alertResourceIds}
+ historyEnabled={props.historyEnabled}
/>
</Suspense>
</div>
@@ -93,6 +98,11 @@ export const GuestPhysicalDisks: Component<{
* applies, then the guest's canonical ID and override keys.
*/
alertResourceIds?: string[];
+ /**
+ * False while the Overview holding these disks is hidden: an expanded disk's
+ * charts and the list's live refresh pause until it is shown again.
+ */
+ historyEnabled?: boolean;
}> = (props) => {
// The Proxmox Overview snapshot deliberately excludes physical disks. Query
// only the open guest's direct children rather than hydrating every disk in
@@ -102,6 +112,7 @@ export const GuestPhysicalDisks: Component<{
query: `type=physical_disk&parent=${encodeURIComponent(parentId)}`,
cacheKey: `guest-physical-disks:${parentId}`,
enabled: () => parentId.length > 0,
+ realtimeEnabled: () => parentId.length > 0 && props.historyEnabled !== false,
});
const disks = () =>
source
@@ -123,7 +134,11 @@ export const GuestPhysicalDisks: Component<{
<div class="space-y-2">
<For each={disks()}>
{(disk) => (
- <GuestPhysicalDiskRow disk={disk} alertResourceIds={props.alertResourceIds ?? []} />
+ <GuestPhysicalDiskRow
+ disk={disk}
+ alertResourceIds={props.alertResourceIds ?? []}
+ historyEnabled={props.historyEnabled !== false}
+ />
)}
</For>
</div>
diff --git a/frontend-modern/src/components/Workloads/__tests__/GuestPhysicalDisks.test.tsx b/frontend-modern/src/components/Workloads/__tests__/GuestPhysicalDisks.test.tsx
index 961f6e2b4b..1bd12bfa35 100644
--- a/frontend-modern/src/components/Workloads/__tests__/GuestPhysicalDisks.test.tsx
+++ b/frontend-modern/src/components/Workloads/__tests__/GuestPhysicalDisks.test.tsx
@@ -15,6 +15,7 @@ const queryState = vi.hoisted(() => ({
error: undefined as unknown,
query: '',
enabled: false,
+ realtimeEnabled: undefined as (() => boolean) | undefined,
}));
// The expanded disk detail now shows its history charts in view; the chart
@@ -22,13 +23,22 @@ const queryState = vi.hoisted(() => ({
// covered by the HistoryChart and DiskDetail suites.
vi.mock('@/components/shared/HistoryChart', () => ({
HistoryChartHoverGroup: (props: { children: JSX.Element }) => <div>{props.children}</div>,
- HistoryChart: (props: { label: string }) => <div data-testid="history-chart">{props.label}</div>,
+ HistoryChart: (props: { label: string; enabled?: boolean }) => (
+ <div data-testid="history-chart" data-enabled={String(props.enabled !== false)}>
+ {props.label}
+ </div>
+ ),
}));
vi.mock('@/hooks/useUnifiedResources', () => ({
- useUnifiedResources: (options: { query: string; enabled: () => boolean }) => {
+ useUnifiedResources: (options: {
+ query: string;
+ enabled: () => boolean;
+ realtimeEnabled?: () => boolean;
+ }) => {
queryState.query = options.query;
queryState.enabled = options.enabled();
+ queryState.realtimeEnabled = options.realtimeEnabled;
return {
resources: () => (queryState.accessor ? queryState.accessor() : queryState.resources),
error: () => queryState.error,
@@ -71,6 +81,7 @@ describe('GuestPhysicalDisks', () => {
queryState.error = undefined;
queryState.query = '';
queryState.enabled = false;
+ queryState.realtimeEnabled = undefined;
});
afterEach(cleanup);
@@ -97,6 +108,28 @@ describe('GuestPhysicalDisks', () => {
expect(within(card).getAllByTestId('guest-physical-disk')).toHaveLength(1);
});
+ it('pauses an expanded disk and the live list while its Overview is hidden', async () => {
+ queryState.resources = [disk];
+ const [shown, setShown] = createSignal(true);
+ render(() => <GuestPhysicalDisks parentId="vm-resource-101" historyEnabled={shown()} />);
+ const row = screen.getByTestId('guest-physical-disk') as HTMLDetailsElement;
+ row.open = true;
+ fireEvent(row, new Event('toggle'));
+ await waitFor(() => expect(screen.getAllByTestId('history-chart').length).toBeGreaterThan(0));
+ const enabledStates = () =>
+ screen.getAllByTestId('history-chart').map((chart) => chart.dataset.enabled);
+ expect(new Set(enabledStates())).toEqual(new Set(['true']));
+ expect(queryState.realtimeEnabled?.()).toBe(true);
+ setShown(false);
+ expect(new Set(enabledStates())).toEqual(new Set(['false']));
+ expect(queryState.realtimeEnabled?.()).toBe(false);
+ // The initial read is not withheld: only background refresh pauses.
+ expect(queryState.enabled).toBe(true);
+ setShown(true);
+ expect(new Set(enabledStates())).toEqual(new Set(['true']));
+ expect(queryState.realtimeEnabled?.()).toBe(true);
+ });
+
it("judges the guest's disks by its own agent's Disk Temp override", async () => {
const getConfig = vi.spyOn(AlertsAPI, 'getConfig').mockResolvedValue({
enabled: true,
diff --git a/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx b/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
index b65cafc976..f06c988eac 100644
--- a/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
@@ -438,6 +438,41 @@ describe('HistoryChart', () => {
expect(screen.queryByText('Min')).not.toBeInTheDocument();
});
+ it('keeps its readings without a spinner or read while paused, then resumes', async () => {
+ vi.useFakeTimers();
+ try {
+ const request = vi.mocked(ChartsAPI.getMetricsHistory);
+ request.mockReset();
+ request.mockResolvedValue({
+ points: [{ timestamp: 1000, value: 10, min: 10, max: 10 }],
+ source: 'store',
+ } as never);
+ const [enabled, setEnabled] = createSignal(true);
+ render(() => (
+ <HistoryChart resourceType="disk" resourceId="d" metric="smart_temp" enabled={enabled()} />
+ ));
+ const chart = screen.getByRole('img', { name: 'History chart' });
+ const description = document.getElementById(chart.getAttribute('aria-describedby')!)!;
+ await vi.advanceTimersByTimeAsync(0);
+ expect(description).toHaveTextContent('10');
+ const calls = request.mock.calls.length;
+ // A hidden drawer tab pauses the chart: no reads, readings kept.
+ setEnabled(false);
+ await vi.advanceTimersByTimeAsync(120_000);
+ expect(request.mock.calls.length).toBe(calls);
+ expect(description).toHaveTextContent('10');
+ expect(screen.queryByLabelText('Loading history')).not.toBeInTheDocument();
+ setEnabled(true);
+ expect(request.mock.calls.length).toBe(calls + 1);
+ expect(screen.queryByLabelText('Loading history')).not.toBeInTheDocument();
+ } finally {
+ vi.useRealTimers();
+ vi.mocked(ChartsAPI.getMetricsHistory)
+ .mockReset()
+ .mockResolvedValue({ points: [], source: 'store' } as never);
+ }
+ });
+
it('exposes a stored singleton to pointer inspection without treating a later empty response as zero', async () => {
const request = vi.mocked(ChartsAPI.getMetricsHistory);
request.mockResolvedValueOnce({
diff --git a/frontend-modern/src/components/shared/__tests__/useHistoryChartState.test.tsx b/frontend-modern/src/components/shared/__tests__/useHistoryChartState.test.tsx
index 3364d3f6af..f09913fa30 100644
--- a/frontend-modern/src/components/shared/__tests__/useHistoryChartState.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/useHistoryChartState.test.tsx
@@ -55,6 +55,9 @@ function mount() {
get data() {
return props().data;
},
+ get enabled() {
+ return props().enabled;
+ },
},
{ getCanvas: () => undefined, getContainer: () => undefined },
);
@@ -205,6 +208,60 @@ describe('History request ownership', () => {
},
);
+ it('pauses reads while disabled, keeps the readings shown and resumes quietly', async () => {
+ request.mockResolvedValueOnce({ points: points(10), source: 'store' } as never);
+ const { state, change } = mount();
+ await settle();
+ const inFlight = deferred();
+ request.mockReturnValueOnce(inFlight.promise);
+ vi.advanceTimersByTime(10_000);
+ expect(request).toHaveBeenCalledTimes(2);
+ // Hiding the chart aborts its read and keeps what it already shows.
+ change({ enabled: false });
+ expect(request.mock.calls[1][0].signal?.aborted).toBe(true);
+ inFlight.resolve({ points: points(99), source: 'store' } as never);
+ await settle();
+ vi.advanceTimersByTime(120_000);
+ expect(request).toHaveBeenCalledTimes(2);
+ expect(state.data()).toEqual(points(10));
+ expect(state.source()).toBe('store');
+ expect(state.loading()).toBe(false);
+ // Showing it again catches up at once without a loading state, then polls.
+ const resumed = deferred();
+ request.mockReturnValueOnce(resumed.promise);
+ change({ enabled: true });
+ expect(request).toHaveBeenCalledTimes(3);
+ expect(state.loading()).toBe(false);
+ expect(state.data()).toEqual(points(10));
+ resumed.resolve({ points: points(30), source: 'store' } as never);
+ await settle();
+ expect(state.data()).toEqual(points(30));
+ request.mockResolvedValueOnce({ points: points(40), source: 'store' } as never);
+ await vi.advanceTimersByTimeAsync(10_000);
+ expect(request).toHaveBeenCalledTimes(4);
+ expect(state.data()).toEqual(points(40));
+ });
+
+ it('starts a selection changed while paused from nothing, without reading', async () => {
+ request.mockResolvedValueOnce({ points: points(10), source: 'store' } as never);
+ const { state, change } = mount();
+ await settle();
+ change({ enabled: false });
+ change({ resourceId: 'b' });
+ expect(state.data()).toEqual([]);
+ vi.advanceTimersByTime(120_000);
+ expect(request).toHaveBeenCalledTimes(1);
+ const next = deferred();
+ request.mockReturnValueOnce(next.promise);
+ change({ enabled: true });
+ expect(request).toHaveBeenCalledTimes(2);
+ expect(request.mock.calls[1][0].resourceId).toBe('b');
+ expect(state.loading()).toBe(true);
+ next.resolve({ points: points(20), source: 'store' } as never);
+ await settle();
+ expect(state.data()).toEqual(points(20));
+ });
+
it('aborts and stops polling on unmount without consuming a late completion', async () => {
const old = deferred();
request.mockReturnValueOnce(old.promise);
diff --git a/frontend-modern/src/components/shared/historyChartModel.ts b/frontend-modern/src/components/shared/historyChartModel.ts
index 103bff018a..c9475114c3 100644
--- a/frontend-modern/src/components/shared/historyChartModel.ts
+++ b/frontend-modern/src/components/shared/historyChartModel.ts
@@ -15,6 +15,11 @@ export interface HistoryChartProps {
compact?: boolean;
hideLock?: boolean;
data?: AggregatedMetricPoint[];
+ /**
+ * False pauses stored reads and polling while keeping the readings already
+ * shown, e.g. for a chart inside a drawer tab that is mounted but hidden.
+ */
+ enabled?: boolean;
}
export interface HistoryChartHoverPoint {
diff --git a/frontend-modern/src/components/shared/useHistoryChartState.ts b/frontend-modern/src/components/shared/useHistoryChartState.ts
index b5aac2231e..22bb9cb2ea 100644
--- a/frontend-modern/src/components/shared/useHistoryChartState.ts
+++ b/frontend-modern/src/components/shared/useHistoryChartState.ts
@@ -106,6 +106,8 @@ export function useHistoryChartState(
const dataMax = createMemo(() => getHistoryChartDataMax(data()));
let previousSelection: string | undefined;
+ // The selection whose stored reply is on screen, so a pause keeps it.
+ let loadedSelection: string | undefined;
// One effect owns a selection, its request and its polling timer. Cleanup
// invalidates completions even when a transport ignores cancellation.
@@ -119,9 +121,9 @@ export function useHistoryChartState(
const locked = isLocked();
const interval = refreshIntervalMs();
const orgSelection = orgVersion();
+ const enabled = props.enabled !== false;
let active = true;
let pending = false;
- let hasLoaded = false;
let controller: AbortController | undefined;
let timer: number | undefined;
@@ -131,11 +133,6 @@ export function useHistoryChartState(
if (timer !== undefined) window.clearInterval(timer);
});
- setData(suppliedData ?? []);
- setSource(suppliedData !== undefined ? 'live' : null);
- setError(null);
- setRefreshFailed(false);
- setLoading(false);
const selection = JSON.stringify([
orgSelection,
resourceType,
@@ -146,6 +143,16 @@ export function useHistoryChartState(
locked,
suppliedData !== undefined,
]);
+ // Pausing and resuming the same selection keeps its readings on screen;
+ // any other change starts from nothing.
+ if (suppliedData !== undefined || selection !== previousSelection) {
+ setData(suppliedData ?? []);
+ setSource(suppliedData !== undefined ? 'live' : null);
+ setError(null);
+ setRefreshFailed(false);
+ loadedSelection = undefined;
+ }
+ setLoading(false);
if (selection !== previousSelection) {
pendingTouch = undefined;
touchTimestamp = null;
@@ -155,6 +162,9 @@ export function useHistoryChartState(
}
previousSelection = selection;
if (suppliedData !== undefined || locked || !resourceId || !resourceType) return;
+ // A paused chart (inside a hidden drawer tab) reads nothing until resumed.
+ if (!enabled) return;
+ let hasLoaded = loadedSelection === selection;
const loadData = async () => {
if (!active || pending) return;
@@ -176,12 +186,14 @@ export function useHistoryChartState(
setError(null);
setRefreshFailed(false);
hasLoaded = true;
+ loadedSelection = selection;
} catch (err) {
if (!active) return;
console.error('Failed to fetch metrics history:', err);
const accessError = getAPIReadAccessErrorMessage(err);
if (accessError) {
hasLoaded = false;
+ loadedSelection = undefined;
pendingTouch = undefined;
touchTimestamp = null;
batch(() => {