Spaces:
Paused

dushyantsingh0 Claude Sonnet 4.6 commited on
Commit
4dd1686
·
1 Parent(s): 0eb22a3

fix: eliminate loading flash on ticket queue navigation in both portals

Browse files

Internal portal: sort_by was always 'recency' which made hasFilters=true
on every mount, forcing globalQueueLoading=true every time the board
opened. sort_by is a presentation preference, not a data filter.

Customer portal: useTicketsPaginated started with useState([]) on every
remount, causing a flash of empty state before the useEffect could
hydrate from sessionStorage. Module-level globalLastResult seeds useState
with the most recent valid cache entry so remounts show stale data
instantly with no visible loading gap.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

frontend/packages/shared/src/hooks/useTickets.ts CHANGED
@@ -171,7 +171,9 @@ export const useAgentQueue = (
171
  const fetchQueue = useCallback(async (force: boolean = false) => {
172
  const lastFetch = lastQueueFetchMap[wsKey] || 0;
173
  const isStale = Date.now() - lastFetch > STALE_WINDOW;
174
- const hasFilters = !!(status_filter || priority_filter || search_query || creator_query || ticket_id_filter || sort_by);
 
 
175
 
176
  // Bypass cache when filters are active or a forced refresh was requested
177
  if (!force && !hasFilters && (globalQueueMap[wsKey] || []).length > 0 && !isStale) return;
 
171
  const fetchQueue = useCallback(async (force: boolean = false) => {
172
  const lastFetch = lastQueueFetchMap[wsKey] || 0;
173
  const isStale = Date.now() - lastFetch > STALE_WINDOW;
174
+ // sort_by is a presentation preference, not a data filter — including it
175
+ // caused loading=true on every board navigation since it's always 'recency'.
176
+ const hasFilters = !!(status_filter || priority_filter || search_query || creator_query || ticket_id_filter);
177
 
178
  // Bypass cache when filters are active or a forced refresh was requested
179
  if (!force && !hasFilters && (globalQueueMap[wsKey] || []).length > 0 && !isStale) return;
frontend/packages/shared/src/hooks/useTicketsPaginated.ts CHANGED
@@ -30,6 +30,27 @@ const PAGINATED_CACHE_PREFIX = 'nexus_pg_';
30
  const MAX_PAGINATED_CACHE_ENTRIES = 10;
31
  const PAGINATED_CACHE_TTL_MS = 60_000; // 1 minute
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  function getPaginatedCacheKey(params: FetchParams): string {
34
  return PAGINATED_CACHE_PREFIX + JSON.stringify(params);
35
  }
@@ -61,8 +82,8 @@ function evictOldPaginatedEntries(): void {
61
  }
62
 
63
  export const useTicketsPaginated = () => {
64
- const [tickets, setTickets] = useState<Ticket[]>([]);
65
- const [total, setTotal] = useState(0);
66
  const [loading, setLoading] = useState(false);
67
  const [error, setError] = useState<string | null>(null);
68
 
@@ -97,6 +118,7 @@ export const useTicketsPaginated = () => {
97
  });
98
  setTickets(response.data.items);
99
  setTotal(response.data.total);
 
100
 
101
  // Write to bounded cache — evict old entries before inserting
102
  evictOldPaginatedEntries();
 
30
  const MAX_PAGINATED_CACHE_ENTRIES = 10;
31
  const PAGINATED_CACHE_TTL_MS = 60_000; // 1 minute
32
 
33
+ // Module-level last-result: survives component remounts so useState can be
34
+ // seeded with stale data immediately, eliminating the empty-flash on navigation.
35
+ let globalLastResult: { tickets: Ticket[]; total: number } | null = (() => {
36
+ try {
37
+ let best: { tickets: Ticket[]; total: number; ts: number } | null = null;
38
+ for (let i = 0; i < sessionStorage.length; i++) {
39
+ const k = sessionStorage.key(i);
40
+ if (!k?.startsWith(PAGINATED_CACHE_PREFIX)) continue;
41
+ const raw = sessionStorage.getItem(k);
42
+ if (!raw) continue;
43
+ const parsed = JSON.parse(raw);
44
+ if (Date.now() - (parsed.timestamp ?? 0) < PAGINATED_CACHE_TTL_MS) {
45
+ if (!best || parsed.timestamp > best.ts) {
46
+ best = { tickets: parsed.items, total: parsed.total, ts: parsed.timestamp };
47
+ }
48
+ }
49
+ }
50
+ return best ? { tickets: best.tickets, total: best.total } : null;
51
+ } catch { return null; }
52
+ })();
53
+
54
  function getPaginatedCacheKey(params: FetchParams): string {
55
  return PAGINATED_CACHE_PREFIX + JSON.stringify(params);
56
  }
 
82
  }
83
 
84
  export const useTicketsPaginated = () => {
85
+ const [tickets, setTickets] = useState<Ticket[]>(globalLastResult?.tickets ?? []);
86
+ const [total, setTotal] = useState(globalLastResult?.total ?? 0);
87
  const [loading, setLoading] = useState(false);
88
  const [error, setError] = useState<string | null>(null);
89
 
 
118
  });
119
  setTickets(response.data.items);
120
  setTotal(response.data.total);
121
+ globalLastResult = { tickets: response.data.items, total: response.data.total };
122
 
123
  // Write to bounded cache — evict old entries before inserting
124
  evictOldPaginatedEntries();