In your vite.config.ts file add toolbar plugin for vite:
vite.config.ts
import { sveltekit } from '@sveltejs/kit/vite';import { defineConfig } from 'vite';import { vercelToolbar } from '@vercel/toolbar/plugins/vite';export default defineConfig({ plugins: [sveltekit(), vercelToolbar()],});
Next render the toolbar in your layout so that it's visible for your visitors. This renders the toolbar for all visitors. In production you may want to render it for team members only:
src/routes/+layout.svelte
<script lang="ts"> import type { LayoutData } from './$types'; import { mountVercelToolbar } from '@vercel/toolbar/vite'; import { onMount } from 'svelte'; onMount(() => mountVercelToolbar()); export let data: LayoutData;</script><main> {data.title} <!-- +page.svelte is rendered in this <slot> --> <slot /></main>
Run your application locally to check that things are working:
npm run dev
You will see an error about SvelteKitError: Not found: /.well-known/vercel/flags. This happens because we already created the FLAGS_SECRET but we did not set up the flags package yet.
So let’s do this next.
Notice how the toolbar knows about the flag's name, description and the link to where the flag can be managed. All of these are communicated through the /.well-known/vercel/flags endpoint, which is set up automatically by the createHandle call we made in hooks.server.ts.
This hook intercepts all requests and responds with the application's feature flags when it sees the authenticated request made by Vercel Toolbar to load your application's feature flags.
Vercel Toolbar also shows the current value of your feature flag, in this case false. This value could be different for each visitor, so it can not be loaded along with the information about the feature flag itself.
Instead, when a feature flag gets evaluated on the server, the hook configured in hooks.server.ts injects a <script data-flag-values /> tag into the response, which contains encrypted information about the feature flag values used when generating that response. This means even if your flag would return Math.random() you would still be able to see the exact value used when generating the page.