debug: add detailed logs to nostr URI resolver for loading state detection

- Log when replacement function is called with Map sizes
- Log all loading keys in the Map
- Log detailed info for each npub/nprofile found: type, hasLoading, isLoading
- Will help identify if encoded IDs don't match or loading state isn't detected
This commit is contained in:
Gigi
2025-11-02 22:47:43 +01:00
parent 7ec87b66d8
commit 8f1288b1a2

View File

@@ -320,6 +320,9 @@ export function replaceNostrUrisInMarkdownWithProfileLabels(
articleTitles: Map<string, string> = new Map(),
profileLoading: Map<string, boolean> = new Map()
): string {
console.log(`[profile-loading-debug][nostr-uri-resolve] Processing markdown, profileLabels=${profileLabels.size}, profileLoading=${profileLoading.size}`)
console.log(`[profile-loading-debug][nostr-uri-resolve] Loading keys:`, Array.from(profileLoading.entries()).filter(([, l]) => l).map(([k]) => k.slice(0, 16) + '...'))
return replaceNostrUrisSafely(markdown, (encoded) => {
const link = createNostrLink(encoded)
@@ -338,11 +341,17 @@ export function replaceNostrUrisInMarkdownWithProfileLabels(
}
// For npub/nprofile, check if loading and show loading state
if ((decoded.type === 'npub' || decoded.type === 'nprofile') && profileLoading.has(encoded) && profileLoading.get(encoded)) {
const label = getNostrUriLabel(encoded)
console.log(`[profile-loading-debug][nostr-uri-resolve] ${encoded.slice(0, 16)}... is LOADING, showing loading state`)
// Wrap in span with profile-loading class for CSS styling
return `[<span class="profile-loading">${label}</span>](${link})`
if (decoded.type === 'npub' || decoded.type === 'nprofile') {
const hasLoading = profileLoading.has(encoded)
const isLoading = profileLoading.get(encoded)
console.log(`[profile-loading-debug][nostr-uri-resolve] ${encoded.slice(0, 16)}... type=${decoded.type}, hasLoading=${hasLoading}, isLoading=${isLoading}`)
if (hasLoading && isLoading) {
const label = getNostrUriLabel(encoded)
console.log(`[profile-loading-debug][nostr-uri-resolve] ${encoded.slice(0, 16)}... is LOADING, showing loading state`)
// Wrap in span with profile-loading class for CSS styling
return `[<span class="profile-loading">${label}</span>](${link})`
}
}
} catch (error) {
// Ignore decode errors, fall through to default label