Skip to content

Commit fb2800a

Browse files
emilhaukclaude
andcommitted
Fix infinite scroll by switching from revealed to intersect trigger
HTMX's revealed trigger listens for window.scroll events, which never fire when scrolling inside .message-list (overflow-y: auto). The intersect trigger uses IntersectionObserver which correctly handles overflow clipping in ancestor scroll containers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3860966 commit fb2800a

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

internal/browser/realtime_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ func TestNoDuplicates_Scrollback(t *testing.T) {
155155
page.Timeout(3 * time.Second).MustElement(".scroll-sentinel")
156156

157157
// Trigger the sentinel directly via htmx.trigger so we don't depend on
158-
// HTMX's polling interval detecting the element in the headless viewport.
159-
// This dispatches the same 'revealed' DOM event that HTMX fires internally
160-
// when its setInterval determines the element is scrolled into view — the
161-
// full hx-get / hx-swap="beforebegin" path is exercised identically.
158+
// the IntersectionObserver firing in the headless viewport. This dispatches
159+
// the same 'intersect' event that HTMX fires internally when its observer
160+
// detects the element — the full hx-get / hx-swap="beforebegin" path is
161+
// exercised identically.
162162
page.MustEval(`() => {
163163
const s = document.querySelector('.scroll-sentinel');
164-
if (s) htmx.trigger(s, 'revealed');
164+
if (s) htmx.trigger(s, 'intersect');
165165
}`)
166166

167167
// Poll until all 55 articles are present (up to 8 s).

web/templates/history.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{if .Data.HasMore}}
44
<div class="scroll-sentinel"
55
hx-get="/rooms/{{.Data.RoomID}}/messages?before={{.Data.OldestMS}}&limit=50"
6-
hx-trigger="revealed"
6+
hx-trigger="intersect once"
77
hx-swap="beforebegin"></div>
88
{{end}}
99

web/templates/room.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ <h1 class="room-main__title"># {{.Data.Room.Name}}</h1>
154154
{{if .Data.OldestMS}}
155155
<div class="scroll-sentinel"
156156
hx-get="/rooms/{{.Data.Room.ID}}/messages?before={{.Data.OldestMS}}&limit=50"
157-
hx-trigger="revealed"
157+
hx-trigger="intersect once"
158158
hx-swap="beforebegin"></div>
159159
{{end}}
160160

0 commit comments

Comments
 (0)