Skip to content
Merged
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
19 changes: 17 additions & 2 deletions src/core/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,24 @@ export const saveState = (state: RootState) => {
};

export const clearSessionStorage = () => {
globalThis.sessionStorage.clear();
try {
globalThis.sessionStorage.clear();
} catch (_) { // Ignore storage errors, nothing was persisted.
}
};

export const clearApiSession = () => {
globalThis.localStorage.removeItem('apiSession');
try {
globalThis.localStorage.removeItem('apiSession');
} catch (_) { // Ignore storage errors, nothing was persisted.
}
};

// Browsers can throw on any storage access (e.g. Firefox's NS_ERROR_FAILURE when site storage is unusable).
export const getStoredTheme = () => {
try {
return globalThis.localStorage.getItem('theme');
} catch (_) {
return null;
}
};
6 changes: 2 additions & 4 deletions src/core/router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global globalThis */
import { useEffect, useRef, useState } from 'react';
import { Navigate, Route, createBrowserRouter, createRoutesFromElements } from 'react-router';
import { RouterProvider } from 'react-router/dom';
import * as Sentry from '@sentry/react';

import ErrorBoundary from '@/components/ErrorBoundary';
import ReleaseManagementSeriesDetail from '@/components/Utilities/ReleaseManagement/ReleaseManagementSeriesDetail';
import { getStoredTheme } from '@/core/localStorage';
import { useServerStatusQuery } from '@/core/react-query/init/queries';
import { useSettingsQuery } from '@/core/react-query/settings/queries';
import { useSelector } from '@/core/store';
Expand Down Expand Up @@ -164,9 +164,7 @@ const Router = () => {
const [bodyVisible, setBodyVisible] = useState(false);

useEffect(() => {
document.body.className = `${
apikey === '' ? globalThis.localStorage.getItem('theme') : (webuiPreviewTheme || theme)
} theme-shoko-gray`;
document.body.className = `${apikey === '' ? getStoredTheme() : (webuiPreviewTheme || theme)} theme-shoko-gray`;
const timeoutId = setTimeout(() => {
if (bodyRef.current) {
bodyRef.current.style.visibility = 'initial';
Expand Down
Loading