npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sly-svelte-infinite-scroll

v1.0.1

Published

A performant infinite scroll component for Svelte with bidirectional loading and dynamic item mounting

Readme

Dead simple infinite scroll for Svelte 5 - just add to the end of any list

AboutFeaturesInstallationUsageExamples

About

A minimal infinite scroll component that you simply add to the end of your list. When it becomes visible, it calls your load function. When that function returns an empty array, it stops. No complex configuration, no managing state - it just works.

Features

  • Drop-in Component - Add to the end of any list, no wrapper needed
  • Auto-detection - Automatically stops when you return an empty array
  • Performance First - Uses IntersectionObserver for efficient scroll detection
  • Zero Dependencies - Just Svelte 5, nothing else

Installation

pnpm add sly-svelte-infinite-scroll
npm install sly-svelte-infinite-scroll
yarn add sly-svelte-infinite-scroll

Requirements

  • Svelte 5.0.0 or higher
  • Modern browser with IntersectionObserver support

Usage

<script lang="ts">
  import { InfiniteScroll } from 'sly-svelte-infinite-scroll';
  
  let items = $state([]);
  
  async function loadMore() {
    const response = await fetch('/api/items?offset=' + items.length);
    const newItems = await response.json();
    
    items = [...items, ...newItems];
    return newItems; // Return empty array to stop
  }
</script>

<div class="list">
  {#each items as item}
    <div>{item.name}</div>
  {/each}
  
  <InfiniteScroll onLoadMore={loadMore} />
</div>

Technologies

The component leverages modern web APIs and Svelte's latest features for optimal performance:

  • Svelte 5 Runes - Using the new reactivity system with $state and $props docs
  • IntersectionObserver API - Efficient visibility detection without scroll listeners docs
  • TypeScript - Full type safety with generic item types docs

Examples

Basic List with API Pagination

<script lang="ts">
  import { InfiniteScroll } from 'sly-svelte-infinite-scroll';
  
  interface Post {
    id: number;
    title: string;
    body: string;
  }
  
  let posts = $state<Post[]>([]);
  let page = $state(1);
  
  async function loadMore() {
    const res = await fetch(`/api/posts?page=${page}&limit=20`);
    const newPosts = await res.json();
    
    posts = [...posts, ...newPosts];
    page++;
    
    return newPosts; // Component stops when this is empty
  }
</script>

<div class="posts">
  {#each posts as post (post.id)}
    <article>
      <h2>{post.title}</h2>
      <p>{post.body}</p>
    </article>
  {/each}
  
  <InfiniteScroll onLoadMore={loadMore} threshold={300} />
</div>

Log Viewer with Maximum Items

<script lang="ts">
  import { InfiniteScroll } from 'sly-svelte-infinite-scroll';
  import LogLine from './LogLine.svelte';
  
  let logs = $state([]);
  let cursor = $state('');
  
  async function loadMore() {
    // Stop after 2000 items
    if (logs.length >= 2000) return [];
    
    const res = await fetch(`/api/logs?cursor=${cursor}`);
    const { items, nextCursor } = await res.json();
    
    logs = [...logs, ...items];
    cursor = nextCursor;
    
    return items;
  }
  
  $effect(() => {
    loadMore(); // Load initial data
  });
</script>

<div class="log-viewer">
  {#each logs as log (log.id)}
    <LogLine {log} />
  {/each}
  
  <InfiniteScroll onLoadMore={loadMore} threshold={200} />
</div>

Check out the full example app in the repository for a complete implementation with a device console log viewer.