ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
perf(frontend): stop pollers stacking, and stop probing absent features
Juan Denisbc51ac47cb5e
diff --git a/frontend/src/components/DeployPill.jsx b/frontend/src/components/DeployPill.jsxindex 8e35db0f..44fc5486 100644--- a/frontend/src/components/DeployPill.jsx+++ b/frontend/src/components/DeployPill.jsx@@ -1,4 +1,4 @@-import { useEffect, useState, useCallback } from 'react';+import { useEffect, useState, useCallback, useRef } from 'react';import { Link, useLocation } from 'react-router-dom';import { Loader2 } from 'lucide-react';import api from '../services/api';@@ -23,28 +23,56 @@ export default function DeployPill() {// Deploy Activity and the console are the surface this pill points at.const onDeploySurface = pathname === '/deployments' || pathname.startsWith('/deployments/');+ // A tick must never start while the previous one is outstanding. This pill+ // lives in the global shell, so it polls on EVERY authenticated route; when+ // the backend is slow a 6s interval with no guard stacks a new pair of+ // requests every 6s on top of the ones already waiting. A 30s response time+ // means five concurrent `status=running` calls — which is exactly what a+ // DevTools capture of /domains showed, alongside a wall of pending rows.+ const inFlight = useRef(false);+const refresh = useCallback(async () => {+ if (inFlight.current) return;+ inFlight.current = true;try {- const [running, pending] = await Promise.all([- api.getDeploymentJobs({ status: 'running', limit: 20 }),- api.getDeploymentJobs({ status: 'pending', limit: 20 }),- ]);- const jobs = [...(running?.jobs || []), ...(pending?.jobs || [])];- setActive(jobs);+ // One request, not two. The endpoint returns the job's status, so+ // asking for each status separately doubled the request count to+ // learn the same thing.+ const res = await api.getDeploymentJobs({ limit: 20 });+ setActive((res?.jobs || []).filter(+ (job) => job.status === 'running' || job.status === 'pending',+ ));} catch {// Silent — the pill is a convenience, not critical chrome.+ } finally {+ inFlight.current = false;}}, []);useEffect(() => {if (onDeploySurface) return undefined;- refresh();- const t = setInterval(refresh, POLL_MS);- // React quickly to live status changes when a console elsewhere is streaming.++ // Polling a background tab buys nothing and competes for the browser's+ // per-origin connections with whatever the visible tab is doing.+ const tick = () => {+ if (document.visibilityState !== 'visible') return;+ refresh();+ };+ tick();+ const t = setInterval(tick, POLL_MS);++ // Catch up once when the tab comes back rather than polling all along.+ const onVisible = () => { if (document.visibilityState === 'visible') refresh(); };+ document.addEventListener('visibilitychange', onVisible);++ // React quickly to live status changes when a console elsewhere is+ // streaming — but a burst of deploy_status events must not become a+ // burst of requests, so the in-flight guard covers these too.const unsubStatus = socketService.on('deploy_status', refresh);const unsubConnect = socketService.on('connected', refresh);return () => {clearInterval(t);+ document.removeEventListener('visibilitychange', onVisible);unsubStatus();unsubConnect();};diff --git a/frontend/src/components/Sidebar.jsx b/frontend/src/components/Sidebar.jsxindex b75b4665..5dabff3b 100644--- a/frontend/src/components/Sidebar.jsx+++ b/frontend/src/components/Sidebar.jsx@@ -100,19 +100,36 @@ const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {};}, [menuOpen]);- // Check if WordPress is installed+ const { nav: pluginNav, tabs: pluginTabs } = useContributions();++ // Runtime conditions are probed ONLY when a contributed nav item actually+ // asks for one. These two probes used to fire unconditionally on every app+ // load, and both endpoints belong to extensions — /gpu/ to serverkit-gpu,+ // /wordpress/standalone/status to serverkit-wordpress. With the extension+ // absent the route is not registered, so the call is a guaranteed 404 that+ // cannot change a single rendered pixel: the only manifest declaring+ // `requiresCondition: "gpuAvailable"` ships with the GPU extension itself,+ // so when it is gone nothing reads the answer.+ //+ // They were not free. In dev the API shares the browser's 6-connection+ // HTTP/1.1 pool with Vite's module graph, so two doomed requests hold a+ // third of the page's connection budget for their entire lifetime.+ const needsGpu = (pluginNav || []).some((i) => i?.requiresCondition === 'gpuAvailable');+ const needsWp = (pluginNav || []).some((i) => i?.requiresCondition === 'wpInstalled');+useEffect(() => {+ if (!needsWp) { setWpInstalled(false); return; }api.getWordPressStatus().then(data => setWpInstalled(!!data?.installed)).catch(() => setWpInstalled(false));- }, []);+ }, [needsWp]);- // Hide GPU Monitor when the host has no GPU (mirrors the wpInstalled gate).useEffect(() => {+ if (!needsGpu) { setGpuAvailable(false); return; }api.getGpuInfo().then(data => setGpuAvailable(!!data?.available)).catch(() => setGpuAvailable(false));- }, []);+ }, [needsGpu]);// Feature-module toggles (WordPress; Email is now an extension). Default to// enabled until the shared module state loads so items never flicker/hide.@@ -141,8 +158,6 @@ const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {api.updateCurrentUser({ sidebar_config: config }).catch(() => {});};- const { nav: pluginNav, tabs: pluginTabs } = useContributions();-const visibleItems = useMemo(() => {const core = getVisibleItems(user?.sidebar_config);const hiddenIds = getHiddenItemIds(user?.sidebar_config);