File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use client'
22
3- import { useState } from 'react'
3+ import { useCallback , useState } from 'react'
44import { MissingAvatar } from './MissingAvatar'
55
66interface SpeakerAvatarImageProps {
@@ -20,6 +20,14 @@ export function SpeakerAvatarImage({
2020} : SpeakerAvatarImageProps ) {
2121 const [ failed , setFailed ] = useState ( false )
2222
23+ // Callback ref detects images that already failed before React hydration
24+ // attached the onError handler (e.g. broken URLs on slow connections).
25+ const imgRef = useCallback ( ( img : HTMLImageElement | null ) => {
26+ if ( img ?. complete && img . naturalWidth === 0 ) {
27+ setFailed ( true )
28+ }
29+ } , [ ] )
30+
2331 if ( failed ) {
2432 return (
2533 < MissingAvatar
@@ -33,6 +41,7 @@ export function SpeakerAvatarImage({
3341
3442 return (
3543 < img
44+ ref = { imgRef }
3645 src = { src }
3746 alt = { name }
3847 className = { `${ className } h-full w-full object-cover object-center` }
You can’t perform that action at this time.
0 commit comments