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

@dts-stn/tab-id-hook

v1.2.0

Published

A React hook for managing unique, persistent tab identifiers to enable browser tab isolation.

Readme

@dts-stn/tab-id-hook

A React hook for managing unique, persistent tab identifiers to enable browser tab isolation.

The Problem

In complex web applications, users often open multiple tabs. If your application relies on shared storage mechanisms like localStorage or server-side sessions without distinguishing between tabs, data from one tab can overwrite data in another. This "data clobbering" leads to corrupted state and a frustrating user experience.

The Solution

@dts-stn/tab-id-hook provides a useTabId() hook that generates a unique identifier for each browser tab.

  • Persistence: The ID is stored in sessionStorage, so it survives page reloads within the same tab.
  • Isolation: Since sessionStorage is scoped to a single tab, each tab gets its own unique ID.
  • URL synchronization: Optionally syncs the tab ID with a URL query parameter to support deep linking and server-side rendering scenarios.

For a deeper dive into the motivation and mechanics, check out the blog post: A practical guide to browser tab isolation in React Router v7.

Installation

pnpm add @dts-stn/tab-id-hook
# or
npm install @dts-stn/tab-id-hook
# or
yarn add @dts-stn/tab-id-hook

Usage

import { useTabId } from "@dts-stn/tab-id-hook";

function MyComponent() {
  // Get the unique ID for this tab
  const tabId = useTabId();

  // Use the tabId to scope your data or API requests
  const sessionDataKey = `my-app-data-${tabId}`;

  return (
    <div>
      <p>Current Tab ID: {tabId}</p>
    </div>
  );
}

Server-Side Usage

You can use the getTabId() helper to retrieve the tab ID from the request URL in your server-side loaders or actions.

Here is a contrived but typical example:

import { getTabId } from "@dts-stn/tab-id-hook";
import { getSession } from "./session"; // Your session management logic

export async function loader({ request }) {
  const tabId = getTabId(request);

  //
  // Important: you must handle cases where the tab ID is missing (e.g., first page load)
  // This typically involves detecting the absence of data in your component and rendering
  // a suspense or spinner component while waiting for the hook to generate a new tab id.
  //

  if (!tabId) {
    return {
      /* 🤷 */
    };
  }

  //
  // Use the tab ID to retrieve isolated data from the session
  //

  const session = await getSession(request);
  const data = session.get(`my-data-${tabId}`);

  return { data };
}

API

useTabId(options?)

Returns the unique tab ID string.

Options

| Option | Type | Default | Description | | ------------------- | --------- | ---------- | ----------------------------------------------------------------------------- | | idSearchParamKey | string | 'tid' | The query parameter key used for storing the tab id in the URL. | | navigate | boolean | true | Whether to automatically update the URL with the tab id as a query parameter. | | reloadDocument | boolean | false | Whether to reload the document after navigating (updating the URL). | | sessionStorageKey | string | 'tab-id' | The session storage key used for persisting the tab id. |

getTabId(request, options?)

Extracts the tab ID from the request URL.

Parameters

  • request: The standard Request object.
  • options:
    • paramKey: The query parameter key to check (default: 'tid').

generateId()

Helper function that generates a random tab identifier in the format xx-0000.

License

MIT