feat(highlights): force synchronous render for immediate highlight display

- Use flushSync to force React to render synchronously after highlight creation
- Eliminates render cycle delay for instant visual feedback
- Highlights now appear immediately in the text when created
This commit is contained in:
Gigi
2025-10-14 00:03:56 +02:00
parent 3b639e2783
commit c7c82954ad

View File

@@ -1,4 +1,5 @@
import { useCallback, useRef } from 'react'
import { flushSync } from 'react-dom'
import { RelayPool } from 'applesauce-relay'
import { NostrEvent } from 'nostr-tools'
import { IEventStore } from 'applesauce-core'
@@ -84,7 +85,11 @@ export const useHighlightCreation = ({
}
highlightButtonRef.current?.clearSelection()
onHighlightCreated(newHighlight)
// Force synchronous render to show highlight immediately
flushSync(() => {
onHighlightCreated(newHighlight)
})
} catch (error) {
console.error('❌ Failed to create highlight:', error)
// Re-throw to allow parent to handle