Notifications

Knit tells readers when someone replies to their posts and comments, or when their reply is approved, and tells the site's admins about new reports, replies waiting for approval and new messages from readers. Each person gets a list under a bell icon on your site, and can also receive emails.

The bell

Put NotificationBell in your header, inside KnitProvider. It shows an unread badge, a list of notifications and a settings panel. It renders nothing while the reader is signed out, and on sites whose plan has no list (see Plans and limits).

notifications-bell.tsx
"use client";

import { NotificationBell } from "@knit/react/ui";

// Put the bell in your header, inside <KnitProvider>. It renders nothing for signed-out readers
export function SiteHeaderTools() {
  return <NotificationBell postBasePath="/blog" />;
}
PropUse
postBasePathBase path of your post pages (default /posts). Use the same value as PostList.
getPostHrefBuild a link yourself. It receives the post's slug, or its ID when the post has no slug.
onNavigateHandle the click yourself, for example with your router.
pollIntervalMsHow often the unread count is refreshed (default 60 seconds, 0 to stop).
classNameClass added to the bell's wrapper.

A notification about a post the reader can no longer see (deleted, or no longer shared with them) only says that the post is unavailable. Its content is never shown.

What is sent

EventSent to
Someone replies to your postThe post's author
Someone replies to your commentThe comment's author
A comment is reportedThe site's owner, and editors on the Team plan
A reply is waiting for approvalThe site's owner, and editors on the Team plan
Your reply was approvedThe reply's author
A reader sends a new message or a follow-up in a participants-only spaceThe site's owner, and editors on the Team plan

Nobody is notified about their own actions. A reply that needs approval notifies the post's author only when it is approved. The email for a waiting reply is skipped if it was approved or rejected before it was sent. Messages in a participants-only space are shown to site admins; a reader is told about replies to their own message like any other reply. Emails never include the text of a message.

Settings

Readers choose, for each kind of event, whether it appears in the list and whether it is emailed. A choice can apply to all sites or to one site, and a site can be muted completely. Email is on by default for events that need an admin to act (reports, replies waiting for approval, messages from readers) and off for events about your own posts (replies, approvals). Every email has an unsubscribe link, and notifications of one kind about the same post that arrive within about 10 minutes are combined into one email. Before sending, Knit checks the settings, permissions and the post again, so an email about a deleted reply or a handled report is not sent. The link in the email opens the page where the reply, message or report was sent: @knit/core sends the current page URL (origin and path only; the query string and fragment are never sent) together with the reply, the message or the report, and the server stores it only if its origin is one of the site's allowed origins. If there is no valid URL (for example an older client), the email links to the top of the site's first allowed origin. You can pass your own URL as pageUrl to createPost (replies, and root posts such as contact messages) and createReport.

The settings are inside the bell. To put them on a page of their own, use NotificationSettings. It shows only what can be changed on the site, and nothing when there is nothing to change.

notifications-settings.tsx
"use client";

import { NotificationSettings } from "@knit/react/ui";

// A page for notification settings, inside <KnitProvider>. It renders nothing for signed-out readers
export function NotificationSettingsPage() {
  return <NotificationSettings />;
}

Plans and limits

FreePersonalTeam
Bell and listNoYesYes
Emails per month, per site (replies, approvals, waiting replies, messages from readers)None5002,000
Report emails per day, per site202020

Report emails do not count toward the monthly limit. Over a limit, no email is sent; on plans with the bell, the notification stays in the list. Days and months are counted in UTC.

Emails for editor invitations and site transfers are separate from these notifications. They go to the invited person as soon as the invitation is created (transfers on every plan including Free, editor invitations on plans with editor seats), don't count toward the limits above, and aren't affected by notification settings or unsubscribing.

Site admins can also change these settings in the Notifications tab of site management (the ⚙ button). On a Free site, which has no bell, this is where they turn report emails back on after unsubscribing, with nothing extra to build. The ⚙ button comes with PostList (unless showToolbar={false}) and PostDetail. If your setup shows no ⚙ button, put NotificationSettings on a page your admins use. You can also place OwnerPanel and a button that opens it (OwnerPanel.Trigger) inside SiteAdmin.Root (see Components).

Headless

Build your own bell with the Notifications and NotificationSettings primitives from @knit/react/primitives, or with the hooks useKnitNotifications (list, unread count, read state) and useKnitNotificationPreferences (settings).

notifications-headless.tsx
"use client";

import { useKnitNotifications } from "@knit/react";

// The unread count and list are yours to render; Knit handles polling and read state
export function MyNotificationLink() {
  const { unreadCount, items, markRead } = useKnitNotifications({ pollIntervalMs: 30_000 });
  return (
    <nav>
      <a href="/notifications">Notifications ({unreadCount})</a>
      <ul>
        {items.map((n) => (
          <li key={n.id}>
            <button type="button" onClick={() => void markRead(n.id)}>
              {n.target ? (n.target.rootTitle ?? n.target.excerpt) : "Unavailable"}
            </button>
          </li>
        ))}
      </ul>
    </nav>
  );
}

Messages live under messages.notifications; see Languages.