fix: enhance image loading logic to handle static paths when sockets are unavailable
This commit is contained in:
@@ -52,9 +52,14 @@ class Images extends Component {
|
|||||||
pics.push(bildId);
|
pics.push(bildId);
|
||||||
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
||||||
}else{
|
}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);
|
pics.push(bildId);
|
||||||
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
if(window.tinyPicCache[bildId]){
|
if(window.tinyPicCache[bildId]){
|
||||||
pics.push(window.tinyPicCache[bildId]);
|
pics.push(window.tinyPicCache[bildId]);
|
||||||
@@ -62,11 +67,16 @@ class Images extends Component {
|
|||||||
pics.push(window.mediumPicCache[bildId]);
|
pics.push(window.mediumPicCache[bildId]);
|
||||||
this.loadPic('tiny',bildId,newMainPic);
|
this.loadPic('tiny',bildId,newMainPic);
|
||||||
}else{
|
}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);
|
pics.push(null);
|
||||||
this.loadPic('tiny',bildId,pics.length-1);
|
this.loadPic('tiny',bildId,pics.length-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
console.log('pics',pics);
|
console.log('pics',pics);
|
||||||
this.setState({ pics, mainPic: newMainPic });
|
this.setState({ pics, mainPic: newMainPic });
|
||||||
}else{
|
}else{
|
||||||
@@ -75,6 +85,9 @@ class Images extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPic = (size,bildId,index) => {
|
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) => {
|
this.props.socketB.emit('getPic', { bildId, size }, (res) => {
|
||||||
if(res.success){
|
if(res.success){
|
||||||
const url = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' }));
|
const url = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' }));
|
||||||
|
|||||||
Reference in New Issue
Block a user