Blocking modal shown when the browser loses its connection, with a “back online” notice when it
returns. Retry never reloads the page: it calls onRetry (which may return a promise)
or re-checks the network, optionally by pinging pingUrl. When a toast context
exists, the reconnect notice is shown as a toast.
Simulate
Last event: none yet
CwOfflineOverlay exampleCopy code
<CwOfflineOverlay
forceOffline={simulateOffline}
onRetry={async () => {
await checkConnection();
}}
/>
<!-- Or let the overlay check the network itself: -->
<CwOfflineOverlay pingUrl="/api/health" />
API
Usage and API reference
CwOfflineOverlay can either follow the browser network state automatically or be forced into offline mode for testing. It also shows a short reconnected toast when the connection comes back.
How to think about it
Use real browser state in productionLeave `forceOffline` undefined when you want the component to respond to actual `online` and `offline` browser events.
Force the state in demos or testsPass `true` or `false` to `forceOffline` when you need deterministic UI state.
Decide what Retry should doIf you do not pass `onRetry`, the component falls back to reloading the page.
Props and callbacks
API
Type
Details
forceOffline
boolean | undefined
Forces the offline state for demos or tests. Leave undefined to use real browser state.
reconnectedDurationMs
Default: 3000
number
How long the "back online" toast stays visible.
onRetry
() => void
Retry handler. Falls back to `window.location.reload()` when omitted.
showRetryButton
Default: true
boolean
Shows or hides the retry button.
retryLabel
Default: Try Again
string
Text displayed inside the retry button.
pingUrl
string
URL requested by Retry to confirm the connection is back.
Copy-paste examples
Each snippet is a complete, working example you can paste into a Svelte 5 component.