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.

Addresses #1557

rcourtman0b6b97115b04
diff --git a/frontend-modern/src/utils/__tests__/routeStateNavigation.test.ts b/frontend-modern/src/utils/__tests__/routeStateNavigation.test.ts
index 30dc17e355..e1ae3d853c 100644
--- a/frontend-modern/src/utils/__tests__/routeStateNavigation.test.ts
+++ b/frontend-modern/src/utils/__tests__/routeStateNavigation.test.ts
@@ -104,6 +104,37 @@ describe('routeStateNavigation', () => {
expect(readPendingAppShellRestoreTop()).toBe(55);
});
+ it('drops a pending rewrite after the user navigates to a different pathname (#1557)', () => {
+ const navigate = vi.fn();
+ let currentPath = '/proxmox/storage';
+ const scheduler = createRouteStateNavigateScheduler(navigate, () => currentPath);
+
+ // The storage surface schedules its query write-back, then the user
+ // clicks the Overview section tab before the setTimeout(0) fires.
+ scheduler.schedule('/proxmox/storage?source=proxmox-pve');
+ currentPath = '/proxmox/overview';
+ vi.runAllTimers();
+
+ expect(navigate).not.toHaveBeenCalled();
+ scheduler.cleanup();
+ });
+
+ it('re-anchors a coalesced rewrite to the pathname of the latest schedule call', () => {
+ const navigate = vi.fn();
+ let currentPath = '/proxmox/backups';
+ const scheduler = createRouteStateNavigateScheduler(navigate, () => currentPath);
+
+ scheduler.schedule('/proxmox/backups?node=pve1');
+ // A second schedule arrives after navigation; the pending rewrite must be
+ // judged against the pathname that scheduled it last, not the first one.
+ currentPath = '/proxmox/overview';
+ scheduler.schedule('/proxmox/overview?type=vm');
+ vi.runAllTimers();
+
+ expect(navigate).toHaveBeenCalledWith('/proxmox/overview?type=vm', ROUTE_STATE_REPLACE_OPTIONS);
+ scheduler.cleanup();
+ });
+
it('skips redundant navigations to the current path', () => {
const navigate = vi.fn();
const scheduler = createRouteStateNavigateScheduler(navigate, () => '/proxmox/backups?rollupId=abc');
diff --git a/frontend-modern/src/utils/routeStateNavigation.ts b/frontend-modern/src/utils/routeStateNavigation.ts
index d1bd185dc6..01f1985156 100644
--- a/frontend-modern/src/utils/routeStateNavigation.ts
+++ b/frontend-modern/src/utils/routeStateNavigation.ts
@@ -16,10 +16,11 @@ export const markRouteStateDeliberateScroll = (now = Date.now()): void => {
);
};
-const isSamePathnameNavigation = (currentPath: string, targetPath: string): boolean => {
- const base = window.location.origin;
- return new URL(currentPath, base).pathname === new URL(targetPath, base).pathname;
-};
+const resolvePathname = (path: string): string =>
+ new URL(path, window.location.origin).pathname;
+
+const isSamePathnameNavigation = (currentPath: string, targetPath: string): boolean =>
+ resolvePathname(currentPath) === resolvePathname(targetPath);
const shouldRestorePreservedScrollValue = (current: number, restore: number): boolean => {
if (Math.abs(current - restore) <= ROUTE_STATE_SCROLL_RESTORE_DIVERGENCE_PX) {
@@ -34,6 +35,7 @@ export const createRouteStateNavigateScheduler = (
) => {
let pendingHandle: number | null = null;
let pendingPath: string | null = null;
+ let pendingSchedulingPathname: string | null = null;
let scrollRestoreTimeoutHandles: number[] = [];
let scrollRestoreFrameHandles: number[] = [];
@@ -75,19 +77,31 @@ export const createRouteStateNavigateScheduler = (
const schedule = (nextPath: string) => {
pendingPath = nextPath;
+ pendingSchedulingPathname = resolvePathname(readCurrentPath());
if (pendingHandle !== null) return;
pendingHandle = window.setTimeout(() => {
pendingHandle = null;
if (typeof window === 'undefined') {
pendingPath = null;
+ pendingSchedulingPathname = null;
return;
}
const target = pendingPath;
+ const schedulingPathname = pendingSchedulingPathname;
pendingPath = null;
+ pendingSchedulingPathname = null;
if (!target) return;
const currentPath = readCurrentPath();
if (currentPath === target) return;
+ // Route-state rewrites only manage the query string of the surface that
+ // scheduled them. If the pathname changed between scheduling and firing
+ // (the user clicked to another section while this rewrite was pending),
+ // the scheduling surface no longer owns the URL — replaying the stale
+ // target would swallow the user's navigation, so drop it instead.
+ if (schedulingPathname !== null && resolvePathname(currentPath) !== schedulingPathname) {
+ return;
+ }
const restoreScroll = isSamePathnameNavigation(currentPath, target)
? { x: window.scrollX, y: window.scrollY }
@@ -143,6 +157,7 @@ export const createRouteStateNavigateScheduler = (
pendingHandle = null;
}
pendingPath = null;
+ pendingSchedulingPathname = null;
};
return { cleanup, schedule };