Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

fix(frontend): stop restoring table filter from storage

Sergey Kozyrenkof8c2876cdf85
diff --git a/frontend/src/hooks/use-table-state.test.tsx b/frontend/src/hooks/use-table-state.test.tsx
index f2c22314..1a18d791 100644
--- a/frontend/src/hooks/use-table-state.test.tsx
+++ b/frontend/src/hooks/use-table-state.test.tsx
@@ -20,17 +20,16 @@ interface RenderResult {
update: ReturnType<typeof useTableState>['update'];
}
-const useStateWithLocation = (options: { debounceMs?: number; storageKey?: string } = {}): RenderResult => {
+const useStateWithLocation = (options: { debounceMs?: number } = {}): RenderResult => {
const { debouncedFilter, filter, pageIndex, resetFilter, setFilter, setPage, update } = useTableState({
debounceMs: options.debounceMs ?? SHORT_DEBOUNCE_MS,
- storageKey: options.storageKey ?? STORAGE_KEY,
});
const { search } = useLocation();
return { debouncedFilter, filter, pageIndex, resetFilter, search, setFilter, setPage, update };
};
-const renderWithRouter = (initialEntries: string[], options?: { debounceMs?: number; storageKey?: string }) => {
+const renderWithRouter = (initialEntries: string[], options?: { debounceMs?: number }) => {
const Wrapper = ({ children }: { children: ReactNode }) => (
<MemoryRouter initialEntries={initialEntries}>{children}</MemoryRouter>
);
@@ -207,37 +206,35 @@ describe('useTableState — atomic `update` (race regression)', () => {
});
});
-describe('useTableState — storage roundtrip', () => {
- it('restores `?q=` from storage when the URL is empty', async () => {
+describe('useTableState — filter is URL-only', () => {
+ // Filter is an ad-hoc query, not a preference. We deliberately do NOT
+ // mirror it into storage or replay it from storage on mount — a fresh
+ // navigation to `/flows` should land on an empty filter even if the user
+ // typed something there earlier in the session. Sorting / column
+ // visibility / page size still persist via `lib/table-state`.
+
+ it('does not restore `?q=` from storage on mount', async () => {
localStorage.setItem(STORAGE_KEY, JSON.stringify({ filter: 'alpha' }));
const { result } = renderWithRouter(['/flows']);
- await waitFor(() => {
- expect(new URLSearchParams(result.current.search).get('q')).toBe('alpha');
- });
+ await act(async () => Promise.resolve());
+ expect(result.current.filter).toBe('');
+ expect(new URLSearchParams(result.current.search).has('q')).toBe(false);
});
- it('does not restore when the URL already has `?q=`', async () => {
+ it('honours `?q=` from the URL regardless of what is in storage', async () => {
localStorage.setItem(STORAGE_KEY, JSON.stringify({ filter: 'stored' }));
const { result } = renderWithRouter(['/flows?q=urlwin']);
await act(async () => Promise.resolve());
expect(result.current.filter).toBe('urlwin');
});
- it('persists the URL filter into storage once typing settles', async () => {
+ it('does not write the typed filter into storage', async () => {
const { result } = renderWithRouter(['/flows']);
act(() => result.current.setFilter('alpha'));
await waitFor(() => {
- expect(readStoredFilter(STORAGE_KEY)).toBe('alpha');
- });
- });
-
- it('clears the storage entry when the filter is set back to empty', async () => {
- localStorage.setItem(STORAGE_KEY, JSON.stringify({ filter: 'alpha' }));
- const { result } = renderWithRouter(['/flows?q=alpha']);
- act(() => result.current.setFilter(''));
- await waitFor(() => {
- expect(readStoredFilter(STORAGE_KEY)).toBeNull();
+ expect(new URLSearchParams(result.current.search).get('q')).toBe('alpha');
});
+ expect(readStoredFilter(STORAGE_KEY)).toBeNull();
});
});
diff --git a/frontend/src/hooks/use-table-state.ts b/frontend/src/hooks/use-table-state.ts
index e2d84b04..8c441fe9 100644
--- a/frontend/src/hooks/use-table-state.ts
+++ b/frontend/src/hooks/use-table-state.ts
@@ -2,9 +2,6 @@ import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useDebouncedValue } from '@/hooks/use-debounced-value';
-import { useEffectAfterMount } from '@/hooks/use-effect-after-mount';
-import { usePageStorageKeys } from '@/hooks/use-page-storage-keys';
-import { loadTableState, updateTableState } from '@/lib/table-state';
import { URL_PARAMS } from '@/lib/url-params';
/**
@@ -36,24 +33,6 @@ interface UseTableStateOptions {
filterParamName?: string;
/** Query string param for the 1-based page number. Default `URL_PARAMS.PAGE` (`'page'`). */
pageParamName?: string;
- /**
- * Suppresses the one-time storage → URL restore on mount. Use on pages
- * that route the `?q=` filter alongside a sibling URL parameter with
- * its own filter semantics — e.g. `/knowledges` combines `?q=` (client
- * text filter) with `?qs=` (server semantic search). Restoring a
- * previously-typed `?q=` on top of a freshly-opened `?qs=` link would
- * silently narrow the search result the user navigated to. The caller
- * decides per-mount whether restore should fire; the value is captured
- * via a ref at mount time so a later toggle doesn't replay a restore
- * the user has since worked past.
- */
- skipRestore?: boolean;
- /**
- * Stable storage key for persisting the filter value (a fresh tab without
- * `?<filterParamName>=` resumes from here). Defaults to
- * `usePageStorageKeys().table` — i.e. `table_4_<current pathname>`.
- */
- storageKey?: string;
}
interface UseTableStateResult {
@@ -73,7 +52,12 @@ interface UseTableStateResult {
}
/**
- * Unified URL + storage state for tables.
+ * Unified URL state for tables — filter + page index live in the query string,
+ * never in storage. A fresh visit to the page without `?q=` shows an empty
+ * filter; only shared URLs (or the user's own back/forward) restore the prior
+ * filter. View preferences (sorting, column visibility, page size, search
+ * columns) still persist via `lib/table-state` — only the ad-hoc query is
+ * URL-only.
*
* Replaces the split `useTableQueryFilter` / `usePagination` pair. The split
* design suffered from a batching race: react-router v6 feeds every
@@ -98,13 +82,9 @@ export function useTableState(options: UseTableStateOptions = {}): UseTableState
debounceMs = 200,
filterParamName = URL_PARAMS.QUERY,
pageParamName = URL_PARAMS.PAGE,
- skipRestore = false,
- storageKey: explicitStorageKey,
} = options;
const [searchParams, setSearchParams] = useSearchParams();
- const { table: defaultStorageKey } = usePageStorageKeys();
- const storageKey = explicitStorageKey ?? defaultStorageKey;
const filter = searchParams.get(filterParamName) ?? '';
const debouncedFilter = useDebouncedValue(filter, debounceMs);
@@ -162,59 +142,6 @@ export function useTableState(options: UseTableStateOptions = {}): UseTableState
setSearchParams(next, { replace: true });
}, [pageParamName, readLatestParams, searchParams, setSearchParams]);
- // Replay the persisted filter into the URL when (a) the URL doesn't
- // already carry one, and (b) the storage has a non-empty value. Run
- // exactly once per storageKey rotation — `restoredForKeyReference`
- // guards against repeating the replay on every render.
- const restoredForKeyReference = useRef<null | string>(null);
- // Snapshot the `skipRestore` decision at mount via a ref so a later
- // toggle (e.g. the user clearing `?qs=`) doesn't fire the restore
- // mid-session — by then they've already engaged with the page and a
- // surprise URL mutation would be jarring.
- const skipRestoreRef = useRef(skipRestore);
-
- useEffect(() => {
- if (restoredForKeyReference.current === storageKey) {
- return;
- }
-
- restoredForKeyReference.current = storageKey;
-
- if (skipRestoreRef.current) {
- return;
- }
-
- if (filter.length > 0) {
- // URL already has a value — that beats storage. Mirror it back
- // into storage so a fresh tab without `?q=` resumes from this
- // intent (shared filtered links).
- updateTableState(storageKey, { filter });
-
- return;
- }
-
- const stored = loadTableState(storageKey).filter;
-
- if (!stored || stored.length === 0) {
- return;
- }
-
- const next = readLatestParams();
-
- next.set(filterParamName, stored);
- // Replace, not push: restoring prior state shouldn't add a history
- // entry the user didn't ask for.
- setSearchParams(next, { replace: true });
- }, [filter, filterParamName, readLatestParams, setSearchParams, storageKey]);
-
- // Persist the URL filter into storage on every commit. Skipping the
- // first render is intentional: a fresh-mount empty `filter` would wipe
- // a freshly-restored storage entry before the restore effect above has
- // had a chance to replay it into the URL.
- useEffectAfterMount(() => {
- updateTableState(storageKey, { filter: filter.length > 0 ? filter : undefined });
- }, [filter, storageKey]);
-
// Coalesce every `update(...)` call fired in the same microtask into one
// `setSearchParams`. The first call schedules the flush; subsequent calls
// merge their patch into the pending buffer instead of issuing their own
diff --git a/frontend/src/pages/knowledges/knowledges.tsx b/frontend/src/pages/knowledges/knowledges.tsx
index e51d035f..f0c7dbef 100644
--- a/frontend/src/pages/knowledges/knowledges.tsx
+++ b/frontend/src/pages/knowledges/knowledges.tsx
@@ -64,16 +64,8 @@ function Knowledges() {
const [isRenameLoading, setIsRenameLoading] = useState(false);
const editingInputRef = useRef<HTMLInputElement>(null);
- // When the user lands on a `?qs=` link (server semantic search) we
- // must suppress the storage→URL `?q=` restore. Re-injecting a previous
- // session's client filter on top of a fresh semantic-search URL would
- // silently narrow the result set behind the user's back.
- // `useTableState` reads `skipRestore` once at mount via a ref, so a
- // later toggle (user clears `?qs=`) won't replay the restore.
const [searchParams, setSearchParams] = useSearchParams();
- const { filter, setFilter } = useTableState({
- skipRestore: searchParams.has(URL_PARAMS.SEARCH),
- });
+ const { filter, setFilter } = useTableState();
// Source-of-truth for the semantic-search input is the URL. The
// `KnowledgesProvider` reads the same `?qs=` and debounces it before