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 🙏

© 2024 – Pkg Stats / Ryan Hefner

next-deploy-notifications

v0.1.6

Published

This library lets your users know when you've deployed a new version of your Next.js application.

Downloads

3,586

Readme

Next.js Deploy Notifications

This library lets your users know when you've deployed a new version of your Next.js application.

Deploy notification

import { useHasNewDeploy } from "next-deploy-notifications";

function App() {
  let { hasNewDeploy } = useHasNewDeploy();

  return (
    <div>
      <main>Your app</main>

      {hasNewDeploy && (
        <Notification>
          New version available!
          <button onClick={() => window.location.reload()}>Refresh</button>
        </Notification>
      )}
    </div>
  );
}

Installation

npm install next-deploy-notifications

# or

yarn add next-deploy-notifications

Setup

API Route

You'll first need to create a new API route in order for this library to work correctly. Paste the following into pages/api/has-new-deploy.js.

// pages/api/has-new-deploy.js

export { APIRoute as default } from "next-deploy-notifications/api";

Usage

The useHasNewDeploy hook will tell you when a new version of your application has been deployed. This hook returns a hasNewDeploy property that's true whenever there's a new deploy.

import { useHasNewDeploy } from "next-deploy-notifications";

function Page() {
  let { hasNewDeploy } = useHasNewDeploy();

  return hasNewDeploy && <div>A new deploy is available!</div>;
}

The useHasNewDeploy hook will check for a new version of your application every 30 seconds. It will suspend checking for new versions if the application window is not focused by the user.

Development environments

When running in development this library will treat the current git commit as your application's version. If the latest git commit sha changes then useHasNewDeploy hook will react as if there was a new deploy.

To trigger a new commit without checking in code, you can use the following command:

git commit -m "Trigger useHasNewDeploy!" --allow-empty

It's worth noting that it can take up to 30 seconds for the application to see the git commit. You'll also need to make sure the application window is focused.

Production environments

This library works out of the box with the following hosting providers:

  • Vercel

    Note: Make sure you're application has "Automatically expose System Environment Variables" checked. This can be found in the Vercel dashboard under Settings > Environment variables.

  • Render

Other hosts

If your web host is not listed above you can add a custom version function in order to make this library work properly.

// pages/api/has-new-deploy.js

import { APIRoute } from "next-deploy-notifications/api";

export APIRoute.configure({
  // Return your app's version here.
  version: () => "123"
})

The version function should return the current version of the application as a string. You can read from process.env, the file system, or even make network calls here.

If needed, version can be an async function or return a promise.

Whenever the value returned by version changes your application's users will be notified of a new deploy.

Please open a new issue if you are adding a custom version function for a well known web host. I'd love to make common hosts supported by default!