From 7b4fc58d2522d6c565cac9c76224865536ee5d8b Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Tue, 2 Dec 2025 22:38:35 +0100 Subject: [PATCH] feat: Migrate favorites state management from Recoil to Jotai --- client/src/hooks/useFavorites.ts | 6 +++--- client/src/store/favorites.ts | 14 +++++--------- client/src/store/index.ts | 3 +-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/client/src/hooks/useFavorites.ts b/client/src/hooks/useFavorites.ts index 3decc8ef33..18ee25f429 100644 --- a/client/src/hooks/useFavorites.ts +++ b/client/src/hooks/useFavorites.ts @@ -1,11 +1,11 @@ import { useEffect, useCallback } from 'react'; -import { useRecoilState } from 'recoil'; +import { useAtom } from 'jotai'; import { useToastContext } from '@librechat/client'; import type { Favorite } from '~/store/favorites'; import { useGetFavoritesQuery, useUpdateFavoritesMutation } from '~/data-provider'; +import { favoritesAtom } from '~/store'; import { useLocalize } from '~/hooks'; import { logger } from '~/utils'; -import store from '~/store'; /** * Hook for managing user favorites (pinned agents and models). @@ -36,7 +36,7 @@ const cleanFavorites = (favorites: Favorite[]): Favorite[] => export default function useFavorites() { const localize = useLocalize(); const { showToast } = useToastContext(); - const [favorites, setFavorites] = useRecoilState(store.favorites); + const [favorites, setFavorites] = useAtom(favoritesAtom); const getFavoritesQuery = useGetFavoritesQuery(); const updateFavoritesMutation = useUpdateFavoritesMutation(); diff --git a/client/src/store/favorites.ts b/client/src/store/favorites.ts index feb1832263..b3744f52b0 100644 --- a/client/src/store/favorites.ts +++ b/client/src/store/favorites.ts @@ -1,4 +1,4 @@ -import { atom } from 'recoil'; +import { createStorageAtom } from './jotai-utils'; export type Favorite = { agentId?: string; @@ -13,11 +13,7 @@ export type FavoriteModel = { export type FavoritesState = Favorite[]; -const favorites = atom({ - key: 'favorites', - default: [], -}); - -export default { - favorites, -}; +/** + * This atom stores the user's favorite models/agents + */ +export const favoritesAtom = createStorageAtom('favorites', []); diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 31f22e70a4..25d721e65b 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -12,9 +12,9 @@ import lang from './language'; import settings from './settings'; import misc from './misc'; import isTemporary from './temporary'; -import favorites from './favorites'; export * from './agents'; export * from './mcp'; +export * from './favorites'; export default { ...artifacts, @@ -31,5 +31,4 @@ export default { ...settings, ...misc, ...isTemporary, - ...favorites, };