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

build-release-detection

v1.0.0

Published

Detect new deployments and notify users with a customizable modal or auto-reload. Works with React, Next.js, Vite, CRA and any framework.

Downloads

64

Readme

build-release-detection

Detect new deployments and notify users — or silently reload — without any server-side infrastructure.

After a deploy, browsers often serve stale JavaScript bundles from the old build. This causes blank screens, infinite loading, and confused users. This package polls a lightweight version.json file on your CDN/server and shows a non-intrusive modal when a new build is detected.


Features

  • Polls /version.json — tiny file, no backend needed
  • Update modal — built-in zero-dependency UI, fully customisable
  • Silent mode — auto-reload without any modal, great for hot-fixes
  • Snooze — "Remind me later" re-shows after a configurable interval
  • Hook-first — useBuildDetection works with any UI (MUI, shadcn, etc.)
  • TypeScript & JavaScript — ships full types, works in .js too
  • Accessible — focus trap, role="dialog", aria-modal, Escape key

Install

npm install build-release-detection
# or
yarn add build-release-detection

Quick Start (2 steps)

Step 1 — Generate version.json at build time

Add the generator to your build script in package.json:

{
  "scripts": {
    "build": "node node_modules/build-release-detection/scripts/generate-version.js && next build"
  }
}

For Vite / CRA:

"build": "node node_modules/build-release-detection/scripts/generate-version.js && vite build"

Also add to .gitignore:

public/version.json

Step 2 — Mount the provider

Next.js (Pages Router) — pages/_app.tsx:

import { BuildDetectionProvider } from "build-release-detection";

export default function App({ Component, pageProps }) {
  return (
    <BuildDetectionProvider>
      <Component {...pageProps} />
    </BuildDetectionProvider>
  );
}

React (Vite / CRA) — src/main.tsx:

import { BuildDetectionProvider } from "build-release-detection";

ReactDOM.createRoot(document.getElementById("root")!).render(
  <BuildDetectionProvider>
    <App />
  </BuildDetectionProvider>
);

That's it. On your next deploy the modal appears automatically.


Silent Mode (auto-reload, no modal)

For non-breaking deploys you can reload the page automatically with no user prompt.

At build time via env var:

SILENT_UPDATE=true npm run build

Or hardcode it in code:

<BuildDetectionProvider silent={true}>

Configuration

<BuildDetectionProvider> props

All props are optional.

| Prop | Type | Default | Description | |------|------|---------|-------------| | versionFileUrl | string | "/version.json" | URL of the version file to poll | | pollInterval | number | 60000 | Poll frequency in ms (1 minute) | | snoozeInterval | number | 900000 | "Remind later" duration in ms (15 min) | | silent | boolean | false | Auto-reload without showing the modal | | onNewBuild | (payload, prevId) => void | — | Callback fired when a new build is detected | | disabled | boolean | false | Completely disable polling | | title | string | "New version available 🚀" | Modal heading | | body | string | "A new version…" | Modal description | | reloadLabel | string | "Reload now" | Primary button label | | snoozeLabel | string | "Remind me in 15 min" | Snooze button label | | dismissLabel | string \| null | "×" | Close button label; null hides it | | overlayClassName | string | — | Class added to the backdrop element | | cardClassName | string | — | Class added to the modal card | | overlayStyle | CSSProperties | — | Inline styles for the backdrop | | cardStyle | CSSProperties | — | Inline styles for the card |


Using Your Own UI

Skip the built-in modal and wire up the hook directly:

import { useBuildDetection } from "build-release-detection";

function MyUpdateDialog() {
  const {
    isUpdateAvailable,
    latestVersion,
    currentBuildId,
    reloadNow,
    remindLater,
    dismiss,
  } = useBuildDetection({
    pollInterval: 60_000,
    snoozeInterval: 15 * 60_000,
    onNewBuild: (payload, prevId) => {
      console.log(`New build: ${payload.buildId} (was: ${prevId})`);
    },
  });

  if (!isUpdateAvailable) return null;

  // Use any UI library — MUI Dialog, shadcn Alert, etc.
  return (
    <div className="update-toast">
      <p>New version available!</p>
      <button onClick={reloadNow}>Reload</button>
      <button onClick={remindLater}>Later</button>
    </div>
  );
}

useBuildDetection return values

| Property | Type | Description | |----------|------|-------------| | isUpdateAvailable | boolean | true when a new build is detected and modal should show | | latestVersion | VersionPayload \| null | The latest payload from the server | | currentBuildId | string \| null | The buildId loaded when the user opened the app | | reloadNow | () => void | Hard-reload via window.location.href | | remindLater | () => void | Close modal and re-show after snoozeInterval | | dismiss | () => void | Close modal (won't reappear until the next new build) |


generate-version.js Environment Variables

| Variable | Default | Description | |----------|---------|-------------| | SILENT_UPDATE | "false" | Set to "true" to embed isSilent: true in the JSON | | VERSION_FILE_PATH | public/version.json | Output path for the generated file | | BUILD_ID | auto-generated | Override the buildId (e.g. your CI commit SHA) |

Using CI commit SHA as buildId:

BUILD_ID=$GITHUB_SHA npm run build

version.json Shape

{
  "buildId": "m3k1a2b-3f9c12d4",
  "isSilent": false,
  "builtAt": "2026-04-14T10:30:00.000Z"
}

How It Works

User opens app
     │
     ▼
Fetch version.json → store buildId as baseline (no modal)
     │
     ▼ (every pollInterval)
Fetch version.json
     │
     ├─ buildId unchanged ──→ nothing
     │
     └─ buildId changed!
           │
           ├─ isSilent: true ──→ window.location.reload()
           │
           └─ isSilent: false
                 │
                 ├─ snooze active ──→ wait
                 │
                 └─ show modal
                       ├─ Reload Now   ──→ window.location.reload()
                       └─ Remind Later ──→ snooze for snoozeInterval

Polling pauses automatically when the browser tab is hidden and resumes when the user switches back.


Testing Locally

  1. Build your app: npm run build
  2. Serve: npx serve out (Next.js static) or npx vite preview
  3. Lower the poll interval to 10s for testing:
    <BuildDetectionProvider pollInterval={10_000}>
  4. Simulate a new deploy:
    node -e "
      const fs = require('fs');
      fs.writeFileSync(
        'out/version.json',
        JSON.stringify({ buildId: Date.now().toString(), isSilent: false })
      )
    "
  5. Wait 10 seconds — the modal appears.
  6. Revert pollInterval before production deploy.

Deploy Commands

# Standard deploy — shows modal to users
npm run build

# Silent deploy — auto-reloads without a modal
SILENT_UPDATE=true npm run build

# Deploy with CI commit SHA as buildId
BUILD_ID=$GITHUB_SHA npm run build