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.

Keep History chart readings through a resize

rcourtmanef486d54e657
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 1bd4086ad3..648f254159 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -9190,6 +9190,11 @@ 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.
+The point cap follows the chart's width but is not part of what the chart
+shows: a resize (or a full-page capture) re-reads the same series at the new
+cap while keeping its readings on screen with no loading state, and only
+pointer inspection resets, since its pixel positions moved. A changed target,
+metric, range, organisation or lock still starts from nothing.
### Shared History single observations
diff --git a/frontend-modern/browser-tests/guest-storage-2263.cjs b/frontend-modern/browser-tests/guest-storage-2263.cjs
index 3b0afb683d..88df1632b8 100644
--- a/frontend-modern/browser-tests/guest-storage-2263.cjs
+++ b/frontend-modern/browser-tests/guest-storage-2263.cjs
@@ -214,11 +214,26 @@ const { chromium } = require('playwright');
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({
+ // A resize asks for the same series at a new point cap: the charts keep
+ // their readings and show no loading state while it is read.
+ const spinners = () => page.getByLabel('Loading history').count();
+ const resizedReads = reads();
+ const resizedRead = page.waitForRequest((request) =>
+ request.url().includes('/api/metrics-store/history'),
+ );
+ await page.setViewportSize({ width: width - 200, height: width === 390 ? 844 : 900 });
+ await resizedRead;
+ assert.equal(await spinners(), 0, 'a resize keeps the charts on screen');
+ await page.waitForTimeout(300);
+ assert.ok(reads() > resizedReads, 'the resized charts read at their new cap');
+ assert.equal(await spinners(), 0, 'no spinner after the resized read');
+ await page.setViewportSize({ width, height: width === 390 ? 844 : 900 });
+ await page.waitForTimeout(300);
+ await page.screenshot({
path: path.join(artifacts, `guest-storage-2263-resumed-${width}.png`),
+ fullPage: true,
});
+ assert.equal(await spinners(), 0, 'a full-page capture leaves no spinner behind');
const beforeNoAgent = requests.length;
await page.getByRole('button', { name: 'No agent' }).click();
assert.equal(await page.locator('[data-testid="guest-physical-disks"]').count(), 0);
diff --git a/frontend-modern/browser-verification/69a153020de8f190.json b/frontend-modern/browser-verification/69a153020de8f190.json
new file mode 100644
index 0000000000..d72b6e161d
--- /dev/null
+++ b/frontend-modern/browser-verification/69a153020de8f190.json
@@ -0,0 +1,45 @@
+{
+ "version": 1,
+ "base_sha": "c94aec835faa62ce5f1fd912913c623b446d022e",
+ "verified_at": "2026-10-14T10:58:40Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/components/shared/useHistoryChartState.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/components/shared/useHistoryChartState.ts": "2ce76a6d4fbfa149d2fda0500f87334e244abbed9ad3f27b65e718e41b998bf4"
+ },
+ "routes": [
+ "/browser-tests/guest-storage-2263.html (production GuestDrawerOverview, GuestPhysicalDisks, DiskDetail and HistoryChart, Chromium via Playwright 1.56.1 on pulse-dev)"
+ ],
+ "viewports": [
+ {
+ "width": 1440,
+ "height": 900
+ },
+ {
+ "width": 390,
+ "height": 844
+ },
+ {
+ "width": 1240,
+ "height": 900
+ },
+ {
+ "width": 190,
+ "height": 844
+ }
+ ],
+ "states": [
+ "disk expanded with 24h History and Live I/O charts loaded",
+ "viewport narrowed by 200px: each chart re-reads at its new point cap with readings kept and no Loading history spinner",
+ "viewport restored and a full-page capture taken: no spinner left behind",
+ "Overview hidden and shown again (pause path from the previous change still passes)"
+ ],
+ "interactions": [
+ "Enter on the disk summary expands it; pointer closes and reopens it",
+ "Hide overview / Show overview",
+ "page.setViewportSize narrow then restore",
+ "full-page screenshot"
+ ]
+}
diff --git a/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx b/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
index f06c988eac..935871e28b 100644
--- a/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/HistoryChart.test.tsx
@@ -473,6 +473,50 @@ describe('HistoryChart', () => {
}
});
+ it('keeps its readings on screen while a resize re-reads at a new point cap', async () => {
+ const request = vi.mocked(ChartsAPI.getMetricsHistory);
+ const observers: Array<() => void> = [];
+ const original = globalThis.ResizeObserver;
+ globalThis.ResizeObserver = class {
+ constructor(callback: () => void) {
+ observers.push(callback);
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ } as unknown as typeof ResizeObserver;
+ let width = 800;
+ const widthSpy = vi
+ .spyOn(HTMLElement.prototype, 'clientWidth', 'get')
+ .mockImplementation(() => width);
+ try {
+ // The first measured width replaces the unmeasured read, so every read
+ // until the resize answers with the same reading.
+ request.mockResolvedValue({
+ points: [{ timestamp: 1000, value: 10, min: 10, max: 10 }],
+ source: 'store',
+ } as never);
+ render(() => <HistoryChart resourceType="disk" resourceId="d" metric="smart_temp" />);
+ const chart = screen.getByRole('img', { name: 'History chart' });
+ const description = document.getElementById(chart.getAttribute('aria-describedby')!)!;
+ await waitFor(() => expect(description).toHaveTextContent('10'));
+ const calls = request.mock.calls.length;
+ request.mockImplementationOnce(() => new Promise(() => {}));
+ width = 400;
+ observers.forEach((resized) => resized());
+ expect(request.mock.calls.length).toBe(calls + 1);
+ expect(request.mock.calls.at(-1)![0].maxPoints).not.toBe(
+ request.mock.calls.at(-2)![0].maxPoints,
+ );
+ expect(description).toHaveTextContent('10');
+ expect(screen.queryByLabelText('Loading history')).not.toBeInTheDocument();
+ } finally {
+ widthSpy.mockRestore();
+ globalThis.ResizeObserver = original;
+ request.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 f09913fa30..44c57d6146 100644
--- a/frontend-modern/src/components/shared/__tests__/useHistoryChartState.test.tsx
+++ b/frontend-modern/src/components/shared/__tests__/useHistoryChartState.test.tsx
@@ -242,6 +242,50 @@ describe('History request ownership', () => {
expect(state.data()).toEqual(points(40));
});
+ it('keeps its readings without a loading state when a resize changes the point cap', async () => {
+ let width = 800;
+ let resized: (() => void) | undefined;
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ constructor(callback: () => void) {
+ resized = callback;
+ }
+ observe() {}
+ disconnect() {}
+ },
+ );
+ const container = document.createElement('div');
+ Object.defineProperty(container, 'clientWidth', { get: () => width });
+ request.mockResolvedValue({ points: points(10), source: 'store' } as never);
+ let state!: HistoryChartState;
+ render(() => {
+ state = useHistoryChartState(
+ { resourceId: 'a', resourceType: 'agent', metric: 'cpu', range: '24h' },
+ { getCanvas: () => undefined, getContainer: () => container },
+ );
+ return <div />;
+ });
+ await settle();
+ await settle();
+ expect(state.data()).toEqual(points(10));
+ const caps = () => request.mock.calls.map((call) => call[0].maxPoints);
+ const before = request.mock.calls.length;
+ const resizedRead = deferred();
+ request.mockReturnValueOnce(resizedRead.promise);
+ width = 400;
+ resized?.();
+ expect(request.mock.calls.length).toBe(before + 1);
+ expect(caps().at(-1)).not.toBe(caps().at(-2));
+ // The same series at a new resolution: readings stay, no spinner.
+ expect(state.data()).toEqual(points(10));
+ expect(state.loading()).toBe(false);
+ resizedRead.resolve({ points: points(20), source: 'store' } as never);
+ await settle();
+ expect(state.data()).toEqual(points(20));
+ vi.unstubAllGlobals();
+ });
+
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();
diff --git a/frontend-modern/src/components/shared/useHistoryChartState.ts b/frontend-modern/src/components/shared/useHistoryChartState.ts
index 22bb9cb2ea..c906379e42 100644
--- a/frontend-modern/src/components/shared/useHistoryChartState.ts
+++ b/frontend-modern/src/components/shared/useHistoryChartState.ts
@@ -106,8 +106,9 @@ 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;
+ let previousSeries: string | undefined;
+ // The series whose stored reply is on screen, so a pause or resize keeps it.
+ let loadedSeries: string | undefined;
// One effect owns a selection, its request and its polling timer. Cleanup
// invalidates completions even when a transport ignores cancellation.
@@ -133,25 +134,29 @@ export function useHistoryChartState(
if (timer !== undefined) window.clearInterval(timer);
});
- const selection = JSON.stringify([
+ // The series is what the chart shows. The point cap follows the chart's
+ // width, so a resize asks for the same series at a new resolution: it
+ // keeps the readings on screen while the new request is in flight.
+ const series = JSON.stringify([
orgSelection,
resourceType,
resourceId,
metric,
chartRange,
- pointsCap,
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) {
+ const selection = JSON.stringify([series, pointsCap]);
+ // Pausing, resuming or resizing the same series keeps its readings on
+ // screen; any other change starts from nothing.
+ if (suppliedData !== undefined || series !== previousSeries) {
setData(suppliedData ?? []);
setSource(suppliedData !== undefined ? 'live' : null);
setError(null);
setRefreshFailed(false);
- loadedSelection = undefined;
+ loadedSeries = undefined;
}
+ previousSeries = series;
setLoading(false);
if (selection !== previousSelection) {
pendingTouch = undefined;
@@ -164,7 +169,7 @@ export function useHistoryChartState(
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;
+ let hasLoaded = loadedSeries === series;
const loadData = async () => {
if (!active || pending) return;
@@ -186,14 +191,14 @@ export function useHistoryChartState(
setError(null);
setRefreshFailed(false);
hasLoaded = true;
- loadedSelection = selection;
+ loadedSeries = series;
} catch (err) {
if (!active) return;
console.error('Failed to fetch metrics history:', err);
const accessError = getAPIReadAccessErrorMessage(err);
if (accessError) {
hasLoaded = false;
- loadedSelection = undefined;
+ loadedSeries = undefined;
pendingTouch = undefined;
touchTimestamp = null;
batch(() => {