Skip to main content
Urbicon UI
source

NotificationListener

A headless SSE listener that fires a callback on each incoming notification and renders no DOM.

01 Usage

Basic

There is nothing to render here: the listener is headless. In your app, onNotification fires on each message from the stream, and the connection reconnects on drop with exponential backoff (1s–30s, up to 5 attempts).
<script lang="ts">
  import { NotificationListener } from '@urbicon-ui/auth';

  // `store` is your own notification state — the listener only delivers.
  const store = { add: (notification: unknown) => console.log('New notification:', notification) };
</script>

<NotificationListener
  onNotification={(n) => store.add(n)}
  onReconnect={(attempt) => console.log('Reconnecting…', attempt)}
/>

02 Accessibility

It renders no DOM at all

The component reads the stream off fetch and renders no markup, so it adds nothing to the accessibility tree and cannot be focused or reached by a screen reader. It can sit anywhere in the page.

Announcing an arrival is the consumer’s job

Because it renders nothing, a notification arriving over the stream is completely silent for assistive tech. If arrival should be announced, route onNotification somewhere that speaks: a live region of your own, a toast, or the NotificationBadge and NotificationCenter this component feeds.

Reconnection is silent

Dropped connections retry with exponential backoff and give up after maxReconnectAttempts, calling the onError and onReconnect callbacks rather than showing any UI. A stream the server refuses arrives as onRefused with the machine code, and the code decides what follows: a 429 connection_limit (too many tabs hold one open) is final, a rate limit waits out Retry-After, a missing session is retried every 30 seconds, a 5xx keeps the backoff. If a stalled or refused stream should be visible to the user, building that indicator is your job; silently missing notifications is the failure mode worth designing against.

03 API Reference

6 props
Prop
Type
Default
Description

04 Types

Local type definitions used by this component.

1 types
Name
Kind
Category
Used by
Description

05 Installation

Import

import { NotificationListener } from '@urbicon-ui/auth';