From b4edb56132f7443a41beb1fe857bf881ab0c077d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Narciso=20E=2E=20N=C3=BA=C3=B1ez=20Arias?= Date: Wed, 19 Aug 2026 16:00:26 -0400 Subject: [PATCH] Merge pull request #5116 from thaingnguyen/agent/fix-stack-log-container-selection fix: preserve selected stack log container (cherry picked from commit 9dab15ad4761e9970f782a61dde1cfa70ded6cea) [skip ci] --- .../dashboard/compose/logs/show-stack.tsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/dokploy/components/dashboard/compose/logs/show-stack.tsx b/apps/dokploy/components/dashboard/compose/logs/show-stack.tsx index a7b4d3014..558dc1c0f 100644 --- a/apps/dokploy/components/dashboard/compose/logs/show-stack.tsx +++ b/apps/dokploy/components/dashboard/compose/logs/show-stack.tsx @@ -72,16 +72,20 @@ export const ShowDockerLogsStack = ({ const containers = data?.filter((container) => container.containerId); useEffect(() => { - if (option === "native") { - if (containers && containers?.length > 0) { - setContainerId(containers[0]?.containerId); - } - } else { - if (services && services?.length > 0) { - setContainerId(services[0]?.containerId); + const currentContainers = option === "native" ? containers : services; + + if (currentContainers) { + const nextContainerId = currentContainers.some( + (container) => container.containerId === containerId, + ) + ? containerId + : currentContainers[0]?.containerId; + + if (nextContainerId !== containerId) { + setContainerId(nextContainerId); } } - }, [option, services, containers]); + }, [option, services, containers, containerId]); const isLoading = option === "native" ? containersLoading : servicesLoading; const containersLength = @@ -106,6 +110,7 @@ export const ShowDockerLogsStack = ({ { + setContainerId(undefined); setOption(checked ? "native" : "swarm"); }} />