Skip to content

Lightweight server monitoring with historical data, docker stats, and alerts.

fix(ui): order container refreshes after initial load on All Containers page

henrygd9afebd3f0285
diff --git a/internal/site/src/components/containers-table/containers-table.tsx b/internal/site/src/components/containers-table/containers-table.tsx
index e9b4e44fc..2879d7051 100644
--- a/internal/site/src/components/containers-table/containers-table.tsx
+++ b/internal/site/src/components/containers-table/containers-table.tsx
@@ -39,7 +39,6 @@ import { getLogTimestampDecorations } from "@/lib/logs"
const syntaxTheme = "github-dark-dimmed"
export default function ContainersTable({ systemId }: { systemId?: string }) {
- const loadTime = Date.now()
const [data, setData] = useState<ContainerRecord[] | undefined>(undefined)
const [sorting, setSorting] = useBrowserStorage<SortingState>(
`sort-c-${systemId ? 1 : 0}`,
@@ -68,7 +67,8 @@ export default function ContainersTable({ systemId }: { systemId?: string }) {
useEffect(() => {
function fetchData(systemId?: string) {
- pb.collection<ContainerRecord>("containers")
+ return pb
+ .collection<ContainerRecord>("containers")
.getList(0, 2000, {
fields: "id,name,image,updatable,ports,cpu,memory,net,health,status,system,updated",
filter: systemId ? pb.filter("system={:system}", { system: systemId }) : undefined,
@@ -102,17 +102,21 @@ export default function ContainersTable({ systemId }: { systemId?: string }) {
return newItems
})
})
+ .catch((e) => {
+ if (!e?.isAbort) console.error(e)
+ })
}
// initial load
- fetchData(systemId)
+ const initialLoad = fetchData(systemId)
// if no systemId, pull system containers after every system update
if (!systemId) {
- return $allSystemsById.listen((_value, _oldValue, systemId) => {
- // exclude initial load of systems
- if (Date.now() - loadTime > 500) {
- fetchData(systemId)
+ return $allSystemsById.listen((_value, oldValue, systemId) => {
+ // skip newly added systems (initial population of the store)
+ if (oldValue[systemId]) {
+ // wait for initial load so its older snapshot can't overwrite newer data
+ initialLoad.then(() => fetchData(systemId))
}
})
}