Skip to content

[2.x] fix: image preview shows empty src in composer preview#469

Merged
imorland merged 1 commit into
2.xfrom
im/fix-image-preview-empty-src
Feb 22, 2026
Merged

[2.x] fix: image preview shows empty src in composer preview#469
imorland merged 1 commit into
2.xfrom
im/fix-image-preview-empty-src

Conversation

@imorland

Copy link
Copy Markdown
Member

Problem

After the thumbnail feature (PR #465), uploading an image with the image-preview template showed a broken image (src="") in the composer live preview:

<img class="FoFUpload--Upl-Image-Preview" src="" ...>

Root cause

The preview() method in ImagePreviewTemplate generates the BBCode string that the JavaScript TextFormatter renderer uses for the composer preview (the live preview while typing, before the post is submitted). It was not including thumbnail_url:

// Before
return "[upl-image-preview uuid={$file->uuid} url={$file->url} alt={$file->base_name}]";

The image-preview blade template uses {@thumbnail_url} as the <img src>. Since thumbnail_url was absent from the BBCode, the JS renderer set src="".

The PHP FormatImagePreview renderer (which properly injects thumbnail_url) only runs at post save/render time — not during the composer live preview.

Fix

Include thumbnail_url in the preview BBCode, using $file->thumbnail_url (the stored thumbnail) falling back to $file->url (the original file URL):

$thumbnailUrl = $file->thumbnail_url ?: $file->url;
return "[upl-image-preview uuid={$file->uuid} url={$file->url} alt={$file->base_name} thumbnail_url={$thumbnailUrl}]";

Forums without thumbnails generated (e.g. before running the backfill command) will show the full-resolution image in the preview, matching the pre-thumbnail behaviour.

🤖 Generated with Claude Code

The preview() method generates the BBCode that the JS TextFormatter
renders live in the composer (before the post is submitted). It was
missing the thumbnail_url attribute, so the image-preview template's
{@thumbnail_url} resolved to an empty string → src="" in the HTML.

The PHP FormatImagePreview renderer (which injects thumbnail_url) only
runs on post save/render, not during the composer preview.

Fix: include thumbnail_url in the preview BBCode, using $file->thumbnail_url
(stored thumbnail) falling back to $file->url (original file URL) so
the preview always has a valid image src.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imorland imorland requested a review from a team as a code owner February 22, 2026 21:55
@imorland imorland changed the title fix: image preview shows empty src in composer preview [2.x] fix: image preview shows empty src in composer preview Feb 22, 2026
@imorland imorland added the bug label Feb 22, 2026
@imorland imorland merged commit ce304d4 into 2.x Feb 22, 2026
29 checks passed
@imorland imorland deleted the im/fix-image-preview-empty-src branch February 22, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant