Increase timeout for parent event fetching in reply detail view
- Add optional timeout parameter to useEvent hook (defaults to 5000ms) - Set 30-second timeout for parent event fetch in ParentNote component - Ensures parent events load reliably even on slow relays Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
+14
-3
@@ -2,17 +2,28 @@ import { useNostr } from '@nostrify/react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { NostrEvent } from '@nostrify/nostrify';
|
||||
|
||||
/** Options for fetching a single event. */
|
||||
export interface UseEventOptions {
|
||||
/** Timeout in milliseconds. Use 0 or undefined for no timeout. Defaults to 5000ms. */
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
/** Fetches a single Nostr event by its hex ID. */
|
||||
export function useEvent(eventId: string | undefined) {
|
||||
export function useEvent(eventId: string | undefined, options?: UseEventOptions) {
|
||||
const { nostr } = useNostr();
|
||||
const timeout = options?.timeout ?? 5000;
|
||||
|
||||
return useQuery<NostrEvent | null>({
|
||||
queryKey: ['event', eventId ?? ''],
|
||||
queryKey: ['event', eventId ?? '', timeout],
|
||||
queryFn: async ({ signal }) => {
|
||||
if (!eventId) return null;
|
||||
const abortSignals = [signal];
|
||||
if (timeout > 0) {
|
||||
abortSignals.push(AbortSignal.timeout(timeout));
|
||||
}
|
||||
const events = await nostr.query(
|
||||
[{ ids: [eventId], limit: 1 }],
|
||||
{ signal: AbortSignal.any([signal, AbortSignal.timeout(5000)]) },
|
||||
{ signal: AbortSignal.any(abortSignals) },
|
||||
);
|
||||
return events[0] ?? null;
|
||||
},
|
||||
|
||||
@@ -451,7 +451,8 @@ function PostDetailContent({ event }: { event: NostrEvent }) {
|
||||
/** Renders the parent event that this reply is responding to. */
|
||||
function ParentNote({ eventId }: { eventId: string }) {
|
||||
const navigate = useNavigate();
|
||||
const { data: event, isLoading } = useEvent(eventId);
|
||||
// Use a 30-second timeout for parent events to ensure they load even on slow relays
|
||||
const { data: event, isLoading } = useEvent(eventId, { timeout: 30000 });
|
||||
const author = useAuthor(event?.pubkey);
|
||||
const metadata = author.data?.metadata;
|
||||
const displayName = event ? (metadata?.name || genUserName(event.pubkey)) : '';
|
||||
|
||||
Reference in New Issue
Block a user