fix: enhance image loading logic to handle static paths when sockets are unavailable

This commit is contained in:
sebseb7
2025-07-20 01:28:36 +02:00
parent ca98c304e5
commit bdd50770be

View File

@@ -51,22 +51,32 @@ class Images extends Component {
}else if(window.tinyPicCache[bildId]){
pics.push(bildId);
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
}else{
// For prerender or when sockets unavailable, use static path
if (!this.props.socket && !this.props.socketB) {
pics.push(`/assets/images/prod${bildId}.jpg`);
} else {
pics.push(bildId);
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
}
}
}else{
if(window.tinyPicCache[bildId]){
pics.push(window.tinyPicCache[bildId]);
}else if(window.mediumPicCache[bildId]){
pics.push(window.mediumPicCache[bildId]);
this.loadPic('tiny',bildId,newMainPic);
}else{
// For prerender or when sockets unavailable, use static path
if (!this.props.socket && !this.props.socketB) {
pics.push(`/assets/images/prod${bildId}.jpg`);
} else {
pics.push(null);
this.loadPic('tiny',bildId,pics.length-1);
}
}
}
}
console.log('pics',pics);
this.setState({ pics, mainPic: newMainPic });
}else{
@@ -75,6 +85,9 @@ class Images extends Component {
}
loadPic = (size,bildId,index) => {
// Skip loading if sockets are not available (e.g., during prerender)
if (!this.props.socketB) return;
this.props.socketB.emit('getPic', { bildId, size }, (res) => {
if(res.success){
const url = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' }));