Skip to content

Network & Offline

firekitNetwork is a reactive singleton that tracks browser connectivity, Firestore sync state, and unconfirmed writes. It initializes automatically on first access.

<script lang="ts">
import { firekitNetwork } from 'svelte-firekit';
</script>
{#if !firekitNetwork.online}
<p>You're offline. Changes will sync when reconnected.</p>
{/if}
{#if firekitNetwork.hasPendingWrites}
<p>Saving...</p>
{:else}
<p>All changes saved</p>
{/if}
PropertyTypeDescription
onlinebooleanBrowser has network connectivity
syncedbooleanAll Firestore snapshots are in sync with the server
hasPendingWritesbooleanThere are unconfirmed Firestore writes
initializedbooleanThe network store has been initialized
errorNetworkError | nullLast error from network operations
firestoreEnabledbooleanFirestore network is currently enabled

Call trackWrite() after performing a Firestore mutation to show a pending state until the write is acknowledged.

import { firekitNetwork, firekitMutations } from 'svelte-firekit';
await firekitMutations.update('posts/my-post', { title: 'Updated' });
firekitNetwork.trackWrite();
// firekitNetwork.hasPendingWrites is now true until Firestore confirms the write

Force Firestore into offline mode or reconnect programmatically.

// Go offline — all reads come from cache, writes are queued
await firekitNetwork.goOffline();
// Reconnect — queued writes are sent to the server
await firekitNetwork.goOnline();

The <NetworkStatus> component provides a declarative way to render UI based on network and sync state using Svelte 5 snippets.

<script lang="ts">
import { NetworkStatus } from 'svelte-firekit';
</script>
<NetworkStatus>
{#snippet online()}
<span class="dot green" />
{/snippet}
{#snippet offline()}
<span class="dot red">You are offline</span>
{/snippet}
{#snippet pending()}
<span>Saving...</span>
{/snippet}
</NetworkStatus>
NameRendered when
onlineBrowser is online and all writes are synced
offlineBrowser is offline
pendingThere are pending Firestore writes