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:
Alejandro
2025-12-22 23:07:04 +01:00
committed by GitHub
parent 75500fa298
commit e5a715aefe

View File

@@ -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(
() =>