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 🙏

© 2026 – Pkg Stats / Ryan Hefner

solid-scroll-restoration

v0.1.2

Published

A lightweight SolidJS primitive for saving and restoring scroll positions on any scrollable element. Supports in-memory, `localStorage`, and `sessionStorage` persistence — perfect for preserving scroll state across route changes or page reloads.

Readme

solid-scroll-restoration

A lightweight SolidJS primitive for saving and restoring scroll positions on any scrollable element. Supports in-memory, localStorage, and sessionStorage persistence — perfect for preserving scroll state across route changes or page reloads.

Installation

npm install solid-scroll-restoration
# or
pnpm add solid-scroll-restoration
# or
yarn add solid-scroll-restoration

Peer dependency: solid-js ^1.9.10

Quick Start

import { createSignal } from "solid-js";
import createScrollRestoration from "solid-scroll-restoration";

const ScrollableList = () => {
  const [scrollElement, setScrollElement] = createSignal<HTMLDivElement | null>(null);

  createScrollRestoration(scrollElement, () => "my-list");

  return (
    <div ref={setScrollElement} style={{ height: "400px", overflow: "auto" }}>
      {/* scrollable content */}
    </div>
  );
};

When the component unmounts and remounts, the scroll position is automatically restored.

API

createScrollRestoration(element, key, options?)

| Parameter | Type | Description | |---|---|---| | element | Accessor<HTMLElement \| null> | A signal returning the scrollable DOM element (typically set via ref). | | key | Accessor<string> | A signal returning a unique string key used to identify this scroll position. Changing the key will save/restore a different scroll position. | | options | ScrollRestorationOptions | Optional configuration object. |

Options

| Option | Type | Default | Description | |---|---|---|---| | debounceTime | number | 100 | Milliseconds to debounce the scroll event listener before saving the position. | | persist | false \| "localStorage" \| "sessionStorage" | false | Where to persist scroll positions. When false, positions are only stored in memory and lost on full page reload. |

Usage Examples

Basic (In-Memory Only)

Scroll positions are kept in a SolidJS signal and restored when the component remounts within the same session. A full page reload will reset them.

createScrollRestoration(scrollElement, () => "feed");

Persist with sessionStorage

Scroll positions survive full page reloads within the same browser tab. Ideal for single-page apps with client-side routing.

createScrollRestoration(scrollElement, () => "feed", {
  persist: "sessionStorage",
});

Persist with localStorage

Scroll positions persist across tabs, windows, and browser sessions.

createScrollRestoration(scrollElement, () => "feed", {
  persist: "localStorage",
});

Dynamic Keys (e.g. Route-Based)

Use a reactive key to track separate scroll positions for different routes or views:

import { useLocation } from "@solidjs/router";

const App = () => {
  const [scrollElement, setScrollElement] = createSignal<HTMLDivElement | null>(null);
  const location = useLocation();

  createScrollRestoration(scrollElement, () => location.pathname, {
    persist: "sessionStorage",
  });

  return (
    <div ref={setScrollElement} style={{ height: "100vh", overflow: "auto" }}>
      {/* routed content */}
    </div>
  );
};

Custom Debounce Time

Reduce save frequency for performance-sensitive scenarios:

createScrollRestoration(scrollElement, () => "feed", {
  debounceTime: 250,
});

How It Works

  1. Listens for scroll events on the target element (debounced).
  2. Saves { scrollTop, scrollLeft } to an in-memory signal, keyed by the string you provide.
  3. Persists (optional) the saved position to localStorage or sessionStorage under the key scrollRestoration-<your-key>.
  4. Restores the position when the component remounts — first checking in-memory state, then falling back to storage if persistence is enabled.

License

MIT