Skip to main content

max / makenotwork

server: clamp discover pagination past the end of the results /discover/results?page=999999 rendered "Showing 0-24999950 of 2" with Next still enabled. The range end was the raw offset even when the page returned no rows, and the Next control only disabled on an exact current_page == total_pages match, which an out-of-range page never hits. Both ends of the range now collapse to zero when the page is empty, and the Prev/Next guards compare with <= and >= so a page past the end disables Next rather than offering another one. What gets fetched is unchanged. Closes GoingsOn problem c69a38d6.
Co-Authored-By
Claude Opus 5 (1M context) <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-08-01 20:23 UTC
Signed with PGP, not checked
Commit: f6ba08665f13331bfdda79db191a9dc65b94a7a2
Parent: 0eb77ac
2 files changed, +14 insertions, -7 deletions
@@ -187,12 +187,12 @@
187 187 <span class="page-info">Showing {{ showing_start }}-{{ showing_end }} of {{ total_items }}</span>
188 188 <div class="pagination">
189 189 {% if total_pages > 0 %}
190 - <button {% if current_page == 1 %}disabled{% endif %}
190 + <button {% if current_page <= 1 %}disabled{% endif %}
191 191 hx-get="/discover/results"
192 192 hx-target="#results-container"
193 193 hx-include=".discover-filter"
194 194 hx-vals='{"page": {{ current_page - 1 }}}'
195 - {% if current_page == 1 %}hx-disabled-elt="this"{% endif %}>Prev</button>
195 + {% if current_page <= 1 %}hx-disabled-elt="this"{% endif %}>Prev</button>
196 196 {% for p in pagination_range %}
197 197 <button {% if *p == current_page %}class="is-selected"{% endif %}
198 198 hx-get="/discover/results"
@@ -207,12 +207,12 @@
207 207 hx-include=".discover-filter"
208 208 hx-vals='{"page": {{ total_pages }}}'>{{ total_pages }}</button>
209 209 {% endif %}
210 - <button {% if current_page == total_pages || total_pages == 0 %}disabled{% endif %}
210 + <button {% if current_page >= total_pages || total_pages == 0 %}disabled{% endif %}
211 211 hx-get="/discover/results"
212 212 hx-target="#results-container"
213 213 hx-include=".discover-filter"
214 214 hx-vals='{"page": {{ current_page + 1 }}}'
215 - {% if current_page == total_pages || total_pages == 0 %}hx-disabled-elt="this"{% endif %}>Next</button>
215 + {% if current_page >= total_pages || total_pages == 0 %}hx-disabled-elt="this"{% endif %}>Next</button>
216 216 {% endif %}
217 217 </div>
218 218 </div>
@@ -1162,9 +1162,16 @@
1162 1162 } else {
1163 1163 offset.saturating_add(1).clamp(0, u32::MAX as i64) as u32
1164 1164 };
1165 - let showing_end = offset
1166 - .saturating_add(result_count as i64)
1167 - .clamp(0, u32::MAX as i64) as u32;
1165 + // An out-of-range `?page=` returns nothing, and the raw offset would then render
1166 + // as "Showing 0-24999950 of 2". With no rows on the page there is no range to
1167 + // show, so both ends collapse to zero.
1168 + let showing_end = if result_count == 0 {
1169 + 0
1170 + } else {
1171 + offset
1172 + .saturating_add(result_count as i64)
1173 + .clamp(0, u32::MAX as i64) as u32
1174 + };
1168 1175
1169 1176 Ok(DiscoverData {
1170 1177 items,