Build a social-style feed that loads posts in pages and fetches the next page automatically as the user scrolls near the bottom.
api.js provides fetchPosts({ cursor, limit, signal }), a mock that stands in for a real endpoint such as GET /api/posts?cursor=…&limit=10. It resolves to { items, nextCursor } after a short delay, where nextCursor is null on the last page (34 posts in total), and rejects with an AbortError when its signal is aborted. Set mockOptions.failRate to simulate network errors.
A real endpoint differs in ways your code should be ready for. It returns JSON over fetch (check response.ok yourself), the cursor is an opaque string, latency and failures vary, and new posts can be inserted at the top while you page. Cursor pagination, rather than ?page=3, is what keeps that last case from producing duplicates.
IntersectionObserver). Also render a visible Load more button: it's the keyboard and fallback path, and environments without IntersectionObserver (like the test runner) rely on it.nextCursor is null, stop loading and show You're all caught up.role="feed" and aria-busy="true" while a page is loading.<article> labelled by its title, with aria-posinset and aria-setsize (-1 while the total is unknown) and tabindex="0".Loaded 10 more posts politely.Spotted a mistake or a rights concern? Report an issue