@@ -12,6 +12,21 @@ import { calcMaxZoom, calcZoomIn, calcZoomOut } from "./calcZoom";
1212import { IconList } from "./IconList" ;
1313import { keyHandler } from "./KeyHandler" ;
1414import { useColorModeValue } from "~/components/ui/color-mode" ;
15+ import { safeParseInt } from "~/utils/safeParseInt" ;
16+
17+ function logImageElement ( img : HTMLImageElement | null ) {
18+ if ( img == null ) {
19+ console . log ( "Image ref is null" ) ;
20+ return ;
21+ }
22+
23+ console . log ( `img.naturalHeight=${ img . naturalHeight } ` ) ;
24+ console . log ( `img.naturalWidth=${ img . naturalWidth } ` ) ;
25+ console . log ( `img.complete=${ img . complete } ` ) ;
26+ console . log ( `img.crossOrigin=${ img . crossOrigin } ` ) ;
27+ console . log ( `img.currentSrc=${ img . currentSrc } ` ) ;
28+ console . log ( `img.src=${ img . src } ` ) ;
29+ }
1530
1631export default function ViewPage ( ) {
1732 const [ searchParams ] = useSearchParams ( ) ;
@@ -58,7 +73,6 @@ export default function ViewPage() {
5873 background . backgroundColor = bg ;
5974 borderColor = getContrastYIQ ( bg . slice ( 1 ) ) ;
6075 } else if ( / ^ [ - a - z ] + $ / . test ( bg ) ) {
61- console . log ( `background: ${ bg } ` ) ;
6276 background . backgroundImage = `url(/images/backgrounds/${ bg } .png)` ;
6377 background . backgroundColor = defaultBorderBackgroundColor ;
6478 borderColor = defaultBorderColor ;
@@ -93,8 +107,20 @@ export default function ViewPage() {
93107 setImageDisplay ( "flex" ) ;
94108 } , [ ] ) ;
95109
96- const onImageError = useCallback ( ( ) => {
97- console . log ( "onerror" ) ;
110+ const onSizeZero = useCallback ( ( ) => {
111+ console . log ( "Image has zero natural size" ) ;
112+ logImageElement ( imageRef . current ) ;
113+
114+ setNaturalWidth ( safeParseInt ( searchParams . get ( "width" ) || "64" , 64 ) ) ;
115+ setNaturalHeight ( safeParseInt ( searchParams . get ( "height" ) || "64" , 64 ) ) ;
116+
117+ setLoading ( false ) ;
118+ setImageDisplay ( "flex" ) ;
119+ } , [ ] ) ;
120+
121+ const onImageError = useCallback ( ( err :any ) => {
122+ console . log ( "onerror" , err ) ;
123+ logImageElement ( imageRef . current ) ;
98124 setLoading ( false ) ;
99125 setLoadErr ( { } ) ;
100126 } , [ ] ) ;
@@ -110,13 +136,13 @@ export default function ViewPage() {
110136 useEffect ( ( ) => {
111137 if ( imageRef . current ?. complete ) {
112138 if ( imageRef . current ?. naturalWidth === 0 ) {
113- onImageError ( ) ;
139+ onSizeZero ( ) ;
114140 } else {
115141 onImageLoad ( ) ;
116142 }
117143 console . log ( "via useEffect" ) ;
118144 }
119- } , [ onImageError , onImageLoad ] ) ;
145+ } , [ onImageError , onImageLoad , onSizeZero ] ) ;
120146
121147 useEffect ( ( ) => {
122148 function handleResize ( ) {
@@ -174,9 +200,8 @@ export default function ViewPage() {
174200 >
175201 < img
176202 alt = { `${ url } (preload/debug)` }
177- onError = { ( ) => {
178- onImageError ( ) ;
179- console . log ( "via onError" ) ;
203+ onError = { ( evt ) => {
204+ onImageError ( evt ) ;
180205 } }
181206 onLoad = { ( ) => {
182207 onImageLoad ( ) ;
0 commit comments