11import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
22import { useCallback , useEffect } from "react" ;
33import type { RouterInputs , RouterOutputs } from "@/server/lib/router" ;
4- import { useAuth } from "@/web/lib /auth-context " ;
4+ import { useAuth } from "@/web/components /auth-provider " ;
55import { orpc } from "@/web/lib/orpc" ;
66import {
77 getStoredChatWidth ,
@@ -23,8 +23,14 @@ const DEFAULT_USER_SETTINGS: UserSettings = {
2323
2424/**
2525 * Shared hook for accessing user settings across the application.
26- * This hook consolidates all user settings queries into a single query,
27- * preventing excessive refetches and potential infinite loops.
26+ *
27+ * Caching Strategy:
28+ * - 5 minute staleTime (matches server cookie cache duration)
29+ * - No automatic refetching (refetchOnMount disabled)
30+ * - Optimistic updates on mutations for instant UI feedback
31+ *
32+ * This consolidates all user settings queries into a single query,
33+ * preventing excessive refetches and reducing server load.
2834 */
2935export function useUserSettings ( ) {
3036 const auth = useAuth ( ) ;
@@ -33,8 +39,9 @@ export function useUserSettings() {
3339 const query = useQuery (
3440 orpc . settings . get . queryOptions ( {
3541 enabled : isAuthenticated ,
36- staleTime : 30_000 ,
42+ staleTime : 5 * 60 * 1000 , // 5 minutes
3743 refetchOnMount : false ,
44+ refetchOnWindowFocus : false ,
3845 retry : false ,
3946 placeholderData : ( ) => {
4047 const storedChatWidth = getStoredChatWidth ( ) ;
0 commit comments