debug: add logs to trace profile labels batching

- Add debug logs in applyPendingUpdates to see when updates are applied
- Add debug logs in scheduleBatchedUpdate to track RAF scheduling
- Add debug logs when adding to pending updates
- Add debug logs for profileLabelsKey computation to verify state updates
- Will help diagnose why profileLabels stays at size 0 despite profiles resolving
This commit is contained in:
Gigi
2025-11-02 23:03:33 +01:00
parent 541d30764e
commit 4a432bac8d
2 changed files with 22 additions and 4 deletions

View File

@@ -27,7 +27,12 @@ export const useMarkdownToHTML = (
// Create stable dependencies based on Map contents, not Map objects
// This prevents unnecessary reprocessing when Maps are recreated with same content
const profileLabelsKey = useMemo(() => {
return Array.from(profileLabels.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join('|')
const key = Array.from(profileLabels.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join('|')
console.log(`[shimmer-debug][markdown-to-html] profileLabelsKey computed, profileLabels.size=${profileLabels.size}, key length=${key.length}`)
if (profileLabels.size > 0) {
console.log(`[shimmer-debug][markdown-to-html] Profile labels in key:`, Array.from(profileLabels.entries()).slice(0, 3).map(([k, v]) => `${k.slice(0, 16)}...="${v}"`))
}
return key
}, [profileLabels])
const profileLoadingKey = useMemo(() => {

View File

@@ -89,7 +89,11 @@ export function useProfileLabels(
*/
const applyPendingUpdates = () => {
const pendingUpdates = pendingUpdatesRef.current
if (pendingUpdates.size === 0) return
console.log(`[shimmer-debug][profile-labels] applyPendingUpdates called, pendingUpdates.size=${pendingUpdates.size}`)
if (pendingUpdates.size === 0) {
console.log(`[shimmer-debug][profile-labels] No pending updates to apply`)
return
}
// Cancel scheduled RAF since we're applying synchronously
if (rafScheduledRef.current !== null) {
@@ -100,9 +104,13 @@ export function useProfileLabels(
// Apply all pending updates in one batch
setProfileLabels(prevLabels => {
const updatedLabels = new Map(prevLabels)
for (const [encoded, label] of pendingUpdates.entries()) {
updatedLabels.set(encoded, label)
const updatesList: string[] = []
for (const [pubkey, label] of pendingUpdates.entries()) {
updatedLabels.set(pubkey, label)
updatesList.push(`${pubkey.slice(0, 16)}...="${label}"`)
}
console.log(`[shimmer-debug][profile-labels] Applying ${updatesList.length} pending updates:`, updatesList)
console.log(`[shimmer-debug][profile-labels] Profile labels before: ${prevLabels.size}, after: ${updatedLabels.size}`)
pendingUpdates.clear()
return updatedLabels
})
@@ -115,10 +123,14 @@ export function useProfileLabels(
*/
const scheduleBatchedUpdate = useCallback(() => {
if (rafScheduledRef.current === null) {
console.log(`[shimmer-debug][profile-labels] Scheduling batched update via RAF`)
rafScheduledRef.current = requestAnimationFrame(() => {
console.log(`[shimmer-debug][profile-labels] RAF fired, calling applyPendingUpdates`)
applyPendingUpdates()
rafScheduledRef.current = null
})
} else {
console.log(`[shimmer-debug][profile-labels] RAF already scheduled, skipping`)
}
}, []) // Empty deps: only uses refs which are stable
@@ -265,6 +277,7 @@ export function useProfileLabels(
const label = displayName ? (displayName.startsWith('@') ? displayName : `@${displayName}`) : getNpubFallbackDisplay(pubkey)
// Add to pending updates and schedule batched application
console.log(`[shimmer-debug][profile-labels] Adding to pending updates: ${pubkey.slice(0, 16)}...="${label}", pendingUpdates.size=${pendingUpdatesRef.current.size + 1}`)
pendingUpdatesRef.current.set(pubkey, label)
scheduleBatchedUpdate()