@@ -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 ;
@@ -84,17 +98,30 @@ export default function ViewPage() {
8498 const isDebug = ( searchParams . get ( "debug" ) || "0" ) === "1" ;
8599
86100 const onImageLoad = useCallback ( ( ) => {
87- console . log (
88- `onload: ${ imageRef . current ?. naturalWidth } , ${ imageRef . current ?. naturalHeight } `
89- ) ;
101+ console . log ( "via onImageLoad" ) ;
102+ logImageElement ( imageRef . current ) ;
103+
90104 setLoading ( false ) ;
91105 setNaturalWidth ( imageRef . current ?. naturalWidth || 1 ) ;
92106 setNaturalHeight ( imageRef . current ?. naturalHeight || 1 ) ;
93107 setImageDisplay ( "flex" ) ;
94108 } , [ ] ) ;
95109
96- const onImageError = useCallback ( ( ) => {
97- console . log ( "onerror" ) ;
110+ const onSizeZero = useCallback ( ( ) => {
111+ console . log ( "via onSizeZero" ) ;
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 ( "via onImageError" , err ) ;
123+ logImageElement ( imageRef . current ) ;
124+
98125 setLoading ( false ) ;
99126 setLoadErr ( { } ) ;
100127 } , [ ] ) ;
@@ -108,15 +135,15 @@ export default function ViewPage() {
108135 } , [ ] ) ;
109136
110137 useEffect ( ( ) => {
138+ console . log ( "via useEffect" ) ;
111139 if ( imageRef . current ?. complete ) {
112140 if ( imageRef . current ?. naturalWidth === 0 ) {
113- onImageError ( ) ;
141+ onSizeZero ( ) ;
114142 } else {
115143 onImageLoad ( ) ;
116144 }
117- console . log ( "via useEffect" ) ;
118145 }
119- } , [ onImageError , onImageLoad ] ) ;
146+ } , [ onImageError , onImageLoad , onSizeZero ] ) ;
120147
121148 useEffect ( ( ) => {
122149 function handleResize ( ) {
@@ -174,10 +201,10 @@ export default function ViewPage() {
174201 >
175202 < img
176203 alt = { `${ url } (preload/debug)` }
177- onError = { ( ) => {
178- onImageError ( ) ;
179- console . log ( "via onError" ) ;
204+ onError = { ( evt ) => {
205+ onImageError ( evt ) ;
180206 } }
207+ crossOrigin = "anonymous"
181208 onLoad = { ( ) => {
182209 onImageLoad ( ) ;
183210 console . log ( "via onLoad" ) ;
0 commit comments