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
Fix row deletes that read state from first render
Juan Denis95a9e227fcf3
diff --git a/frontend/scripts/stale-columns-browser.mjs b/frontend/scripts/stale-columns-browser.mjsnew file mode 100644index 00000000..71384a26--- /dev/null+++ b/frontend/scripts/stale-columns-browser.mjs@@ -0,0 +1,98 @@+import assert from 'node:assert/strict';+import { existsSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { createServer } from 'vite';+import react from '@vitejs/plugin-react';+import { chromium } from 'playwright';++// Row actions inside memoized table columns. The columns were memoized+// without the state their delete handlers read, so a delete clicked after+// opening a vault or a variable group used the value from first render: the+// vault refresh read a null vault, and the variable delete sent group null.+// The real pages; only HTTP, toasts, confirm and translation are stubbed.+const root = fileURLToPath(new URL('../', import.meta.url));+const fixture = `+import React from 'react';+import {createRoot} from 'react-dom/client';+import {MemoryRouter} from 'react-router-dom';+import Vaults from '/src/pages/Vaults.jsx';+import SharedVariableGroups from '/src/components/shared/SharedVariableGroups.jsx';+const log=(...a)=>(window.calls=window.calls||[]).push(a);+const vault={id:11,name:'alpha-vault',description:'',secret_count:1,workspace_id:null};+window.testApi={+ listVaults:()=>Promise.resolve({vaults:[vault]}),+ getWorkspaces:()=>Promise.resolve({workspaces:[]}),+ getVault:(id)=>{log('getVault',id);return Promise.resolve({vault});},+ listSecrets:()=>Promise.resolve({secrets:[{id:5,name:'API_TOKEN',value:'••••',updated_at:null}]}),+ deleteSecret:(id)=>{log('deleteSecret',id);return Promise.resolve({});},+ listVariableGroups:()=>Promise.resolve({groups:[{id:21,name:'shared-env',variable_count:1,attachment_count:0}]}),+ getVariableGroup:(id)=>Promise.resolve({id,name:'shared-env',variables:[{id:31,key:'REGION',value:'x',is_secret:false}],attachments:[]}),+ deleteGroupVariable:(gid,vid)=>{log('deleteGroupVariable',gid,vid);return Promise.resolve({});},+};+const which=new URLSearchParams(location.search).get('page');+createRoot(document.getElementById('root')).render(<MemoryRouter>{which==='vaults'?<Vaults/>:<SharedVariableGroups scopeType="workspace" scopeId={1}/>}</MemoryRouter>);+`;+const server = await createServer({+ root, configFile: false, logLevel: 'error', resolve: { alias: { '@': path.join(root, 'src') } },+ cacheDir: path.join(root, 'node_modules/.vite-stale-columns-regression'),+ optimizeDeps: { entries: [] }, server: { host: '127.0.0.1', port: 0 },+ plugins: [{+ name: 'stale-columns-fixtures', enforce: 'pre',+ resolveId(id) {+ if (id === 'react-i18next') return '\0test-i18n';+ if (id.endsWith('/sc-fixture.jsx')) return path.join(root, 'sc-fixture.jsx');+ },+ load(id) {+ const normalized = id.replaceAll('\\', '/');+ if (id === '\0test-i18n') return `const t=(key,f)=>typeof f==='string'?f:(f&&(f.defaultValue_other||f.defaultValue))||key;export const useTranslation=()=>({t,i18n:{language:'en'}});export const Trans=({children})=>children;export const initReactI18next={type:'3rdParty',init(){}};`;+ if (normalized.endsWith('/src/contexts/useWorkspace.js')) return `const ws={activeWorkspaceId:null,workspaces:[],setActiveWorkspace(){}};export const useWorkspace=()=>ws;`;+ if (normalized.endsWith('/src/contexts/useToast.js')) return `const toast={error(m){(window.toasts=window.toasts||[]).push(m)},success(){},info(){},warning(){}};export const useToast=()=>toast;`;+ if (normalized.endsWith('/src/hooks/useConfirm.js')) return `const confirm=async()=>true;export function useConfirm(){return {confirm,confirmState:{isOpen:false},handleConfirm(){},handleCancel(){}};}`;+ if (normalized.endsWith('/src/services/api.js') || normalized.endsWith('/src/services/api/index.js')) return `const api=new Proxy({}, {get:(_,key)=>(...args)=>(window.testApi[key]?window.testApi[key](...args):Promise.resolve({}))});export {api};export default api;`;+ if (normalized.endsWith('/sc-fixture.jsx')) return fixture;+ },+ configureServer(vite) {+ vite.middlewares.use('/sc-check', async (_req, res) => {+ res.setHeader('Content-Type', 'text/html');+ res.end(await vite.transformIndexHtml('/sc-check', '<div id="root"></div><script type="module" src="/sc-fixture.jsx"></script>'));+ });+ },+ }, react()],+});+const executablePath = [process.env.CHROME_PATH, chromium.executablePath(), 'C:/Program Files/Google/Chrome/Application/chrome.exe', 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'].find(candidate => candidate && existsSync(candidate));+let browser;+try {+ await server.listen();+ browser = await chromium.launch({ ...(executablePath ? { executablePath } : {}), headless: true });+ const base = `http://127.0.0.1:${server.httpServer.address().port}/sc-check`;++ const vaults = await browser.newPage();+ const vaultErrors = [];+ vaults.on('pageerror', error => vaultErrors.push(error.message));+ await vaults.goto(`${base}?page=vaults`);+ await vaults.getByText('alpha-vault').first().click();+ await vaults.getByText('API_TOKEN').first().waitFor();+ await vaults.getByTitle('Delete', { exact: true }).first().click();+ await vaults.waitForFunction(() => window.calls.filter(c => c[0] === 'getVault').length === 2);+ assert.deepEqual(await vaults.evaluate(() => window.calls),+ [['getVault', 11], ['deleteSecret', 5], ['getVault', 11]]);+ assert.deepEqual(await vaults.evaluate(() => window.toasts || []), []);+ assert.deepEqual(vaultErrors, []);+ console.log('PASS deleting a secret refreshes the vault that is open');++ const groups = await browser.newPage();+ const groupErrors = [];+ groups.on('pageerror', error => groupErrors.push(error.message));+ await groups.goto(`${base}?page=groups`);+ await groups.getByText('shared-env').first().click();+ await groups.getByText('REGION').first().waitFor();+ await groups.getByTitle('Delete variable', { exact: true }).first().click();+ await groups.waitForFunction(() => (window.calls || []).some(c => c[0] === 'deleteGroupVariable'));+ assert.deepEqual(await groups.evaluate(() => window.calls), [['deleteGroupVariable', 21, 31]]);+ assert.deepEqual(groupErrors, []);+ console.log('PASS deleting a group variable names the open group');+} finally {+ await browser?.close();+ await server.close();+}diff --git a/frontend/src/components/shared/SharedVariableGroups.jsx b/frontend/src/components/shared/SharedVariableGroups.jsxindex 442765f8..d8ffc230 100644--- a/frontend/src/components/shared/SharedVariableGroups.jsx+++ b/frontend/src/components/shared/SharedVariableGroups.jsx@@ -289,7 +289,7 @@ const SharedVariableGroups = ({ scopeType = 'workspace', scopeId = 'default' })),},// eslint-disable-next-line react-hooks/exhaustive-deps- ], []);+ ], [selectedId, loadGroups]);const variableColumns = useMemo(() => [{@@ -350,7 +350,7 @@ const SharedVariableGroups = ({ scopeType = 'workspace', scopeId = 'default' })),},// eslint-disable-next-line react-hooks/exhaustive-deps- ], []);+ ], [selectedId, loadDetail, loadGroups]);if (!detail) {return (diff --git a/frontend/src/pages/Vaults.jsx b/frontend/src/pages/Vaults.jsxindex 6eddd94c..1dff35ee 100644--- a/frontend/src/pages/Vaults.jsx+++ b/frontend/src/pages/Vaults.jsx@@ -333,7 +333,7 @@ export default function Vaults() {},},// eslint-disable-next-line react-hooks/exhaustive-deps- ], [revealSecretId, revealedValue]);+ ], [revealSecretId, revealedValue, selectedVault]);const vaultTable = selectedVault ? (<ResourceListPage