feat(v2): load older messages in pod chat - #767
Merged
Conversation
"Load older messages" worked on the anonymous showcase route but did nothing in a pod you had actually joined. Not a broken feature — it was never built there. PR #764 added paging to the showcase reader only; the authenticated path fired exactly one `?limit=50` request, kept no cursor, and exposed no way to ask for anything older, so any conversation past 50 messages was simply unreachable. The backend already supported it: messageController accepts `before`, and both readers bottom out in the same PGMessage.findByPodId. The entire gap was client-side. - useV2PodDetail gains hasMore / loadingOlder / loadOlder. End-of-history is inferred from a short page, since this endpoint returns a bare array with no envelope and changing that shape would break every existing consumer. - Pages are merged by id rather than concatenated: the socket can deliver a message while the request is in flight, and a plain concat would duplicate it. - V2PodChat renders the pager at the top of the scroll container, styled to match the showcase pill so the two reading surfaces agree. Two scroll defects had to be fixed or the feature would have looked broken: - the auto-scroll effect keyed on `messages.length`, so prepending a page threw the reader from the older message they had just asked for straight back to the bottom. It now keys on the newest message's id, so prepends are ignored. - a prepend changes scrollHeight and jumps the viewport, so the reader's position is held by restoring distance-from-bottom, which is invariant under a prepend. 6 hook tests: cursor correctness, prepend order, dedupe against an overlapping socket message, no-op on an empty pod, and hasMore surviving a failed request so the button stays retryable. Frontend suite 69/69, 316 tests. Lint at baseline. Needs a real-browser check after deploy — jsdom has no layout engine, so the scroll-anchor behaviour specifically is not covered by these tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DMeWzgFxsfBcjoLVLewEES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported: "the load older messages thing works on the public-read showcase room but it doesn't work on a real entered pod."
It was never built there
Not a broken feature. #764 added paging to the showcase reader only. The authenticated path fired exactly one request and kept no cursor:
V2PodChathad no button, no scroll handler, no observer. So any conversation past 50 messages was simply unreachable in a pod you had joined.The backend already supported it —
messageControlleracceptsbefore, and both readers bottom out in the samePGMessage.findByPodId. The whole gap was client-side.What's here
useV2PodDetailgainshasMore/loadingOlder/loadOlder. End-of-history is inferred from a short page, because this endpoint returns a bare array and adding an envelope would break every existing consumer.enandzh-CN.Two scroll defects that would have made it look broken
messages.length, so prepending a page threw the reader from the older message they'd just asked for straight back to the bottom. Now keyed on the newest message's id, so prepends are ignored.scrollHeightand jumps the viewport. The reader's position is held by restoring distance-from-bottom, which is invariant under a prepend.Neither is visible to jsdom, which is why they're called out rather than assumed fixed.
Test
6 hook tests: cursor correctness, prepend order, dedupe against an overlapping socket message, no-op on an empty pod, and
hasMoresurviving a failed request so the button stays retryable.Frontend suite 69/69 suites, 316 tests. Lint identical to baseline (163 problems, the 1 error pre-existing in
PersonalityBuilder.tsx). Typecheck: one pre-existing error remains, one removed.Wants a real-browser check after deploy — per CLAUDE.md, jsdom has no layout engine, and the scroll-anchor behaviour above is exactly the class of thing it can't cover.
🤖 Generated with Claude Code