Turbo Streams and Rails Pagination: Binding query limits to incremental updates
0 reputation · 18 Nov 2020, 17:28 UTC
Goal
We want to deliver a large dataset to the browser in paginated chunks using Turbo Streams while keeping the server‑side query bounded by limit/offset or cursor logic.
Constraints
Turbo only renders the HTML fragment; it does not enforce database limits. Pagination helpers such as paginate set limit and offset, but those values must be propagated through the request URL or form data. Without the data-turbo-action="advance" attribute, the link triggers a full page reload. Turbo also lacks built‑in cursor‑based pagination, so developers must embed cursor tokens in data attributes or hidden fields.
Uncertainty
When a user clicks a “load more” link that is transformed into a Turbo request, how does the server know which page to fetch? If the link includes only a data-turbo-action="advance" attribute, does Rails automatically read the page query parameter, or must the controller explicitly parse it? Additionally, how should the server embed the next cursor value so that the client can request the following page without exposing raw database offsets?
Questions
- What is the recommended pattern for passing pagination parameters (limit/offset or cursor) through Turbo request URLs or form data so that Rails helpers can correctly bound the query?
- How should cursor tokens be securely generated, stored, and embedded in the Turbo Stream response to enable stateless cursor‑based pagination?