Svelte / SvelteKit SDK

Developer preview

This feature is in developer preview. Use with caution as it may change unexpectedly. For more information, contact us.

The Uniform SDK for Svelte and SvelteKit provides a full integration between Uniform DXP and Svelte applications. It spans three complementary packages:

  • @uniformdev/canvas-svelte: Svelte components for rendering Canvas compositions (UniformComposition, UniformSlot, UniformText, UniformRichText) and contextual editing support.
  • @uniformdev/canvas-sveltekit: SvelteKit-specific integrations: route loading (createUniformLoad), server hooks (createUniformHandle), preview handlers, and ISR configuration.
  • @uniformdev/context-svelte: Svelte bindings for Uniform Context, enabling personalization, A/B testing, visitor scoring, and behavior tracking via the UniformContext provider and reactive helpers.

Start from an example project for a working SvelteKit app without installing and wiring up the SDK yourself. Each example has the Uniform packages, routes, preview handler, and component map in place, and comes with content for your Uniform project.

  • SvelteKit Starter: Minimal starter with composition rendering, component mapping, and visual editing.
  • SvelteKit Demo: Full-featured demo with personalization, A/B testing, and edge middleware.

To run the starter:

  1. Clone the examples repository and open the starter:

    git clone --depth 1 https://github.com/uniformdev/examples.git cd examples/examples/sveltekit-starter
  2. Set NPM_TOKEN to your npm access token from Uniform. The examples include edge-side personalization, which requires private packages, and their .npmrc reads the token from this variable. If you don't have an access token, request one from Uniform Support.

    export NPM_TOKEN=<your-npm-token>
  3. Install the dependencies:

    npm install
  4. Create a .env file with UNIFORM_API_KEY, UNIFORM_PROJECT_ID, and UNIFORM_PREVIEW_SECRET. See Environment variables for where to find the values.

  5. Push the starter's content to your project:

    npm run push:content

    Use a new, empty project. The push runs in mirror mode, so entities in the project that aren't in the starter's uniform-data folder move to Trash. See sync commands.

  6. Start the dev server:

    npm run dev

    The dev script downloads the personalization manifest before it starts Vite.

  7. In Canvas, set the preview URL to http://localhost:5173/preview, the starter's preview route.

The demo uses the same steps in examples/sveltekit-demo. To add the SDK to an existing SvelteKit app instead, follow Manual setup.


The Uniform Svelte SDK is split between framework-agnostic Svelte packages and SvelteKit-specific packages:

ConcernSvelte packageSvelteKit package
Composition rendering@uniformdev/canvas-svelte
Components (UniformText, UniformSlot, etc.)@uniformdev/canvas-svelte
Context provider@uniformdev/context-svelte
Reactive helpers (getScores, getQuirks)@uniformdev/context-svelte
Route loading (createUniformLoad)@uniformdev/canvas-sveltekit
Server hooks (createUniformHandle)@uniformdev/canvas-sveltekit
Preview handler@uniformdev/canvas-sveltekit
ISR configuration@uniformdev/canvas-sveltekit
Edge personalization (NESI)@uniformdev/context-edge-sveltekit

If you are using SvelteKit (recommended), install all packages. The Svelte-only packages (canvas-svelte, context-svelte) can also be used in non-SvelteKit Svelte setups, but you will need to handle routing and data fetching yourself.


How it works

Follow a request from the catch-all route to the rendered composition

Manual setup

Install the packages and set up the layout, hooks, routes, and preview handler

Build components

Map Uniform components to Svelte components and render parameters

Slots

Render the child components of a slot with UniformSlot

Personalization and testing

Render variants in the page or with the NESI hook

Client-side context

Read and update visitor scores and quirks

Contextual editing

Support visual editing in Canvas

Manifest management

Download and publish the personalization manifest

ISR

Cache and revalidate pages on Vercel

Best practices

Recommendations for components, personalization, and manifests

Recipes

Code for common tasks

Troubleshooting

Fixes for common problems

SDK reference

Exports and type definitions