fix: prevent settings from saving unnecessarily

- Wrap handleSaveSettings in useCallback to prevent recreation
- Only trigger save effect when localSettings object changes
- Remove onSave from dependency array with eslint-disable comment
- Settings now only save when user actually changes a setting
This commit is contained in:
Gigi
2025-10-05 03:56:49 +01:00
parent 89c00035a8
commit 850a4bede5
2 changed files with 5 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, useCallback } from 'react'
import { Hooks } from 'applesauce-react'
import { useEventStore } from 'applesauce-react/hooks'
import { RelayPool } from 'applesauce-relay'
@@ -114,7 +114,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
}
}
const handleSaveSettings = async (newSettings: UserSettings) => {
const handleSaveSettings = useCallback(async (newSettings: UserSettings) => {
if (!relayPool || !activeAccount) return
try {
const fullAccount = accountManager.getActive()
@@ -129,7 +129,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
setToastType('error')
setToastMessage('Failed to save settings')
}
}
}, [relayPool, activeAccount, accountManager, eventStore])
const handleSelectUrl = async (url: string) => {
setSelectedUrl(url)

View File

@@ -40,7 +40,8 @@ const Settings: React.FC<SettingsProps> = ({ settings, onSave, onClose }) => {
}
onSave(localSettings)
}, [localSettings, onSave])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [localSettings])
const previewFontFamily = getFontFamily(localSettings.readingFont)