[APP-2160] Address /grill review: move logger.error to useEffect; guard readingTime > 0

- PublicationFooter: profile-resolve error was logged during render, causing
  duplicate Sentry events on every re-render of an errored card. Move to
  useEffect keyed on the error transition.
- MetaRow: render reading-time chip only when readingTime > 0. Guards against
  pathological appview responses where the field is 0 or negative.
This commit is contained in:
vineyardbovines
2026-05-12 14:31:39 -04:00
committed by Eric Bailey
parent c418f7a3df
commit 1adfdb4a15
2 changed files with 13 additions and 10 deletions
@@ -44,7 +44,7 @@ export function MetaRow({link}: {link: PublicationViewExternal}) {
the URL). Component exists below for the moment that field lands.
*/}
{/* <SharesChip count={???} /> */}
{typeof link.readingTime === 'number' && (
{typeof link.readingTime === 'number' && link.readingTime > 0 && (
<ReadingTimeChip minutes={link.readingTime} />
)}
</View>
@@ -1,3 +1,4 @@
import {useEffect} from 'react'
import {View} from 'react-native'
import {Trans, useLingui} from '@lingui/react/macro'
@@ -21,15 +22,17 @@ export function PublicationFooter({
const did = parseDidFromAtUri(source.associatedRecord?.uri)
const profileQuery = useProfileQuery({did: did ?? undefined})
if (profileQuery.error && did) {
// Sweep finding: silence non-actionable network errors here. We use
// `logger.error` only when the DID was present and the lookup failed for
// a non-network reason; React Query already handles transient network
// failures with its built-in retry. This keeps Sentry quiet on broken DIDs.
logger.error('PublicationEmbed handle resolve failed', {
safeMessage: profileQuery.error,
})
}
const profileError = profileQuery.error
useEffect(() => {
if (profileError && did) {
// Log once per error transition. React Query handles transient network
// failures via retry; once the error is set we don't want to re-log on
// every render (could burn Sentry quota with a feed of broken DIDs).
logger.error('PublicationEmbed handle resolve failed', {
safeMessage: profileError,
})
}
}, [profileError, did])
const handle = did ? profileQuery.data?.handle : undefined
const name = source.name || (source.uri ? toNiceDomain(source.uri) : '')