devtools/docs/framework/svelte/basic-setup.md
Alem Tuzlak d7c5a93710
feat: add Svelte 5 adapter and devtools-utils Svelte factories (#366)
* docs: add Svelte devtools adapter design doc

* docs: add Svelte devtools implementation plan

* feat(svelte-devtools): add Svelte 5 adapter package

* feat(devtools-utils): add Svelte factory functions and build config

* fix: resolve knip issues and update svelte vite plugin to v6

* docs: add Svelte documentation

* chore: add changeset for Svelte adapter

* ci: apply automated fixes

* fix(svelte-devtools): mount once and tear down stale plugin components on update

- Mount the core exactly once: untrack props in the mount $effect so a prop
  change no longer destroys and rebuilds the entire devtools core (the update
  $effect already handles config/plugin changes reactively).
- update() now calls destroyAllComponents() before setConfig(), matching the
  Angular adapter — the core re-invokes render/name for the new plugin set, so
  without this the previous Svelte instances were orphaned and leaked.
- renderComponent() keys mounted components by container.id directly (the core
  always assigns one) instead of an empty-string fallback that could never be
  matched on destroy.
- vite.config: cast svelte() plugin as any, matching the vue/solid configs, to
  satisfy the vite 8 plugin types.

* chore(devtools-utils): add svelte devDependency for the svelte subpath build

The `./svelte` build type-checks svelte-importing source, so svelte must be
resolvable at build time (mirroring vite-plugin-solid for the solid build)
rather than relying on workspace hoisting of the optional peer.

* test(devtools-utils): cover svelte plugin and panel factories

Mirrors the existing solid class factory tests: createSveltePlugin shape +
NoOp behavior, and createSveltePanel mounting/tearing down a class-based core.

* ci: apply automated fixes

* refactor(devtools-utils): make createSveltePlugin generic over component props

Threads a TComponentProps generic through the svelte plugin factory (mirroring
createVuePlugin) so plugin props are type-checked against the component instead
of falling back to `any`. Addresses PR review feedback.

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-06-23 11:12:54 +02:00

1.8 KiB

title id
Basic setup basic-setup

TanStack Devtools provides you with an easy-to-use and modular client that allows you to compose multiple devtools into one easy-to-use panel.

Setup

Install the TanStack Devtools library. This will install the devtools core as well as provide you with the Svelte-specific adapter.

npm i @tanstack/svelte-devtools

Next, in the root of your application, import the TanStackDevtools component from @tanstack/svelte-devtools and add it to your template.

<script lang="ts">
  import { TanStackDevtools } from '@tanstack/svelte-devtools'
</script>

<main>
  <!-- Your app content -->
</main>
<TanStackDevtools />

Import the desired devtools and provide them to the TanStackDevtools component via the plugins prop along with a label for the menu.

<script lang="ts">
  import { TanStackDevtools } from '@tanstack/svelte-devtools'
  import type { TanStackDevtoolsSveltePlugin } from '@tanstack/svelte-devtools'
  import { SvelteQueryDevtoolsPanel } from '@tanstack/svelte-query-devtools'

  const plugins: TanStackDevtoolsSveltePlugin[] = [
    {
      name: 'Svelte Query',
      component: SvelteQueryDevtoolsPanel,
    },
  ]
</script>

<main>
  <!-- Your app content -->
</main>
<TanStackDevtools {plugins} />

Note: The Svelte adapter uses component (a Svelte component reference) instead of render (a JSX element) in plugin definitions. Additional props can be provided via the props field and are passed to the component on mount.

Finally, add any additional configuration you desire to the TanStackDevtools component. More information can be found under the TanStack Devtools Configuration section.