Svelte SDK best practices

Developer preview

This feature is in developer preview. Use with caution as it may change unexpectedly. For more information, contact us.
  1. Use TypeScript. The SDK is TypeScript-first. Define Props interfaces using ComponentProps<T> for all components with proper types for each parameter.

  2. Use componentMap over resolveRenderer. The declarative component map is simpler, more readable, and easier to maintain than a resolver function. Reserve resolveRenderer for cases where your own code has to pick the component.

  3. Download manifest before build. Use npm run pull:manifest && vite build to ensure the manifest is always up-to-date. Never commit a stale manifest.

  4. Run publish:manifest after changes. Always run uniform context manifest publish after modifying signals, enrichments, or quirks. The manifest must be re-downloaded after publishing.

  5. Use flattenValues for assets. Always use flattenValues from @uniformdev/canvas for asset parameters rather than manually traversing the parameter structure.

  6. Access component prop for metadata. When you need raw parameter data, component IDs, variant info, or slot information, use the component prop.

  7. Use getScores() and getQuirks() for reactive data. Accessing context.scores directly does not trigger re-renders. Always use the reactive helpers for values that affect the UI.

  8. Keep the preview handler in place. The preview API endpoint and server hooks are required for visual editing in the Uniform Canvas editor. Do not remove them.

  9. Use edge together with the NESI hook. outputType="edge" without the hook in src/hooks.server.ts leaves the placeholders in the HTML. Use standard when you do not run that hook.

  10. Use the type__variant naming convention. For variant-specific component mappings, use double underscore (hero__dark) in the component map rather than creating separate resolver logic.