Skip to content

Commit 48aaa64

Browse files
committed
fix: don't set after when loading backwards to avoid infinite recursion in the loading frontend
1 parent c1cd172 commit 48aaa64

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

pkg/handler/handlers_conversation.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,12 @@ func buildMessagesResponse(result core.MessageResult, query core.MessageQuery) a
235235
resp.Before = &first
236236
}
237237

238-
// "after" cursor: set if there are newer messages beyond the returned set.
239-
// When loading with "around", we're typically at the latest point, so don't
240-
// set "after". When loading with explicit "before" param, there are newer
241-
// messages the user hasn't scrolled to yet.
242-
if query.Before != "" && query.Around == "" {
238+
// "after" cursor: set only when loading forward with an explicit "after"
239+
// param AND more messages exist beyond the returned set (!result.End).
240+
// When loading backward ("before" or "around"), we must NOT set "after" —
241+
// doing so would cause the frontend to reset its historyStopAt cursor,
242+
// triggering an infinite reload loop.
243+
if query.After != "" && !result.End {
243244
last := time.Unix(result.Messages[len(result.Messages)-1].Timestamp, 0).UTC()
244245
resp.After = &last
245246
}

0 commit comments

Comments
 (0)