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.
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)
@davidb It seems that one of the recent commit to the lightbox component has a bug preventing the component from starting in discourse solved and other items like that, after my PR get merged.
I’m not quite sure whether this PR actually breaks that.
The repro can be done here right now.
Like clicking the [IMG_6085] from the onebox quote, or open the link and click the image of the answer in discourse solved component of the given page. The original behavior is open a lightbox, but now nothing happened.
The console shows an error: Uncaught TypeError: Cannot read properties of null (reading 'getAttribute')
Related code is:
// this ensures that cropped images (eg: grid) do not cause jittering when closing
data.thumbCropped = true;
data.src = data.src || el.getAttribute("data-large-src");
-> data.origSrc = imgEl.getAttribute("data-orig-src");
data.title = el.title || imgEl.alt || imgEl.title;
Maybe turning the code into the following will work: