fix: add SSR guards to localStorage/sessionStorage access

- Add window check to getInitialColumnVisibility in transaction-list.tsx
- Add window check to getInitialColumnVisibility in transactions/index.tsx
- Add SSR guards to balance-import-config-storage.ts functions
- Add SSR guards to import-config-storage.ts functions
- Add SSR guards to use-appearance.tsx functions
This commit is contained in:
Víctor Falcón 2025-12-08 18:19:20 +01:00
parent aaaba66684
commit 3b56e24447
5 changed files with 26 additions and 0 deletions

View File

@ -146,6 +146,10 @@ function TransactionRowComponent({
}
function getInitialColumnVisibility(): VisibilityState {
if (typeof window === 'undefined') {
return { account: false };
}
try {
const stored = localStorage.getItem(COLUMN_VISIBILITY_KEY);
if (stored) {

View File

@ -20,6 +20,8 @@ const setCookie = (name: string, value: string, days = 365) => {
};
const applyTheme = (appearance: Appearance) => {
if (typeof document === 'undefined') return;
const isDark =
appearance === 'dark' || (appearance === 'system' && prefersDark());
@ -36,11 +38,15 @@ const mediaQuery = () => {
};
const handleSystemThemeChange = () => {
if (typeof window === 'undefined') return;
const currentAppearance = localStorage.getItem('appearance') as Appearance;
applyTheme(currentAppearance || 'system');
};
export function initializeTheme() {
if (typeof window === 'undefined') return;
const savedAppearance =
(localStorage.getItem('appearance') as Appearance) || 'system';

View File

@ -13,6 +13,8 @@ export function saveBalanceImportConfig(
accountId: UUID,
config: BalanceImportConfig,
): void {
if (typeof window === 'undefined') return;
try {
const key = `${STORAGE_KEY_PREFIX}${accountId}`;
localStorage.setItem(key, JSON.stringify(config));
@ -24,6 +26,8 @@ export function saveBalanceImportConfig(
export function loadBalanceImportConfig(
accountId: UUID,
): BalanceImportConfig | null {
if (typeof window === 'undefined') return null;
try {
const key = `${STORAGE_KEY_PREFIX}${accountId}`;
const stored = localStorage.getItem(key);
@ -46,6 +50,8 @@ export function loadBalanceImportConfig(
}
export function clearBalanceImportConfig(accountId: UUID): void {
if (typeof window === 'undefined') return;
try {
const key = `${STORAGE_KEY_PREFIX}${accountId}`;
localStorage.removeItem(key);

View File

@ -11,6 +11,8 @@ export function saveImportConfig(
accountId: number,
config: ImportConfig,
): void {
if (typeof window === 'undefined') return;
try {
const key = `${STORAGE_KEY_PREFIX}${accountId}`;
localStorage.setItem(key, JSON.stringify(config));
@ -20,6 +22,8 @@ export function saveImportConfig(
}
export function loadImportConfig(accountId: number): ImportConfig | null {
if (typeof window === 'undefined') return null;
try {
const key = `${STORAGE_KEY_PREFIX}${accountId}`;
const stored = localStorage.getItem(key);
@ -42,6 +46,8 @@ export function loadImportConfig(accountId: number): ImportConfig | null {
}
export function clearImportConfig(accountId: number): void {
if (typeof window === 'undefined') return;
try {
const key = `${STORAGE_KEY_PREFIX}${accountId}`;
localStorage.removeItem(key);

View File

@ -157,6 +157,10 @@ function TransactionRowComponent({
}
function getInitialColumnVisibility(): VisibilityState {
if (typeof window === 'undefined') {
return { account: false };
}
try {
const stored = localStorage.getItem(COLUMN_VISIBILITY_KEY);
if (stored) {