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

uni-themes

v0.0.1

Published

Theme switching for React apps: framework-agnostic core, zero-FOUC inline script, no React 19 script warnings. Works with Next.js, React Router, TanStack Start and Vite.

Readme

uni-themes

Theme switching for React apps — framework-agnostic core, zero-FOUC inline script, no React 19 script warnings. Works with Next.js, React Router, TanStack Start and Vite.

next-themes is battle-tested but unmaintained: its provider renders the anti-FOUC <script> from a client component, which triggers React 19's "Encountered a script tag while rendering" error whenever the tree remounts (e.g. switching a root [lang] segment). uni-themes splits the script out as a server-renderable component you put in <head> yourself — the warning is impossible by construction — and keeps the rest of the API drop-in familiar.

  • Zero FOUC — a synchronous inline script resolves the theme before first paint
  • No React 19 warnings — the script never renders from a client component
  • system support — tracks prefers-color-scheme live, plus color-scheme on <html>
  • Cross-tab sync — via the storage event
  • Cookie mode — read the theme on the server (Next.js, React Router, TanStack Start)
  • Tiny — framework-agnostic core + a useSyncExternalStore React binding, ESM only

Install

pnpm add uni-themes

Next.js (App Router)

// app/layout.tsx — stays a server component
import { ThemeProvider } from 'uni-themes'
import { ThemeScript } from 'uni-themes/script'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <head>
        <ThemeScript />
      </head>
      <body>
        <ThemeProvider>{children}</ThemeProvider>
      </body>
    </html>
  )
}
'use client'
import { useTheme } from 'uni-themes'

export function ThemeSwitcher() {
  const { resolvedTheme, setTheme } = useTheme()
  return (
    <button onClick={() => setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')}>
      Toggle
    </button>
  )
}

To read the theme on the server, switch on cookie storage and use uni-themes/next:

import { getTheme } from 'uni-themes/next'

// <ThemeScript storage="cookie" /> + <ThemeProvider storage="cookie">
const theme = await getTheme() // 'dark' | 'light' | 'system' | null

React Router / Remix

// app/root.tsx
import { ThemeProvider } from 'uni-themes'
import { ThemeScript } from 'uni-themes/script'
import { getThemeFromRequest } from 'uni-themes/server'

export async function loader({ request }: LoaderFunctionArgs) {
  return { theme: getThemeFromRequest(request) } // storage: 'cookie'
}

export default function Root() {
  return (
    <html lang="en" suppressHydrationWarning>
      <head>
        <ThemeScript storage="cookie" />
        <Meta />
        <Links />
      </head>
      <body>
        <ThemeProvider storage="cookie">
          <Outlet />
        </ThemeProvider>
        <Scripts />
      </body>
    </html>
  )
}

TanStack Start

Render <ThemeScript /> in the head of __root.tsx and wrap the outlet in <ThemeProvider>; getThemeFromRequest from uni-themes/server works in server functions.

Vite SPA

No script needed — there is no server-rendered HTML to flash. Just wrap the app:

import { ThemeProvider } from 'uni-themes'

createRoot(document.getElementById('root')!).render(
  <ThemeProvider>
    <App />
  </ThemeProvider>,
)

(If you want the theme applied even before React loads, paste buildThemeScript()'s output from uni-themes/core into a <script> in index.html.)

API

ThemeProvider / ThemeScript options

Pass the same config to both.

| Option | Default | | | --- | --- | --- | | themes | ['light', 'dark'] | Selectable themes, excluding 'system' | | defaultTheme | 'system' | Falls back to 'light' when enableSystem: false | | enableSystem | true | Track prefers-color-scheme, offer 'system' | | attribute | 'class' | Or any data-* attribute, e.g. 'data-theme' | | storageKey | 'theme' | localStorage key and cookie name | | storage | 'localStorage' | 'cookie' enables server reading (localStorage still mirrored); 'none' disables persistence | | enableColorScheme | true | Keep <html style="color-scheme"> in sync | | disableTransitionOnChange | false | Suppress CSS transitions on theme change | | forcedTheme | — | Pin the rendered theme (per-page overrides) |

ThemeScript additionally accepts nonce.

useTheme()

const {
  theme,          // selected theme, e.g. 'system'
  resolvedTheme,  // 'system' resolved to 'light' | 'dark'
  systemTheme,    // OS preference, undefined on the server
  themes,
  forcedTheme,
  setTheme,
} = useTheme()

On the server (and hydration's first pass) theme is defaultTheme and resolvedTheme guesses 'light' for 'system' — gate theme-dependent text on mount if you need exactness; the DOM attribute itself is always correct before paint.

Subpath exports

| Entry | Contents | | --- | --- | | uni-themes | ThemeProvider, useTheme (client) | | uni-themes/script | ThemeScript, buildThemeScript (server-safe) | | uni-themes/core | Framework-agnostic store + script builder | | uni-themes/server | getThemeFromRequest, cookie helpers (any Request-based server) | | uni-themes/next | getTheme() via next/headers |

Migrating from next-themes

ThemeProvider and useTheme are drop-in for the common props (attribute, defaultTheme, enableSystem, storageKey, disableTransitionOnChange, forcedTheme, themes). Then move the script into your server layout's <head> via ThemeScript. Not carried over: value class mapping, scriptProps, useTheme().forcedTheme semantics differences are documented above.

License

MIT © Brendan Dash