fix: prevent duplicate highlights and remove excessive logging

- Add deduplication when adding highlights via onHighlightCreated
- Remove excessive UI logging that was causing performance issues
- Fixes duplicate highlight warning and improves render performance
This commit is contained in:
Gigi
2025-10-30 21:29:35 +01:00
parent deab9974fa
commit 2a869f11e0
2 changed files with 9 additions and 25 deletions

View File

@@ -229,7 +229,14 @@ const Bookmarks: React.FC<BookmarksProps> = ({
currentArticle,
selectedUrl,
readerContent,
onHighlightCreated: (highlight) => setHighlights(prev => [highlight, ...prev]),
onHighlightCreated: (highlight) => setHighlights(prev => {
// Deduplicate by checking if highlight with this ID already exists
const exists = prev.some(h => h.id === highlight.id)
if (exists) {
return prev // Don't add duplicate
}
return [highlight, ...prev]
}),
settings
})

View File

@@ -310,39 +310,16 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
const isLocalOnly = highlight.isLocalOnly
const publishedRelays = highlight.publishedRelays || []
// Only log when values are meaningful (not undefined/empty) to reduce spam
if (isLocalOnly !== undefined || publishedRelays.length > 0) {
console.log('🎯 [HIGHLIGHT-UI] Rendering highlight relay indicator:', {
highlightId: highlight.id,
isLocalOnly: isLocalOnly,
publishedRelays: publishedRelays,
publishedRelayCount: publishedRelays.length,
willShowAirplaneIcon: isLocalOnly
})
}
// Show highlighter icon with relay info if available
if (highlight.publishedRelays && highlight.publishedRelays.length > 0) {
const relayNames = highlight.publishedRelays.map(url =>
url.replace(/^wss?:\/\//, '').replace(/\/$/, '')
)
const iconInfo = {
return {
icon: isLocalOnly ? faPlane : faHighlighter,
tooltip: isLocalOnly ? 'Local relays only - will sync when remote relays available' : relayNames.join('\n'),
spin: false
}
console.log('🔍 [HIGHLIGHT-UI] Icon decision made:', {
highlightId: highlight.id,
isLocalOnly: isLocalOnly,
iconType: isLocalOnly ? 'airplane' : 'highlighter',
tooltip: iconInfo.tooltip,
actualPublishedRelaysInUI: publishedRelays,
relayNames: relayNames,
conditionResult: isLocalOnly ? 'SHOULD_SHOW_AIRPLANE' : 'SHOULD_SHOW_HIGHLIGHTER'
})
return iconInfo
}
if (highlight.seenOnRelays && highlight.seenOnRelays.length > 0) {