Lovablefeatureintermediate

Add Infinite Scroll to Lovable App

Add infinite scroll with Intersection Observer, loading indicators, and end-of-list detection.

What you'll get

Infinite scroll with Intersection Observer, loading indicators, scroll position memory, and end-of-list detection.

The Prompt

Add infinite scroll to data lists in my Lovable app.

REQUIREMENTS:
1. Replace pagination with infinite scroll on list/grid pages.
2. Use Intersection Observer API to detect when the user scrolls near the bottom of the list (200px threshold).
3. Fetch the next page of results from Supabase using range queries (e.g., .range(offset, offset + pageSize)).
4. Show a loading spinner at the bottom while fetching the next page.
5. Detect end of data and show an "All items loaded" message. Stop observing after the last page.
6. Maintain scroll position when navigating away and returning (using sessionStorage).
7. Add a "Scroll to top" button that appears after scrolling past 3 pages.
8. Handle errors gracefully — show a retry button if a page fetch fails.
9. Support pull-to-refresh on mobile to reload from the first page.

DATABASE:
- No new tables. Uses existing tables with offset/limit queries.
- Ensure the query has a consistent ORDER BY for stable pagination.

SECURITY:
- Validate page size on the server to prevent abuse (max 50 items per request).

Replace these variables

VariableReplace with
[PAGE_SIZE]Number of items to load per page (e.g., 20)
[TARGET_LIST]Which list/grid to add infinite scroll to

Tips for best results

Always add a consistent ORDER BY clause — without it, items may appear in different positions across pages.

Set the intersection threshold to 200px so content loads before the user hits the bottom.

Follow-up prompts

Add virtual scrolling

Upgrade to virtual scrolling (windowing) that only renders visible items in the DOM. This improves performance for lists with thousands of items.

Related prompts