diff --git a/src/hooks/useMarkdownToHTML.ts b/src/hooks/useMarkdownToHTML.ts index 95b5977c..6afb4e99 100644 --- a/src/hooks/useMarkdownToHTML.ts +++ b/src/hooks/useMarkdownToHTML.ts @@ -61,14 +61,12 @@ export const useMarkdownToHTML = ( setProcessedMarkdown('') if (!markdown) { - console.log(`[markdown-to-html] No markdown provided`) return } let isCancelled = false const processMarkdown = () => { - console.log(`[markdown-to-html] Processing markdown with ${profileLabels.size} profile labels`) try { // Replace nostr URIs with profile labels (progressive) and article titles const processed = replaceNostrUrisInMarkdownWithProfileLabels( @@ -79,7 +77,6 @@ export const useMarkdownToHTML = ( if (isCancelled) return - console.log(`[markdown-to-html] Markdown processed, length: ${processed.length}`) setProcessedMarkdown(processed) } catch (error) { console.error(`[markdown-to-html] Error processing markdown:`, error) diff --git a/src/hooks/useProfileLabels.ts b/src/hooks/useProfileLabels.ts index fbb3cecc..dc55c4eb 100644 --- a/src/hooks/useProfileLabels.ts +++ b/src/hooks/useProfileLabels.ts @@ -33,7 +33,6 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): // Ignore errors, continue processing other pointers } }) - console.log(`[profile-labels] Extracted ${result.length} profile identifiers from content:`, result.map(r => ({ encoded: r.encoded.slice(0, 20) + '...', pubkey: r.pubkey.slice(0, 16) + '...' }))) return result } catch (error) { console.warn(`[profile-labels] Error extracting profile pointers:`, error) @@ -44,13 +43,11 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): // Initialize labels synchronously from cache on first render to avoid delay const initialLabels = useMemo(() => { if (profileData.length === 0) { - console.log(`[profile-labels] No profile data, returning empty labels`) return new Map() } const allPubkeys = profileData.map(({ pubkey }) => pubkey) const cachedProfiles = loadCachedProfiles(allPubkeys) - console.log(`[profile-labels] Loaded ${cachedProfiles.size} cached profiles out of ${allPubkeys.length} requested`) const labels = new Map() profileData.forEach(({ encoded, pubkey }) => { @@ -61,12 +58,10 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): const displayName = profileData.display_name || profileData.name || profileData.nip05 if (displayName) { labels.set(encoded, `@${displayName}`) - console.log(`[profile-labels] Found cached name for ${encoded.slice(0, 20)}...: ${displayName}`) } else { // Use fallback npub display if profile has no name const fallback = getNpubFallbackDisplay(pubkey) labels.set(encoded, fallback) - console.log(`[profile-labels] Cached profile for ${encoded.slice(0, 20)}... has no name, using fallback: ${fallback}`) } } catch (error) { // Use fallback npub display if parsing fails @@ -74,12 +69,9 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): labels.set(encoded, fallback) console.warn(`[profile-labels] Error parsing cached profile for ${encoded.slice(0, 20)}..., using fallback:`, error) } - } else { - console.log(`[profile-labels] No cached profile for ${encoded.slice(0, 20)}... (pubkey: ${pubkey.slice(0, 16)}...)`) } }) - console.log(`[profile-labels] Initial labels from cache:`, Array.from(labels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label }))) return labels }, [profileData]) @@ -155,11 +147,9 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): const pubkeysToFetch: string[] = [] - console.log(`[profile-labels] Checking eventStore for ${profileData.length} profiles`) profileData.forEach(({ encoded, pubkey }) => { // Skip if already resolved from initial cache if (labels.has(encoded)) { - console.log(`[profile-labels] Skipping ${encoded.slice(0, 20)}..., already has label from cache`) return } @@ -169,12 +159,7 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): const eventStoreProfile = eventStore.getEvent(pubkey + ':0') if (eventStoreProfile) { profileEvent = eventStoreProfile - console.log(`[profile-labels] Found profile in eventStore for ${encoded.slice(0, 20)}...`) - } else { - console.log(`[profile-labels] Profile not in eventStore for ${encoded.slice(0, 20)}... (pubkey: ${pubkey.slice(0, 16)}...)`) } - } else { - console.log(`[profile-labels] No eventStore available`) } if (profileEvent) { @@ -183,12 +168,10 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): const displayName = profileData.display_name || profileData.name || profileData.nip05 if (displayName) { labels.set(encoded, `@${displayName}`) - console.log(`[profile-labels] Set label from eventStore for ${encoded.slice(0, 20)}...: @${displayName}`) } else { // Use fallback npub display if profile has no name const fallback = getNpubFallbackDisplay(pubkey) labels.set(encoded, fallback) - console.log(`[profile-labels] Profile in eventStore for ${encoded.slice(0, 20)}... has no name, using fallback: ${fallback}`) } } catch (error) { // Use fallback npub display if parsing fails @@ -199,7 +182,6 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): } else { // No profile found yet, will use fallback after fetch or keep empty // We'll set fallback labels for missing profiles at the end - console.log(`[profile-labels] Adding ${encoded.slice(0, 20)}... to fetch queue`) pubkeysToFetch.push(pubkey) } }) @@ -209,12 +191,9 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): if (!labels.has(encoded)) { const fallback = getNpubFallbackDisplay(pubkey) labels.set(encoded, fallback) - console.log(`[profile-labels] Setting fallback label for ${encoded.slice(0, 20)}...: ${fallback}`) } }) - console.log(`[profile-labels] Labels after checking cache and eventStore:`, Array.from(labels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label }))) - console.log(`[profile-labels] Profiles to fetch: ${pubkeysToFetch.length}`, pubkeysToFetch.map(p => p.slice(0, 16) + '...')) setProfileLabels(new Map(labels)) // Fetch missing profiles asynchronously with reactive updates @@ -228,9 +207,6 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): } }) - console.log(`[profile-labels] Fetching ${pubkeysToFetch.length} profiles from relays`) - console.log(`[profile-labels] Calling fetchProfiles with relayPool and ${pubkeysToFetch.length} pubkeys`) - // Capture refs at effect level for cleanup function const currentPendingUpdatesRef = pendingUpdatesRef const currentRafScheduledRef = rafScheduledRef @@ -239,12 +215,9 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): const handleProfileEvent = (event: NostrEvent) => { const encoded = pubkeyToEncoded.get(event.pubkey) if (!encoded) { - console.log(`[profile-labels] Received profile for unknown pubkey ${event.pubkey.slice(0, 16)}..., skipping`) return } - console.log(`[profile-labels] Received profile event for ${encoded.slice(0, 20)}...`) - // Determine the label for this profile let label: string try { @@ -252,11 +225,9 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): const displayName = profileData.display_name || profileData.name || profileData.nip05 if (displayName) { label = `@${displayName}` - console.log(`[profile-labels] Updated label reactively for ${encoded.slice(0, 20)}... to @${displayName}`) } else { // Use fallback npub display if profile has no name label = getNpubFallbackDisplay(event.pubkey) - console.log(`[profile-labels] Profile for ${encoded.slice(0, 20)}... has no name, keeping fallback: ${label}`) } } catch (error) { // Use fallback npub display if parsing fails @@ -292,8 +263,6 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): fetchProfiles(relayPool, eventStore as unknown as IEventStore, pubkeysToFetch, undefined, handleProfileEvent) .then((fetchedProfiles) => { - console.log(`[profile-labels] Fetch completed (EOSE), received ${fetchedProfiles.length} profiles total`) - // Ensure any pending batched updates are applied immediately after EOSE // This ensures all profile updates are applied even if RAF hasn't fired yet const pendingUpdates = currentPendingUpdatesRef.current @@ -313,16 +282,8 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): updatedLabels.set(encoded, label) } pendingUpdates.clear() - console.log(`[profile-labels] Flushed ${pendingCount} pending updates after EOSE`) - console.log(`[profile-labels] Final labels after EOSE:`, Array.from(updatedLabels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label }))) return updatedLabels }) - } else { - // No pending updates, just log final state - setProfileLabels(prevLabels => { - console.log(`[profile-labels] Final labels after EOSE:`, Array.from(prevLabels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label }))) - return prevLabels - }) } }) .catch((error) => { @@ -359,14 +320,6 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null): // Clear using captured reference to avoid linter warning pendingUpdates.clear() } - } else { - if (pubkeysToFetch.length === 0) { - console.log(`[profile-labels] No profiles to fetch`) - } else if (!relayPool) { - console.log(`[profile-labels] No relayPool available, cannot fetch profiles`) - } else if (!eventStore) { - console.log(`[profile-labels] No eventStore available, cannot fetch profiles`) - } } }, [profileData, eventStore, relayPool, initialLabels]) diff --git a/src/services/profileService.ts b/src/services/profileService.ts index 04722016..94e8d587 100644 --- a/src/services/profileService.ts +++ b/src/services/profileService.ts @@ -195,12 +195,10 @@ export const fetchProfiles = async ( ): Promise => { try { if (pubkeys.length === 0) { - console.log(`[fetch-profiles] No pubkeys provided`) return [] } const uniquePubkeys = Array.from(new Set(pubkeys)) - console.log(`[fetch-profiles] Requested ${pubkeys.length} profiles (${uniquePubkeys.length} unique)`) // First, check localStorage cache for all requested profiles const cachedProfiles = loadCachedProfiles(uniquePubkeys) @@ -213,16 +211,11 @@ export const fetchProfiles = async ( eventStore.add(profile) } - console.log(`[fetch-profiles] Found ${cachedProfiles.size} profiles in cache`) - // Determine which pubkeys need to be fetched from relays const pubkeysToFetch = uniquePubkeys.filter(pubkey => !cachedProfiles.has(pubkey)) - console.log(`[fetch-profiles] Need to fetch ${pubkeysToFetch.length} profiles from relays`) - // If all profiles are cached, return early if (pubkeysToFetch.length === 0) { - console.log(`[fetch-profiles] All profiles cached, returning ${profilesByPubkey.size} profiles`) return Array.from(profilesByPubkey.values()) } @@ -230,9 +223,6 @@ export const fetchProfiles = async ( const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url) const prioritized = prioritizeLocalRelays(relayUrls) const { local: localRelays, remote: remoteRelays } = partitionRelays(prioritized) - - console.log(`[fetch-profiles] Querying ${localRelays.length} local relays and ${remoteRelays.length} remote relays`) - console.log(`[fetch-profiles] Active relays:`, relayUrls) const hasPurplePages = relayUrls.some(url => url.includes('purplepag.es')) if (!hasPurplePages) { console.warn(`[fetch-profiles] purplepag.es not in active relay pool, adding it temporarily`) @@ -259,9 +249,6 @@ export const fetchProfiles = async ( eventStore.add(event) // Cache to localStorage for future use cacheProfile(event) - console.log(`[fetch-profiles] Received profile for ${event.pubkey.slice(0, 16)}... (event #${eventCount})`) - } else { - console.log(`[fetch-profiles] Received older profile for ${event.pubkey.slice(0, 16)}..., keeping existing`) } } @@ -291,12 +278,10 @@ export const fetchProfiles = async ( const profiles = Array.from(profilesByPubkey.values()) - console.log(`[fetch-profiles] Fetch completed: received ${eventCount} events, ${fetchedPubkeys.size} unique profiles`) const missingPubkeys = pubkeysToFetch.filter(p => !fetchedPubkeys.has(p)) if (missingPubkeys.length > 0) { console.warn(`[fetch-profiles] ${missingPubkeys.length} profiles not found on relays:`, missingPubkeys.map(p => p.slice(0, 16) + '...')) } - console.log(`[fetch-profiles] Returning ${profiles.length} total profiles (${cachedProfiles.size} cached + ${fetchedPubkeys.size} fetched)`) // Note: We don't preload all profile images here to avoid ERR_INSUFFICIENT_RESOURCES // Profile images will be cached by Service Worker when they're actually displayed. diff --git a/src/utils/nostrUriResolver.tsx b/src/utils/nostrUriResolver.tsx index 57a95204..8d9775ad 100644 --- a/src/utils/nostrUriResolver.tsx +++ b/src/utils/nostrUriResolver.tsx @@ -315,14 +315,12 @@ export function replaceNostrUrisInMarkdownWithProfileLabels( profileLabels: Map = new Map(), articleTitles: Map = new Map() ): string { - console.log(`[markdown-replace] Replacing URIs with ${profileLabels.size} profile labels and ${articleTitles.size} article titles`) return replaceNostrUrisSafely(markdown, (encoded) => { const link = createNostrLink(encoded) // Check if we have a resolved profile name if (profileLabels.has(encoded)) { const displayName = profileLabels.get(encoded)! - console.log(`[markdown-replace] Using profile label for ${encoded.slice(0, 20)}...: ${displayName}`) return `[${displayName}](${link})` } @@ -331,7 +329,6 @@ export function replaceNostrUrisInMarkdownWithProfileLabels( const decoded = decode(encoded) if (decoded.type === 'naddr' && articleTitles.has(encoded)) { const title = articleTitles.get(encoded)! - console.log(`[markdown-replace] Using article title for ${encoded.slice(0, 20)}...: ${title}`) return `[${title}](${link})` } } catch (error) { @@ -340,7 +337,6 @@ export function replaceNostrUrisInMarkdownWithProfileLabels( // For other types or if not resolved, use default label (shortened npub format) const label = getNostrUriLabel(encoded) - console.log(`[markdown-replace] Using default label for ${encoded.slice(0, 20)}...: ${label}`) return `[${label}](${link})` }) }