Skip to main content

Svelte SDK API Reference

Complete API documentation for the Svelte SDK.

Provider Props

PropTypeRequiredDescription
clientReplaneNoPre-created client (alternative to connection)
connectionConnectOptions | nullYes*Connection options (see below), or null to skip connection
defaultsRecord<string, unknown>NoDefault values if server is unavailable
contextRecord<string, unknown>NoDefault context for override evaluations
snapshotReplaneSnapshotNoSnapshot for SSR hydration
loggerReplaneLoggerNoCustom logger (default: console)
loaderSnippetNoSnippet to show while loading
asyncbooleanNoConnect asynchronously (renders immediately with defaults)

*Required when not using the client prop. Pass null to explicitly skip connection.

Connection Options

OptionTypeRequiredDescription
baseUrlstringYesReplane server URL
sdkKeystringYesSDK key for authentication
connectTimeoutMsnumberNoSDK connection timeout (default: 5000)
requestTimeoutMsnumberNoTimeout for SSE requests (default: 2000)
retryDelayMsnumberNoBase delay between retries (default: 200)
inactivityTimeoutMsnumberNoSSE inactivity timeout (default: 30000)
fetchFntypeof fetchNoCustom fetch implementation

See the JavaScript SDK documentation for more details.

config

Creates a reactive store for a config value. Similar to readable() or derived().

<script>
import { config } from '@replanejs/svelte'

// Returns a Svelte readable store
const featureEnabled = config<boolean>('featureEnabled')

// With evaluation context
const greeting = config<string>('greeting', {
context: { userId: '123', isPremium: true }
})
</script>

{#if $featureEnabled}
<p>{$greeting}</p>
{/if}

getReplane

Gets the Replane client from context.

<script>
import { getReplane } from '@replanejs/svelte'

const replane = getReplane()

function handleClick() {
const value = replane.get('some-config')
console.log(value)
}
</script>

<button onclick={handleClick}>Get Config</button>

configFrom

Creates a reactive store from a client directly (without context). Type-safe with full autocomplete for config names.

<script>
import { configFrom, getReplane } from '@replanejs/svelte'

const replane = getReplane()

const featureEnabled = configFrom(replane, 'featureEnabled')
</script>

{#if $featureEnabled}
<p>Feature is enabled!</p>
{/if}

ReplaneContext

Context component that provides the Replane client to your component tree.

With a pre-created client

<script>
import { ReplaneContext, Replane } from '@replanejs/svelte';

const client = new Replane();
await client.connect({
baseUrl: 'https://replane.example.com',
sdkKey: 'your-sdk-key',
});
</script>

<ReplaneContext {client}>
<App />
</ReplaneContext>

With connection (client managed internally)

<script>
import { ReplaneContext } from '@replanejs/svelte'

const connection = {
baseUrl: 'https://replane.example.com',
sdkKey: 'your-sdk-key'
}
</script>

<svelte:boundary onerror={(e) => console.error(e)}>
<ReplaneContext {connection}>
<App />

{#snippet loader()}
<p>Loading...</p>
{/snippet}
</ReplaneContext>

{#snippet failed(error)}
<p>Error: {error.message}</p>
{/snippet}
</svelte:boundary>

With async mode

<script>
import { ReplaneContext } from '@replanejs/svelte'

const connection = {
baseUrl: 'https://replane.example.com',
sdkKey: 'your-sdk-key'
}

const defaults = {
featureEnabled: false
}
</script>

<ReplaneContext {connection} {defaults} async>
<App />
</ReplaneContext>

createTypedConfig

Creates a typed version of config with autocomplete for config names.

import { createTypedConfig } from '@replanejs/svelte'

interface AppConfigs {
theme: { darkMode: boolean; primaryColor: string }
features: { betaEnabled: boolean }
}

export const appConfig = createTypedConfig<AppConfigs>()

createTypedReplane

Creates a typed version of getReplane.

import { createTypedReplane } from '@replanejs/svelte'

export const getAppReplane = createTypedReplane<AppConfigs>()

getReplaneSnapshot

Fetches a snapshot for SSR. Use in +layout.server.ts or +page.server.ts.

import { getReplaneSnapshot } from '@replanejs/svelte'

const snapshot = await getReplaneSnapshot({
connection: { baseUrl: '...', sdkKey: '...' }
})