Skip to content

Fix blank images in matrix box after upload#4124

Merged
mo-nathan merged 4 commits intomainfrom
njw-4123-fix-blank-images-after-upload
Apr 16, 2026
Merged

Fix blank images in matrix box after upload#4124
mo-nathan merged 4 commits intomainfrom
njw-4123-fix-blank-images-after-upload

Conversation

@mo-nathan
Copy link
Copy Markdown
Member

@mo-nathan mo-nathan commented Apr 14, 2026

Summary

Fixes #4123

Images were showing blank in matrix boxes immediately after upload. Root cause: process_image hadn't finished creating thumbnails, so the browser requested the remote image URL, got a 404, cached it, and the blank image persisted even after processing completed.

Three layered fixes plus an nginx config sync:

1. Generate thumbnails first (script/process_image)

  • Reversed resize order: create 320px and thumb before larger sizes
  • Thumbnail available in ~2 seconds instead of waiting behind all larger sizes (~9+ seconds)

2. Placeholder fallback (app/models/image/url.rb)

  • When no image source is available (transferred=false, no local file), return a placeholder image URL instead of the remote URL that will 404
  • Added place_holder_thumb.jpg and place_holder_320.jpg to public/ for direct serving

3. No-cache on nginx image redirects (config/etc/nginx.conf)

  • Added dedicated location block for image file paths with try_files to serve local files first
  • Fallback @images location returns 302 redirect with Cache-Control: no-store so browsers don't cache redirects to not-yet-transferred images

4. Sync nginx config with production

  • Action Cable websocket location block
  • IPv6 listeners
  • SSL cert path update (-0001)
  • Google Cloud archive rewrite pattern (1[0123] range)

A fourth fix (option 1 from the issue) adds Cache-Control: no-store to 404 responses on images.mushroomobserver.org — that change needs to be coordinated separately with the image server admin.

Test plan

  • Verify existing image model tests pass
  • Upload an image and confirm placeholder appears briefly in matrix box instead of blank
  • Confirm image appears correctly once processing completes
  • Verify nginx config is valid (nginx -t)

🤖 Generated with Claude Code

mo-nathan and others added 2 commits April 14, 2026 14:00
Images were showing blank in matrix boxes immediately after upload
because process_image hadn't finished creating thumbnails. The browser
would request the remote URL, get a 404, cache it, and the blank
image persisted even after processing completed.

Three layered fixes:

1. Generate thumbnails first in process_image — create 320 and thumb
   before larger sizes so matrix box images are available sooner

2. Return placeholder image URLs when no source is available — instead
   of falling through to the remote URL that will 404, serve
   place_holder_thumb.jpg or place_holder_320.jpg

3. Add Cache-Control: no-store to nginx image redirects — prevents
   browsers from caching 302 redirects to images that may not exist
   yet on the remote server. Also updates the Google Cloud archive
   rewrite pattern to match production (1[0123] range).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bring repo nginx config in line with what's running in production:
- Add IPv6 listeners
- Add Certbot host check in HTTP->HTTPS redirect
- Add Action Cable websocket location block
- Update SSL cert path to -0001 (Certbot renewal)
- Update comment wording to match production

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 14, 2026 18:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Addresses blank matrix-box images immediately after upload by avoiding early 404s (and cached failures) while thumbnails are still being generated/transferred.

Changes:

  • Reorders thumbnail generation in script/process_image to produce 320px + thumb first.
  • Adds placeholder image URLs for thumbnail/small when no source is available yet.
  • Updates nginx image handling to prefer local files, otherwise redirect with Cache-Control: no-store, plus syncs several production nginx settings.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
script/process_image Generates 320px + thumb earlier in the processing pipeline to reduce the window where matrix boxes request missing thumbnails.
app/models/image/url.rb Returns placeholder URLs for thumbnail/small when neither “transferred” nor local-file sources exist.
config/etc/nginx.conf Adds dedicated /images/... handling and no-store redirects, plus production parity updates (IPv6, Cable, SSL path, archive regex).
public/place_holder_thumb.jpg New placeholder asset for thumbnail size.
public/place_holder_320.jpg New placeholder asset for 320px size.

Comment thread config/etc/nginx.conf Outdated
Comment thread app/models/image/url.rb
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 14, 2026

Coverage Status

coverage: 96.266%. remained the same — njw-4123-fix-blank-images-after-upload into main

mo-nathan and others added 2 commits April 16, 2026 09:08
Strip /images prefix in nginx redirect so image server receives
the expected /<size>/<id>.<ext> path instead of
/images/<size>/<id>.<ext>.

Add test verifying that untransferred images return placeholder
URLs for thumbnail/small sizes and fall back to remote source
for other sizes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mo-nathan mo-nathan merged commit 65cda0d into main Apr 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Images not showing up immediately after upload

3 participants