mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-09 23:16:50 +02:00
fix: memoize contact list pointer to fix $contacts alias (#25)
The $contacts alias in REQ command was broken due to an object reference issue. The contact list pointer object was being created inline on every render, causing useNostrEvent to treat it as a new pointer each time and disrupting the subscription. Now properly memoize the pointer object so it only changes when accountPubkey or needsAccount actually changes, ensuring stable subscriptions and proper contact list retrieval. Fixes the $contacts alias resolution in REQ commands. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -659,13 +659,18 @@ export default function ReqViewer({
|
||||
const activeAccount = state.activeAccount;
|
||||
const accountPubkey = activeAccount?.pubkey;
|
||||
|
||||
// Fetch contact list (kind 3) if needed for $contacts resolution
|
||||
const contactListEvent = useNostrEvent(
|
||||
needsAccount && accountPubkey
|
||||
? { kind: 3, pubkey: accountPubkey, identifier: "" }
|
||||
: undefined,
|
||||
// Memoize contact list pointer to prevent unnecessary re-subscriptions
|
||||
const contactPointer = useMemo(
|
||||
() =>
|
||||
needsAccount && accountPubkey
|
||||
? { kind: 3, pubkey: accountPubkey, identifier: "" }
|
||||
: undefined,
|
||||
[needsAccount, accountPubkey],
|
||||
);
|
||||
|
||||
// Fetch contact list (kind 3) if needed for $contacts resolution
|
||||
const contactListEvent = useNostrEvent(contactPointer);
|
||||
|
||||
// Extract contacts from kind 3 event (memoized to prevent unnecessary recalculation)
|
||||
const contacts = useMemo(
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user