From 7eb6d33dadbe75b4047466d3c944543e33e6d90e Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sat, 13 Dec 2025 21:30:36 +0000 Subject: [PATCH] fix: add null safety checks for resources() in useResourcesAsLegacy Prevents errors when resources array is undefined during initial load. --- frontend-modern/src/hooks/useResources.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend-modern/src/hooks/useResources.ts b/frontend-modern/src/hooks/useResources.ts index db0a296..f562a8d 100644 --- a/frontend-modern/src/hooks/useResources.ts +++ b/frontend-modern/src/hooks/useResources.ts @@ -246,13 +246,13 @@ export function useResourcesAsLegacy() { // by id in the WebSocket store (stable identities, fine-grained updates). // Only synthesize legacy types from unified resources when it looks like the backend // isn't providing that legacy field (e.g., resources include the type but legacy array is empty). - const hasVmResources = createMemo(() => resources().some((r) => r.type === 'vm')); - const hasNodeResources = createMemo(() => resources().some((r) => r.type === 'node')); + const hasVmResources = createMemo(() => (resources() || []).some((r) => r.type === 'vm')); + const hasNodeResources = createMemo(() => (resources() || []).some((r) => r.type === 'node')); const hasContainerResources = createMemo(() => - resources().some((r) => r.type === 'container' || r.type === 'oci-container'), + (resources() || []).some((r) => r.type === 'container' || r.type === 'oci-container'), ); - const hasHostResources = createMemo(() => resources().some((r) => r.type === 'host')); - const hasDockerHostResources = createMemo(() => resources().some((r) => r.type === 'docker-host')); + const hasHostResources = createMemo(() => (resources() || []).some((r) => r.type === 'host')); + const hasDockerHostResources = createMemo(() => (resources() || []).some((r) => r.type === 'docker-host')); // Convert resources to legacy VM format // Falls back to legacy state.vms array when unified resources aren't yet populated