main ← small-lovely-cat:main
opened 06:02AM - 27 Oct 25 UTC
The new experimental `PhotoSwipeLightbox` (siteSettings.experimental_lightbox) c… ontain bugs when the image link exists in `Discourse Solved` or the upload component in `admin/config/logo`. The root cause is that `PhotoSwipeLightbox` need width and height from the already-loaded image, while `Discourse Solved` and the upload component don't have these attributes.
Without these attributes, the image will be stretched to fill the browser window, causing distortion, as shown in the figure attached.
This commit add a preload mechanism for images without dimensions to get their dimensions, so that they can be displayed normally.
Before fix:
`upload component`
<img width="1600" height="801" alt="image" src="https://github.com/user-attachments/assets/ad1eb80d-a348-412a-a3d3-75701c97f6a4" />
`Discourse Solved`
<img width="1007" height="484" alt="image" src="https://github.com/user-attachments/assets/20d227c7-2539-463a-903d-4a83d8782460" />
<img width="1919" height="914" alt="image" src="https://github.com/user-attachments/assets/d0c8ef5f-05a6-48dc-b507-94b796b095b9" />
After fix:
`upload component`
<img width="1603" height="758" alt="image" src="https://github.com/user-attachments/assets/03302997-9a43-425d-a7df-c218961a377a" />
`Discourse Solved`
<img width="1603" height="760" alt="image" src="https://github.com/user-attachments/assets/ced4355a-8818-4ef5-bce2-cb632165e3a9" />
The new experimental PhotoSwipeLightbox (siteSettings.experimental_lightbox) contain bugs when the image link exists in Discourse Solved or the upload component in admin/config/logo and somewhere without a rendered [img] html mark.
The root cause is that PhotoSwipeLightbox need width and height from the already-loaded image, while Discourse Solved and the upload component don’t have these attributes.
Without these attributes, the image will be stretched to fill the browser window, causing distortion, as shown in the figure attached.
This commit add a preload mechanism for images without dimensions to get their dimensions, so that they can be displayed normally.
2 Likes
davidb
(David B)
November 11, 2025, 9:30am
2
Thank you for reporting this and sharing a fix.
I’ve added some comments/suggestions on the PR but overall I think we need a fallback like this to catch the edge cases.
OK thanks, I’ll cast insight into the comments accordingly when free.
context "when missing data attributes" do
it "preloads images and sets dimensions" do
upload_1.update(width: 400, height: 300)
post.update(
cooked:
"<p><a href=\"#{upload_1.url}\" class=\"lightbox\" data-download-href=\"#{upload_1.url}\">[image]</a></p>",
)
topic_page.visit_topic(topic)
lightbox_link = find("#post_1 a.lightbox")
lightbox_link.click
expect(lightbox).to be_visible
expect(lightbox_link["data-target-width"]).to eq(upload_1.width.to_s)
expect(lightbox_link["data-target-height"]).to eq(upload_1.height.to_s)
end
end
I’m adding this to the lightbox_spec.rb as a unit test for those images without dimensions, so does that seem okey?
1 Like
Also, I have made some alterations to the discrimination logic, to handle those with meta but without the meta fails to contain the size info. (i.e., the upload component)
const missingMetaData = !item
.querySelector(".meta")
?.textContent.trim()
.split(/x|×/)
.every((v) => v && +v > 0);
1 Like
davidb
(David B)
November 20, 2025, 7:18am
6
Thank you for working on this and following up on the PR review. I’ve merged this now.
1 Like