Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const AppContent = (props) => {
const backHandlerRef = useRef(null);
const detailsItemStackRef = useRef([]);
const jellyseerrItemStackRef = useRef([]);

const prevUserIdRef = useRef(null);

const fetchLibraries = useCallback(async () => {
if (isAuthenticated && api && user) {
try {
Expand Down Expand Up @@ -243,6 +244,20 @@ const AppContent = (props) => {
}
}, [isAuthenticated]);

// Redirect to Browse panel on user change to reset state, prevents issues with stale data when switching accounts
useEffect(() => {
if (!isAuthenticated || !user?.Id) {
prevUserIdRef.current = null;
return;
}

if (user.Id !== prevUserIdRef.current) {
prevUserIdRef.current = user.Id;
setPanelHistory([]);
setPanelIndex(PANELS.BROWSE);
}
}, [user?.Id, isAuthenticated]);

const navigateTo = useCallback((panel, addToHistory = true) => {
if (addToHistory && panelIndex !== PANELS.LOGIN) {
setPanelHistory(prev => {
Expand Down
11 changes: 6 additions & 5 deletions src/views/Browse/Browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Browse = ({
onSelectLibrary,
isVisible = true
}) => {
const {api, serverUrl, accessToken, hasMultipleServers} = useAuth();
const {api, serverUrl, accessToken, hasMultipleServers, user} = useAuth();
const {settings} = useSettings();
const unifiedMode = settings.unifiedLibraryMode && hasMultipleServers;
const [isLoading, setIsLoading] = useState(true);
Expand Down Expand Up @@ -365,26 +365,27 @@ const Browse = ({
libraries: libs,
featuredItems: featured,
timestamp: Date.now(),
serverUrl
serverUrl,
userId: user?.Id || null
};
await saveToStorage(STORAGE_KEY_BROWSE, cacheData);
} catch (e) {
console.warn('[Browse] Failed to save cache:', e);
}
}, [serverUrl]);
}, [serverUrl, user?.Id]);

// Load browse data from persistent storage
const loadBrowseCache = useCallback(async () => {
try {
const cached = await getFromStorage(STORAGE_KEY_BROWSE);
if (cached && cached.serverUrl === serverUrl) {
if (cached && cached.serverUrl === serverUrl && cached.userId === (user?.Id || null)) {
return cached;
}
} catch (e) {
console.warn('[Browse] Failed to load cache:', e);
}
return null;
}, [serverUrl]);
}, [serverUrl, user?.Id]);

useEffect(() => {
const loadData = async () => {
Expand Down
Loading