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" />
يحتوي PhotoSwipeLightbox التجريبي الجديد (siteSettings.experimental_lightbox) على أخطاء عندما يكون رابط الصورة موجودًا في Discourse Solved أو مكون التحميل في admin/config/logo. السبب الجذري هو أن PhotoSwipeLightbox يحتاج إلى العرض والارتفاع من الصورة التي تم تحميلها بالفعل، بينما لا يحتوي Discourse Solved ومكون التحميل على هذه السمات.
بدون هذه السمات، سيتم تمديد الصورة لملء نافذة المتصفح، مما يتسبب في تشويه، كما هو موضح في الشكل المرفق.
يضيف هذا الالتزام آلية تحميل مسبق للصور التي لا تحتوي على أبعاد للحصول على أبعادها، حتى يمكن عرضها بشكل طبيعي.
إعجابَين (2)
davidb
(David B)
11 نوفمبر 2025، 9:30ص
2
شكراً لك على الإبلاغ عن هذا ومشاركة الحل.
لقد أضفت بعض التعليقات/الاقتراحات على طلب السحب (PR) ولكن بشكل عام أعتقد أننا بحاجة إلى آلية احتياطية كهذه للتعامل مع الحالات الاستثنائية.
حسنًا، شكرًا، سأقوم بإلقاء نظرة على التعليقات عند توافري.
context "عندما تفتقد سمات البيانات" do
it "يقوم بتحميل الصور مسبقًا ويضبط الأبعاد" 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")
expect(lightbox_link["data-target-width"]).to be_nil
expect(lightbox_link["data-target-height"]).to be_nil
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
أنا أضيف هذا إلى lightbox_spec.rb كاختبار وحدة لتلك الصور التي لا تحتوي على أبعاد، هل يبدو هذا جيدًا؟
بالإضافة إلى ذلك، لقد أجريت بعض التعديلات على منطق التمييز، للتعامل مع تلك التي تحتوي على بيانات وصفية ولكن البيانات الوصفية لا تحتوي على معلومات الحجم. (أي، مكون التحميل)
const missingMetaData = !item
.querySelector(".meta")
?.textContent.trim()
.split(/x|×/)
.every((v) => v && +v > 0);