Front End · JavaScript · Debugging

The Gallery Wasn't Empty. It Just Wasn't Where It Belonged.

Product galleries sometimes went blank after shoppers switched between product options. The obvious theory was that the images never loaded. They did. The gallery was there the whole time, just shifted out of view.

A blank gallery, sometimes

On product pages, choosing a different size or variant swaps the product images in the gallery. Every so often, after switching, the gallery just showed nothing. No images, no obvious error, and the rest of the page kept working fine.

Intermittent front-end bugs are the worst kind. By the time someone reports it, the page has been reloaded and everything looks normal again.

First, rule out the server

When something looks broken, it's tempting to blame the back end. So I checked the production server's health: CPU, memory, connections, app pool restarts, and the application logs for search or rendering errors.

All healthy. Low CPU, plenty of memory, no unexpected restarts, no relevant errors. Whatever was blanking the gallery wasn't server pressure, which pointed the investigation back to the browser.

Blank isn't the same as empty

The next question was simple: when the gallery looks blank, is it actually empty? I checked in the browser instead of guessing.

The images had loaded successfully. The carousel had been initialized, and its container had real dimensions. But the carousel's track was sitting at an offset of about -346 pixels, which pushed the visible slide outside the frame. The gallery wasn't empty. It was just somewhere you couldn't see it.

// Run in DevTools when the gallery looks blank
({
  images: document.querySelectorAll('.productimage img').length,
  carousels: document.querySelectorAll('.productimage .slick-initialized').length,
  trackTransform: getComputedStyle(
    document.querySelector('.productimage .slick-track')
  ).transform
})

The leading theory (and why it's still a theory)

There was a second clue. A third-party "where to buy" widget on the same page refreshes itself when the variant changes, and it sometimes threw an error: it tried to clear a timer on a request that no longer existed. That looks like a timing problem inside the widget, and an error mid-update could interrupt the gallery before it finished positioning itself.

So the leading theory is a race condition: switch variants quickly, the widget's refresh and the gallery's rebuild overlap, the widget errors, and the gallery is left in the wrong position.

I want to be honest about the status. That race wasn't conclusively proven, and I don't have a verified permanent fix. What I did build was the instrumentation to catch it: a small logging script that records the widget's refresh start and end, any JavaScript errors, and every change to the gallery, so the next occurrence leaves evidence behind.

What I took away

  • "Blank" is a symptom, not a diagnosis. Check whether the content is missing or just misplaced.
  • Rule out the server quickly so you don't spend days in the wrong layer.
  • Third-party scripts share your page and can break your components without touching your code.
  • For intermittent bugs, build logging that captures the next occurrence instead of waiting to get lucky.
  • Label findings and hypotheses separately. It keeps everyone honest, including you.