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.

Wait for canonical resource hydrate before ws paint

rcourtman97e0820a2bf1
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 60e1f54184..566c003880 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -95,7 +95,10 @@ querying, and the operator-facing storage health presentation layer.
thinner websocket `state.resources` payloads may refresh status and metrics,
but they must not downgrade richer REST-hydrated platform summary fields or
synthesize standalone `clusterId` values from resource names while the same
- session is open.
+ session is open. For the default immediate-hydration path, storage and
+ recovery consumers must also wait for the first canonical REST snapshot
+ instead of painting thinner websocket transport rows first and then
+ rehydrating into a richer canonical shape a moment later.
Storage and recovery consumers must also inherit the hook's canonical
`ResourceType` normalization for route/query filters, so storage subtypes
such as `physical_disk` stay on the same cache-backed snapshot instead of
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index ed8844a99b..8c73820670 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -175,7 +175,11 @@ assembly branch.
across transport boundaries: thinner realtime `state.resources` payloads
must merge into the existing canonical resource snapshot instead of
downgrading richer REST-only infrastructure details such as disk I/O, source
- metadata, or platform summary fields after first hydrate.
+ metadata, or platform summary fields after first hydrate. For default
+ `initialHydration: 'immediate'` consumers, that same path must not paint the
+ thinner websocket transport before the first canonical REST snapshot exists;
+ only explicit `prefer-ws` consumers may render directly from the realtime
+ transport before canonical hydrate completes.
Canonical cluster membership in that shared path must come only from
explicit cluster identity such as Kubernetes context or platform cluster
labels; standalone resource names must never be repurposed as synthetic
diff --git a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts
index be569c7736..7e220c7867 100644
--- a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts
+++ b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts
@@ -291,6 +291,44 @@ describe('useUnifiedResources', () => {
dispose();
});
+ it('waits for the first canonical REST snapshot before painting immediate hydration screens', async () => {
+ let resolveFetch:
+ | ((value: { ok: true; json: () => Promise<{ data: Array<typeof v2Resource> }> }) => void)
+ | undefined;
+ apiFetchMock.mockImplementation(
+ () =>
+ new Promise((resolve) => {
+ resolveFetch = resolve;
+ }),
+ );
+
+ let dispose = () => {};
+ let result: ReturnType<UseUnifiedResourcesModule['useUnifiedResources']> | undefined;
+ createRoot((d) => {
+ dispose = d;
+ result = useUnifiedResources();
+ });
+
+ await flushAsync();
+
+ expect(apiFetchMock).toHaveBeenCalledTimes(1);
+ expect(result!.loading()).toBe(true);
+ expect(result!.resources()).toHaveLength(0);
+
+ resolveFetch?.({
+ ok: true,
+ json: async () => ({ data: [v2Resource] }),
+ });
+
+ await waitForResourceCount(() => result!.resources().length);
+ await waitForValue(() => result!.loading(), false);
+
+ expect(result!.resources()[0]?.id).toBe(v2Resource.id);
+ expect(result!.resources()[0]?.displayName).toBe(v2Resource.name);
+
+ dispose();
+ });
+
it('skips unified resource hydration while disabled and resumes when enabled', async () => {
let dispose = () => {};
let result: ReturnType<UseUnifiedResourcesModule['useUnifiedResources']> | undefined;
diff --git a/frontend-modern/src/hooks/useUnifiedResources.ts b/frontend-modern/src/hooks/useUnifiedResources.ts
index b78f57ae4e..a6850e0506 100644
--- a/frontend-modern/src/hooks/useUnifiedResources.ts
+++ b/frontend-modern/src/hooks/useUnifiedResources.ts
@@ -1136,6 +1136,12 @@ export function useUnifiedResources(options?: UseUnifiedResourcesOptions) {
}
const wsResources = Array.isArray(wsStore.state.resources) ? wsStore.state.resources : [];
+ // For normal page loads, keep the first paint on the canonical REST contract.
+ // Only `prefer-ws` consumers are allowed to render directly from the thinner
+ // realtime transport before a canonical snapshot exists.
+ if (!cacheEntry.hasSnapshot && !prefersWsInitialHydration) {
+ return;
+ }
const allResourcesEntry = getUnifiedResourcesCacheEntry(
buildScopedUnifiedResourcesCacheKey(ALL_RESOURCES_CACHE_KEY, currentOrgScope),
);