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
Defer realtime tick application while the operator scrolls
rcourtmanb262f24c54f0
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.mdindex 2e23bbaa43..968d6d68e3 100644--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md@@ -261,6 +261,21 @@ consumes realtime projection work. Re-entering an inactive tab must catch upfrom the shared canonical cache rather than replaying every missed delta.Hidden tabs continue advancing the raw baseline without reconciling the estate;all hidden changes are materialized once when the document becomes visible.+Active operator scrolling gates realtime resource work harder still: a tick+arriving mid-gesture queues its delta unapplied, in arrival order, because on+a large estate even the baseline patch walks the whole resource array. The+reporting projection and the realtime tick token (`lastUpdate`) defer+latest-wins alongside — the token is what every downstream realtime consumer+keys on, so holding it keeps unified projections and workload remaps fully+quiescent through the gesture. Queued deltas drain in order — at scroll+idle, before any in-place tick applies, and into the same deferral set the+hidden-tab path uses — so one batch materializes everything while nothing is+visually moving. The queue is bounded by a single gesture: hidden tabs keep+the in-place baseline advance, and a full snapshot supersedes and clears any+queued deltas along with the deferral set. Alert application stays live+mid-gesture. This is a scheduling boundary, not a cost reduction — the+per-tick reconciliation cost itself remains owned by the+resource-payload-static-metadata gap.These rules must be proved against a 50-node fixture and may not be replaced byblank-row virtualization or a second page-local polling path.diff --git a/frontend-modern/browser-verification.json b/frontend-modern/browser-verification.jsonindex 96f8ea9348..0e58006515 100644--- a/frontend-modern/browser-verification.json+++ b/frontend-modern/browser-verification.json@@ -1,38 +1,16 @@{"version": 1,- "base_sha": "8d573cd0ac341f794f88bd940a01db229c54bfbb",- "verified_at": "2026-08-26T15:06:01Z",+ "base_sha": "c154fa7aed228ea03d37e35833770940c1858a77",+ "verified_at": "2026-08-26T16:18:38Z","result": "passed","changed_paths": [- "frontend-modern/src/components/Infrastructure/useTableWindowing.ts",- "frontend-modern/src/components/Infrastructure/useUnifiedResourceTableViewportSync.ts",- "frontend-modern/src/components/Storage/useStoragePoolsTableWindowing.ts",- "frontend-modern/src/components/Workloads/WorkloadPanel.tsx",- "frontend-modern/src/components/Workloads/useGroupedTableWindowing.ts",- "frontend-modern/src/components/Workloads/useMetricBarState.ts",- "frontend-modern/src/components/Workloads/useStackedDiskBarState.ts",- "frontend-modern/src/components/Workloads/useStackedMemoryBarState.ts",- "frontend-modern/src/components/Workloads/useWorkloadViewportSync.ts",- "frontend-modern/src/components/shared/windowedPageScroll.ts",- "frontend-modern/src/features/platformPage/usePlatformWindowedItems.ts"+ "frontend-modern/src/stores/websocket.ts"],"content_sha256": {- "frontend-modern/src/components/Infrastructure/useTableWindowing.ts": "6eea3c4a17afd2d4238e88331e12e98c034a08cb2c104f1d3e46bed92993deff",- "frontend-modern/src/components/Infrastructure/useUnifiedResourceTableViewportSync.ts": "91f650cd432ce8929c9fb6d108e6e37b0cfbf40103955ae9a2fcdb5734910721",- "frontend-modern/src/components/Storage/useStoragePoolsTableWindowing.ts": "4e30ae20adf83f0b0f1dfe41d87331f0b52b641b29b0d457f392a1c00f185aa6",- "frontend-modern/src/components/Workloads/WorkloadPanel.tsx": "d29985e9245a3f60bbb9ca82e3ea330b3f07b08a9b11a079232cba27a6df57ff",- "frontend-modern/src/components/Workloads/useGroupedTableWindowing.ts": "187b4b20e623e75d52be00de396e5fef6be9e4c85384207a827768e37d8e0b39",- "frontend-modern/src/components/Workloads/useMetricBarState.ts": "1dcfac801c35a81151a0f2776830089067f9bebe5237ccc5f7df53c20d7433bf",- "frontend-modern/src/components/Workloads/useStackedDiskBarState.ts": "329a108849bc84fd0cd4c45524ea3cee8208bb01f16217254e3a9f4b772eda2a",- "frontend-modern/src/components/Workloads/useStackedMemoryBarState.ts": "dc505c9daa2aebcaf614892cc584a325ea320febc346ce0e177ff4cf37894c85",- "frontend-modern/src/components/Workloads/useWorkloadViewportSync.ts": "4b441530125c7544093fcc19247ad0a2037dcaf1b064c1a087c755f1b0f1f6bf",- "frontend-modern/src/components/shared/windowedPageScroll.ts": "6749cde8e9a17316ab53e691268e40dfc081c14d8d41b1eb1e331c9b5151ca80",- "frontend-modern/src/features/platformPage/usePlatformWindowedItems.ts": "9c89637fcd267edf335e8d516266bd6f9a3965fed2c4289bcc287d63c383543c"+ "frontend-modern/src/stores/websocket.ts": "0c28ea223ca92422fe2f64bf8b0db336c29381c00a8300c3993c8d38f8903b46"},"routes": [- "/proxmox/overview",- "/proxmox/storage",- "/docker"+ "/proxmox/overview"],"viewports": [{@@ -45,21 +23,16 @@}],"states": [- "large mock estate: 50 nodes and 929 guests with the guest table windowed to a 140-row mounted budget",- "storage pools table windowed and scrolled while visible on the Storage tab",- "storage surface prewarmed but hidden behind the Overview tab while the guest table scrolls",- "overview surface hidden behind the Storage tab, then restored at a deep scroll position",- "narrow-viewport mobile layout with bottom navigation and compact guest rows",- "docker containers page with grouped host/container tables"+ "large mock estate: 50 nodes and 929 guests with realtime delta ticks arriving every few seconds over the websocket",+ "continuous operator scrolling spanning multiple realtime ticks",+ "scroll idle immediately after a gesture with deferred ticks pending",+ "narrow-viewport mobile layout scrolling across a realtime tick"],"interactions": [- "continuous mouse-wheel scrolling through the full 929-guest table with long-animation-frame and rAF cadence instrumentation: runway top-ups now cost 15-31ms in dead-band batches (previously 200-260ms blocking wheel handler)",- "isolation battery on the guest table: +/-8px per-frame oscillation (0 frames over 25ms), 600px/s and 2600px/s and 6000px/s scripted continuous scrolls (p50 at native 13.3ms frame time, bounded mutation frames only)",- "single synthetic wheel shifts at multiple scroll depths measuring per-shift cost (5-12ms for 4-10 row top-ups)",- "scrollbar-style teleport jumps re-centering the mounted window without blanks",- "tab switch Overview -> Storage -> Overview with deep scroll in between: hidden surface skips viewport sync, restored surface refills the viewport without spacer blanks",- "storage pools table wheel-scrolled while visible: windowed rows advance with correct content",- "narrow-viewport scroll through the guest table: windowing intact, metric bars sized by ResizeObserver initial delivery",- "docker page scrolled end to end with zero console errors"+ "long-animation-frame instrumentation across 16-20s continuous scrolls: zero websocket onmessage long frames during scrolling (previously 200-560ms per tick), one coalesced flush landing 300-450ms after scroll idle via the deferral timer",+ "store-internal probes confirming mid-scroll ticks queue their resource deltas, defer the reporting projection and lastUpdate token latest-wins, and drain fully at idle",+ "per-message section timing showing mid-scroll tick cost at or below ~1ms with alert application still live",+ "Last refresh footer observed advancing across scrolls on desktop and narrow viewports, confirming deferred ticks still land and data stays live",+ "zero console errors across desktop and narrow passes"]}diff --git a/frontend-modern/src/stores/__tests__/websocket-unified.test.ts b/frontend-modern/src/stores/__tests__/websocket-unified.test.tsindex 934fdb5cdf..e02693bd0a 100644--- a/frontend-modern/src/stores/__tests__/websocket-unified.test.ts+++ b/frontend-modern/src/stores/__tests__/websocket-unified.test.ts@@ -769,6 +769,265 @@ describe('websocket store unified resource contract', () => {}});+ it('defers resource deltas while the operator scrolls and flushes at scroll idle', async () => {+ const { store, dispose } = await createStoreHarness();+ try {+ await waitForOpenTick();+ emitMessage({+ type: 'initialState',+ data: {+ resources: [+ {+ id: 'vm-1',+ type: 'vm',+ name: 'vm-1',+ status: 'running',+ cpu: { current: 10 },+ },+ ],+ lastUpdate: 100,+ activeAlerts: [],+ recentlyResolved: [],+ },+ });++ // A tick arriving mid-gesture must not reconcile the estate.+ window.dispatchEvent(new Event('scroll'));+ emitMessage({+ type: 'rawData',+ data: {+ lastUpdate: 200,+ resourceDelta: { upserts: [{ id: 'vm-1', cpu: { current: 20 } }] },+ },+ });+ expect(store.state.resources[0]?.cpu?.current).toBe(10);++ // Scrolling continues: the idle recheck re-arms instead of flushing.+ vi.advanceTimersByTime(200);+ window.dispatchEvent(new Event('scroll'));+ emitMessage({+ type: 'rawData',+ data: {+ lastUpdate: 300,+ resourceDelta: { upserts: [{ id: 'vm-1', cpu: { current: 30 } }] },+ },+ });+ vi.advanceTimersByTime(200);+ expect(store.state.resources[0]?.cpu?.current).toBe(10);+ // The realtime tick token defers too, so downstream consumers keyed on+ // it stay quiescent through the gesture.+ expect(store.state.lastUpdate).toBe(100);++ // Gesture idle: both deferred ticks land as one coalesced reconciliation.+ vi.advanceTimersByTime(600);+ expect(store.state.resources[0]?.cpu?.current).toBe(30);+ expect(store.state.lastUpdate).toBe(300);+ } finally {+ dispose();+ }+ });++ it('holds hidden-tab deferrals through an active scroll and lands them at idle', async () => {+ const visibility = vi.spyOn(document, 'visibilityState', 'get');+ visibility.mockReturnValue('visible');+ const { store, dispose } = await createStoreHarness();+ try {+ await waitForOpenTick();+ emitMessage({+ type: 'initialState',+ data: {+ resources: [+ {+ id: 'vm-1',+ type: 'vm',+ name: 'vm-1',+ status: 'running',+ cpu: { current: 10 },+ },+ ],+ lastUpdate: 100,+ activeAlerts: [],+ recentlyResolved: [],+ },+ });++ visibility.mockReturnValue('hidden');+ emitMessage({+ type: 'rawData',+ data: {+ lastUpdate: 200,+ resourceDelta: { upserts: [{ id: 'vm-1', cpu: { current: 20 } }] },+ },+ });++ // The tab returns while the operator is already scrolling: the deferred+ // tick must wait for scroll idle rather than landing mid-gesture.+ window.dispatchEvent(new Event('scroll'));+ visibility.mockReturnValue('visible');+ document.dispatchEvent(new Event('visibilitychange'));+ expect(store.state.resources[0]?.cpu?.current).toBe(10);++ vi.advanceTimersByTime(600);+ expect(store.state.resources[0]?.cpu?.current).toBe(20);+ } finally {+ dispose();+ visibility.mockRestore();+ }+ });++ it('drains scroll-queued deltas in arrival order before a hidden-tab tick applies', async () => {+ const visibility = vi.spyOn(document, 'visibilityState', 'get');+ visibility.mockReturnValue('visible');+ const { store, dispose } = await createStoreHarness();+ try {+ await waitForOpenTick();+ emitMessage({+ type: 'initialState',+ data: {+ resources: [+ {+ id: 'vm-1',+ type: 'vm',+ name: 'vm-1',+ status: 'running',+ cpu: { current: 10 },+ memory: { used: 1 },+ },+ ],+ lastUpdate: 100,+ activeAlerts: [],+ recentlyResolved: [],+ },+ });++ // Tick A queues mid-scroll with a memory change tick B does not carry.+ window.dispatchEvent(new Event('scroll'));+ emitMessage({+ type: 'rawData',+ data: {+ lastUpdate: 200,+ resourceDelta: { upserts: [{ id: 'vm-1', cpu: { current: 20 }, memory: { used: 5 } }] },+ },+ });++ // Tick B arrives hidden and applies in place — A must drain first so the+ // baseline never sees B's older sibling fields overwrite A's.+ visibility.mockReturnValue('hidden');+ emitMessage({+ type: 'rawData',+ data: {+ lastUpdate: 300,+ resourceDelta: { upserts: [{ id: 'vm-1', cpu: { current: 30 } }] },+ },+ });+ expect(store.state.resources[0]?.cpu?.current).toBe(10);++ vi.advanceTimersByTime(600);+ visibility.mockReturnValue('visible');+ document.dispatchEvent(new Event('visibilitychange'));++ expect(store.state.resources[0]?.cpu?.current).toBe(30);+ expect(store.state.resources[0]?.memory?.used).toBe(5);+ } finally {+ dispose();+ visibility.mockRestore();+ }+ });++ it('defers the reporting projection during scroll and applies only the latest payload', async () => {+ const { store, dispose } = await createStoreHarness();+ try {+ await waitForOpenTick();+ emitMessage({+ type: 'initialState',+ data: {+ connectedInfrastructure: [{ id: 'infra-1', name: 'old' }],+ resources: [],+ lastUpdate: 100,+ activeAlerts: [],+ recentlyResolved: [],+ },+ });+ expect(store.state.connectedInfrastructure[0]?.name).toBe('old');++ window.dispatchEvent(new Event('scroll'));+ emitMessage({+ type: 'rawData',+ data: { lastUpdate: 200, connectedInfrastructure: [{ id: 'infra-1', name: 'mid' }] },+ });+ vi.advanceTimersByTime(200);+ window.dispatchEvent(new Event('scroll'));+ emitMessage({+ type: 'rawData',+ data: { lastUpdate: 300, connectedInfrastructure: [{ id: 'infra-1', name: 'new' }] },+ });+ expect(store.state.connectedInfrastructure[0]?.name).toBe('old');++ vi.advanceTimersByTime(800);+ expect(store.state.connectedInfrastructure[0]?.name).toBe('new');+ } finally {+ dispose();+ }+ });++ it('drops scroll-queued deltas when a full snapshot supersedes their baseline', async () => {+ const { store, dispose } = await createStoreHarness();+ try {+ await waitForOpenTick();+ emitMessage({+ type: 'initialState',+ data: {+ resources: [+ {+ id: 'vm-1',+ type: 'vm',+ name: 'vm-1',+ status: 'running',+ cpu: { current: 10 },+ },+ ],+ lastUpdate: 100,+ activeAlerts: [],+ recentlyResolved: [],+ },+ });++ window.dispatchEvent(new Event('scroll'));+ emitMessage({+ type: 'rawData',+ data: {+ lastUpdate: 200,+ resourceDelta: { upserts: [{ id: 'vm-1', cpu: { current: 20 } }] },+ },+ });+ expect(store.state.resources[0]?.cpu?.current).toBe(10);++ // A full snapshot replaces the baseline the queued delta referenced.+ emitMessage({+ type: 'rawData',+ data: {+ resources: [+ {+ id: 'vm-1',+ type: 'vm',+ name: 'vm-1',+ status: 'running',+ cpu: { current: 40 },+ },+ ],+ lastUpdate: 300,+ },+ });+ expect(store.state.resources[0]?.cpu?.current).toBe(40);++ // The idle flush must not resurrect the stale queued delta.+ vi.advanceTimersByTime(600);+ expect(store.state.resources[0]?.cpu?.current).toBe(40);+ } finally {+ dispose();+ }+ });+// Regression: on estates large enough that the full snapshot exceeds the// inbound guard (~3100 resources at the ~2.7 KB/resource measured against a// real /api/state payload; ~12.8 MB at 5000), the client dropped initialStatediff --git a/frontend-modern/src/stores/websocket.ts b/frontend-modern/src/stores/websocket.tsindex 400e0a35cf..db17d7dd5d 100644--- a/frontend-modern/src/stores/websocket.ts+++ b/frontend-modern/src/stores/websocket.ts@@ -424,6 +424,28 @@ export function createWebSocketStore(url: string) {// Per-key change shapes for deferred ids, unioned across the hidden ticks so// the resume merge can still take the fast path for metrics-only rows.const deferredResourceKeys = new Map<string, readonly string[] | null>();+ // Resource ticks defer while the operator is actively scrolling, not just+ // while the tab is hidden: on a large estate even the baseline patch walks+ // the whole resource array, so a mid-gesture tick blocks the main thread for+ // hundreds of milliseconds and hitches input. Scroll-gated ticks queue+ // unapplied in arrival order and land at scroll idle, when nothing is+ // visually moving. Hidden tabs keep the in-place baseline advance instead:+ // a tab can stay hidden for hours, and the queue must stay bounded by one+ // gesture's length.+ const OPERATOR_SCROLL_ACTIVE_WINDOW_MS = 250;+ const DEFERRED_FLUSH_RECHECK_MS = 300;+ const deferredResourceDeltaQueue: { upserts?: unknown; removed?: unknown; order?: unknown }[] =+ [];+ // The reporting projection is a whole-array replace, so mid-gesture ticks+ // keep only the latest payload instead of a queue; reconciling it deep-walks+ // every entry and is the other main-thread cost a tick pays.+ let deferredConnectedInfrastructure: ConnectedInfrastructureItem[] | null = null;+ // lastUpdate is the realtime tick token every downstream consumer keys on+ // (unified resource projections, workload remaps). It defers with the rest+ // so a mid-scroll tick triggers no derived recomputation at all.+ let deferredLastUpdate: number | null = null;+ let lastOperatorScrollAt = 0;+ let deferredFlushTimer = 0;// Latest capabilityCatalog from the state payload. Broadcast resources carry// capabilitiesRef instead of inline capability blobs; ingestion expands the// ref back into `capabilities` so consumers keep the inline shape.@@ -519,6 +541,9 @@ export function createWebSocketStore(url: string) {rawServerResources = null;deferredResourceIds.clear();deferredResourceKeys.clear();+ deferredResourceDeltaQueue.length = 0;+ deferredConnectedInfrastructure = null;+ deferredLastUpdate = null;lastFullStateRecoveryAt = 0;oversizedSnapshotObserved = false;// A recovery request from a retired connection may still settle, but its@@ -654,26 +679,102 @@ export function createWebSocketStore(url: string) {syncContainerCommands(nextResources, changedResourceIds);};- const handleResourceVisibilityChange = () => {+ const isOperatorScrollActive = () =>+ Date.now() - lastOperatorScrollAt < OPERATOR_SCROLL_ACTIVE_WINDOW_MS;++ // Deltas queued during an active scroll apply strictly in arrival order.+ // Draining advances the raw baseline and unions the change shapes into the+ // deferral set without reconciling, so one merge materializes everything.+ const applyQueuedResourceDeltas = () => {+ if (deferredResourceDeltaQueue.length === 0) return;+ const queued = deferredResourceDeltaQueue.splice(0);+ if (!rawServerResources) return;+ for (const delta of queued) {+ const appliedDelta = applyResourceStateDelta(rawServerResources, delta);+ appliedDelta.resources.forEach(hydrateSlimResource);+ rawServerResources = appliedDelta.resources;+ appliedDelta.changedIds.forEach((id) => {+ const tickKeys = appliedDelta.changedKeys.get(id) ?? null;+ deferredResourceKeys.set(+ id,+ deferredResourceIds.has(id)+ ? unionResourceChangedKeys(deferredResourceKeys.get(id), tickKeys)+ : tickKeys,+ );+ deferredResourceIds.add(id);+ });+ }+ };++ const flushDeferredResources = () => {+ const pendingInfrastructure = deferredConnectedInfrastructure;+ deferredConnectedInfrastructure = null;+ const pendingLastUpdate = deferredLastUpdate;+ deferredLastUpdate = null;+ if (rawServerResources !== null) {+ applyQueuedResourceDeltas();+ }+ const baseline = rawServerResources;+ let commitDeferredMerge: (() => void) | undefined;+ if (baseline !== null && deferredResourceIds.size > 0) {+ const changedResourceIds = new Set(deferredResourceIds);+ const changedResourceKeys = new Map(deferredResourceKeys);+ deferredResourceIds.clear();+ deferredResourceKeys.clear();+ const nextResources = mergeCanonicalResourceDeltaSnapshot(+ baseline,+ state.resources,+ changedResourceIds,+ changedResourceKeys,+ );+ commitDeferredMerge = () =>+ commitResources(nextResources, changedResourceIds, changedResourceKeys);+ }+ if (!commitDeferredMerge && !pendingInfrastructure && pendingLastUpdate === null) {+ return;+ }+ batch(() => {+ if (pendingInfrastructure) {+ setState('connectedInfrastructure', reconcile(pendingInfrastructure, { key: 'id' }));+ }+ commitDeferredMerge?.();+ if (pendingLastUpdate !== null) {+ setState('lastUpdate', pendingLastUpdate);+ }+ });+ };++ // Flush deferred ticks once nothing gates them: a hidden document flushes+ // through the visibilitychange listener, and active scrolling re-arms a+ // recheck until the gesture goes idle.+ const scheduleDeferredResourceFlush = () => {if (- document.visibilityState !== 'visible' ||- rawServerResources === null ||- deferredResourceIds.size === 0+ deferredResourceIds.size === 0 &&+ deferredResourceDeltaQueue.length === 0 &&+ deferredConnectedInfrastructure === null &&+ deferredLastUpdate === null) {return;}+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;+ if (!isOperatorScrollActive()) {+ flushDeferredResources();+ return;+ }+ if (deferredFlushTimer) return;+ deferredFlushTimer = window.setTimeout(() => {+ deferredFlushTimer = 0;+ scheduleDeferredResourceFlush();+ }, DEFERRED_FLUSH_RECHECK_MS);+ };- const changedResourceIds = new Set(deferredResourceIds);- const changedResourceKeys = new Map(deferredResourceKeys);- deferredResourceIds.clear();- deferredResourceKeys.clear();- const nextResources = mergeCanonicalResourceDeltaSnapshot(- rawServerResources,- state.resources,- changedResourceIds,- changedResourceKeys,- );- batch(() => commitResources(nextResources, changedResourceIds, changedResourceKeys));+ const handleResourceVisibilityChange = () => {+ if (document.visibilityState !== 'visible') return;+ scheduleDeferredResourceFlush();+ };++ const handleOperatorScroll = () => {+ lastOperatorScrollAt = Date.now();};if (typeof document !== 'undefined') {@@ -681,6 +782,12 @@ export function createWebSocketStore(url: string) {passive: true,});}+ if (typeof window !== 'undefined') {+ // Capture phase: scroll events do not bubble, so a window-level capture+ // listener is the only way to observe every scroller (app shell, drawers)+ // without adding per-surface listeners.+ window.addEventListener('scroll', handleOperatorScroll, { capture: true, passive: true });+ }const beginConnection = () => {const connectionId = ++nextConnectionId;@@ -823,10 +930,21 @@ export function createWebSocketStore(url: string) {const connectedInfrastructure = Array.isArray(message.data.connectedInfrastructure)? (message.data.connectedInfrastructure as ConnectedInfrastructureItem[]): [];- setState(- 'connectedInfrastructure',- reconcile(connectedInfrastructure, { key: 'id' }),- );+ if (+ typeof document !== 'undefined' &&+ document.visibilityState !== 'hidden' &&+ isOperatorScrollActive()+ ) {+ // Latest-wins: a newer payload simply replaces the pending one.+ deferredConnectedInfrastructure = connectedInfrastructure;+ scheduleDeferredResourceFlush();+ } else {+ deferredConnectedInfrastructure = null;+ setState(+ 'connectedInfrastructure',+ reconcile(connectedInfrastructure, { key: 'id' }),+ );+ }}if (message.data.metrics !== undefined) setState('metrics', message.data.metrics);if (message.data.performance !== undefined)@@ -845,7 +963,11 @@ export function createWebSocketStore(url: string) {let changedResourceIds: ReadonlySet<string> | undefined;let changedResourceKeys: ResourceChangedKeys | undefined;if (message.data.resources !== undefined) {+ // A full snapshot supersedes every pending deferral, and queued+ // deltas reference the baseline this snapshot replaces.deferredResourceIds.clear();+ deferredResourceKeys.clear();+ deferredResourceDeltaQueue.length = 0;if (Array.isArray(message.data.resources)) {// Expand capabilitiesRef and synthesize omitted default// policies before the rows feed the baseline clone and the@@ -880,50 +1002,64 @@ export function createWebSocketStore(url: string) {message.data.resourceDelta !== undefined) {if (rawServerResources) {- const appliedDelta = applyResourceStateDelta(- rawServerResources,- message.data.resourceDelta,- );- // Patched rows are fresh objects: re-synthesize a nulled-out- // default policy and re-expand capabilities when a patch moved- // the ref. Unpatched rows no-op.- appliedDelta.resources.forEach(hydrateSlimResource);- rawServerResources = appliedDelta.resources;- changedResourceIds = appliedDelta.changedIds;- if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {- changedResourceIds.forEach((id) => {- const tickKeys = appliedDelta.changedKeys.get(id) ?? null;- deferredResourceKeys.set(- id,- deferredResourceIds.has(id)- ? unionResourceChangedKeys(deferredResourceKeys.get(id), tickKeys)- : tickKeys,- );- deferredResourceIds.add(id);- });+ if (+ typeof document !== 'undefined' &&+ document.visibilityState !== 'hidden' &&+ (isOperatorScrollActive() || deferredResourceDeltaQueue.length > 0)+ ) {+ // Mid-gesture ticks queue unapplied so they cost nothing+ // until scroll idle. A non-empty queue keeps queueing even+ // after the gesture ends so deltas never apply out of order.+ deferredResourceDeltaQueue.push(message.data.resourceDelta);+ scheduleDeferredResourceFlush();} else {- const combinedKeys = appliedDelta.changedKeys;- deferredResourceIds.forEach((id) => {- combinedKeys.set(- id,- combinedKeys.has(id)- ? unionResourceChangedKeys(- combinedKeys.get(id),- deferredResourceKeys.get(id) ?? null,- )- : (deferredResourceKeys.get(id) ?? null),- );- });- changedResourceIds = new Set([...deferredResourceIds, ...changedResourceIds]);- deferredResourceIds.clear();- deferredResourceKeys.clear();- changedResourceKeys = combinedKeys;- nextResources = mergeCanonicalResourceDeltaSnapshot(+ // Preserve arrival order before applying this tick in place.+ applyQueuedResourceDeltas();+ const appliedDelta = applyResourceStateDelta(rawServerResources,- state.resources,- changedResourceIds,- changedResourceKeys,+ message.data.resourceDelta,);+ // Patched rows are fresh objects: re-synthesize a nulled-out+ // default policy and re-expand capabilities when a patch+ // moved the ref. Unpatched rows no-op.+ appliedDelta.resources.forEach(hydrateSlimResource);+ rawServerResources = appliedDelta.resources;+ changedResourceIds = appliedDelta.changedIds;+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {+ changedResourceIds.forEach((id) => {+ const tickKeys = appliedDelta.changedKeys.get(id) ?? null;+ deferredResourceKeys.set(+ id,+ deferredResourceIds.has(id)+ ? unionResourceChangedKeys(deferredResourceKeys.get(id), tickKeys)+ : tickKeys,+ );+ deferredResourceIds.add(id);+ });+ } else {+ const combinedKeys = appliedDelta.changedKeys;+ deferredResourceIds.forEach((id) => {+ combinedKeys.set(+ id,+ combinedKeys.has(id)+ ? unionResourceChangedKeys(+ combinedKeys.get(id),+ deferredResourceKeys.get(id) ?? null,+ )+ : (deferredResourceKeys.get(id) ?? null),+ );+ });+ changedResourceIds = new Set([...deferredResourceIds, ...changedResourceIds]);+ deferredResourceIds.clear();+ deferredResourceKeys.clear();+ changedResourceKeys = combinedKeys;+ nextResources = mergeCanonicalResourceDeltaSnapshot(+ rawServerResources,+ state.resources,+ changedResourceIds,+ changedResourceKeys,+ );+ }}} else {// A delta landed before any full snapshot (e.g. the initial@@ -977,10 +1113,19 @@ export function createWebSocketStore(url: string) {// Updated recentlyResolved}- setState(- 'lastUpdate',- typeof message.data.lastUpdate === 'number' ? message.data.lastUpdate : Date.now(),- );+ const nextLastUpdate =+ typeof message.data.lastUpdate === 'number' ? message.data.lastUpdate : Date.now();+ if (+ typeof document !== 'undefined' &&+ document.visibilityState !== 'hidden' &&+ isOperatorScrollActive()+ ) {+ deferredLastUpdate = nextLastUpdate;+ scheduleDeferredResourceFlush();+ } else {+ deferredLastUpdate = null;+ setState('lastUpdate', nextLastUpdate);+ }});logger.debug('message', {type: message.type,@@ -1321,10 +1466,15 @@ export function createWebSocketStore(url: string) {pendingAckTimeouts.clear();if (typeof window !== 'undefined') {window.removeEventListener(ALERTS_DETECTION_EVENT, handleAlertsDetectionEvent);+ window.removeEventListener('scroll', handleOperatorScroll, { capture: true });}if (typeof document !== 'undefined') {document.removeEventListener('visibilitychange', handleResourceVisibilityChange);}+ if (deferredFlushTimer) {+ window.clearTimeout(deferredFlushTimer);+ deferredFlushTimer = 0;+ }if (ws) {ws.close(1000, 'Component unmounting');ws = null;