Bug 38981

Summary: Local cover images failing to load in OPAC search results
Product: Koha Reporter: David Cook <dcook>
Component: OPACAssignee: Owen Leonard <oleonard>
Status: CONFIRMED --- QA Contact: Testopia <testopia>
Severity: blocker    
Priority: P5 - low CC: david, jonathan.druart, martin.renvoize, petr.broz
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38963
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 26933    
Bug Blocks:    

Description David Cook 2025-01-28 03:40:32 UTC
It looks like bug 26933 might've broke OPAC local cover images in the search results due to a possible race condition.

In koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt around line 630 there is a window.load() call which runs 'wait_for_images(verify_cover_images)'.

If you're only using OPACLocalCoverImages, there is no wait, so verify_cover_images() is called immediately. That function  removes the .cover-image element if there are no images.

In the case of OPACLocalCoverImages, there are no images yet, so the element gets removed.

Now there are no images yet because 'KOHA.LocalCover.GetCoverFromBibnumber(false);', the function which populates the local cover image elements, hasn't even run yet. Note that it's called within a $(document).ready() which is written lower than the window.load()


It's possible that different configurations would yield different results, if they load different resources at different times, which could affect when the handlers run. 

I've observed the above when using a fairly vanilla koha-testing-docker.
Comment 1 Jonathan Druart 2025-01-28 11:42:25 UTC
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt

555                 // if( $(coverSlide).find(".cover-image").length < 1 ){
556                 //     $(coverSlide).remove();
557                 // } else {
558                     // This is a suboptimal workaround; we should do this via load, but
559                     // the image code is scattered all over now. We come here now after
560                     // window load and wait_for_images (so load completed).
561                     var check_complete = 1;
562                     $(coverSlide).find("img").each( function() {
563                         if( !this.complete || this.naturalHeight == 0 ) check_complete = 0;
564                     });
565                     if( check_complete ) $(coverSlide).removeClass('cover-slides');
566                 // }

Why are those lines commented?

It works (at first glance) if I bring them back.