# 网格灯箱图片显示顺序错误

**URL:** https://meta.discourse.org/t/grid-lightbox-images-show-in-wrong-order/402817
**Category:** Bug
**Tags:** lightbox
**Created:** [2026年五月12日 21:12 UTC](https://meta.discourse.org/t/grid-lightbox-images-show-in-wrong-order/402817 "2026-05-12T21:12:55Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026年五月13日 09:16 UTC](https://meta.discourse.org/t/grid-lightbox-images-show-in-wrong-order/402817/3 "2026-05-13T09:16:40Z")

</div>

感谢 @Shauny 的报告。这次调试和修复的过程很有趣 🤓

> <https://github.com/discourse/discourse/pull/39968>
>
> Inside a \`\[grid\]\` block, the lightbox arrow navigation followed column-balanced …DOM order instead of the original markdown order. For four images this resulted in 1, 3, 2, 4 because \`Columns\` distributes items by height into the shortest column.
> 
> \`lightbox.js\` collects items via \`querySelectorAll(".lightbox")\`, which returns nodes in document order — the same scrambled order the layout algorithm produced.
> 
> \`Columns\` now tags each item with \`data-lightbox-position\` carrying its original index before reordering. A new \`sortLightboxItems\` helper in \`lightbox.js\` reorders items within each grid by that attribute before they reach PhotoSwipe. The existing RTL reverse continues to apply on top, so right-to-left navigation now mirrors logical order rather than the scrambled layout.
> 
> https://meta.discourse.org/t/402817

cc @davidb

---

_[View the full topic](https://meta.discourse.org/t/grid-lightbox-images-show-in-wrong-order/402817)._
