Svelte / SvelteKit SDK
Developer preview
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 theUniformContextprovider and reactive helpers.
Quick start#
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:
Clone the examples repository and open the starter:
git clone --depth 1 https://github.com/uniformdev/examples.git cd examples/examples/sveltekit-starterSet
NPM_TOKENto your npm access token from Uniform. The examples include edge-side personalization, which requires private packages, and their.npmrcreads the token from this variable. If you don't have an access token, request one from Uniform Support.export NPM_TOKEN=<your-npm-token>Install the dependencies:
npm installCreate a
.envfile withUNIFORM_API_KEY,UNIFORM_PROJECT_ID, andUNIFORM_PREVIEW_SECRET. See Environment variables for where to find the values.Push the starter's content to your project:
npm run push:contentUse a new, empty project. The push runs in
mirrormode, so entities in the project that aren't in the starter'suniform-datafolder move to Trash. See sync commands.Start the dev server:
npm run devThe
devscript downloads the personalization manifest before it starts Vite.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.
Svelte vs SvelteKit#
The Uniform Svelte SDK is split between framework-agnostic Svelte packages and SvelteKit-specific packages:
| Concern | Svelte package | SvelteKit 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.
Guides#
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