Installation
Install the package
Install the DevTools package as a dev dependency:
The DevTools package version is
6.0.4 and is compatible with @tanstack/svelte-query 6.0.0+.Features
The Svelte Query DevTools provide powerful debugging capabilities:Query Explorer
View all queries in your application:- Active queries - Currently mounted and in use
- Inactive queries - Cached but not mounted
- Stale queries - Data that needs refetching
- Fresh queries - Recently fetched data
Query Inspector
Click on any query to see detailed information:- Query key
- Query status (pending, error, success)
- Last updated timestamp
- Data preview
- Query configuration
- Observers count
- Query tags
Mutation Inspector
Track all mutations in your app:- Mutation status
- Variables passed to mutation
- Mutation response data
- Error information
Actions
Perform actions on queries:- Refetch - Manually trigger a refetch
- Invalidate - Mark query as stale
- Remove - Remove query from cache
- Reset - Reset error state
Configuration
Customize the DevTools appearance and behavior:+layout.svelte
Options
Set to
true to have the DevTools open by default on page load.Position of the toggle button. Options:
'top-left', 'top-right', 'bottom-left', 'bottom-right'.Position of the DevTools panel. Options:
'top', 'bottom', 'left', 'right'.Custom QueryClient instance. By default, uses the client from context.
Custom error types to display in the DevTools.
Nonce for Content Security Policy (CSP). Used for inline styles.
Attach DevTools styles to a specific Shadow DOM target.
Hide disabled queries from the query list.
Usage Examples
Basic Setup
The simplest configuration:+layout.svelte
Custom Position
Position the DevTools on the right side:Open by Default
Useful during development:With SvelteKit
Only show DevTools in development:+layout.svelte
The DevTools are automatically tree-shaken from production builds, but you can add an explicit check for clarity.
DevTools Interface
Query States
Queries are color-coded by state:- Green - Fresh data (within
staleTime) - Yellow - Stale data (needs refetch)
- Gray - Inactive (cached but not mounted)
- Blue - Fetching (currently refetching)
- Red - Error state
Filter Queries
Use the search bar to filter queries:Sort Queries
Sort queries by:- Query key
- Last updated
- Observer count
- Status
Debugging Tips
Inspect query keys
Click on a query to see its full query key structure. This helps ensure your keys are unique and properly structured.
Monitor refetch behavior
Watch the “Last Updated” timestamp to see when queries refetch. This helps debug issues with:
staleTimeconfiguration- Window focus refetching
- Interval refetching
Check observer count
The observer count shows how many components are using a query. If it’s 0, the query is inactive and may be garbage collected.
Advanced Features
Custom Error Types
Display custom error information:Shadow DOM Integration
For apps using Shadow DOM:CSP Nonce Support
For Content Security Policy compliance:Performance
The DevTools are designed to have minimal performance impact:- Lazy loaded - Only imported when used
- Development only - Automatically removed in production
- Efficient updates - Only re-renders when query state changes
- Virtual scrolling - Handles thousands of queries efficiently
Keyboard Shortcuts
Use keyboard shortcuts for faster navigation:Cmd/Ctrl + K- Toggle DevTools/- Focus search↑/↓- Navigate queriesEnter- Open selected queryEsc- Close query detail
Troubleshooting
DevTools not appearing
Check that:- You’re in development mode
- The component is inside
QueryClientProvider - The package is installed correctly
DevTools in production
The DevTools should be automatically removed. If they appear in production:- Check your build configuration
- Ensure you’re using a production build:
Styling conflicts
If DevTools styles conflict with your app:- Use
shadowDOMTargetto isolate styles - Adjust
positionandbuttonPosition - Apply custom CSS overrides
Implementation Details
The DevTools component is implemented in/packages/svelte-query-devtools/src/Devtools.svelte and uses:
- Svelte 5 runes -
$state,$effect,$derived - Dynamic import - Lazy loads
@tanstack/query-devtools - Environment detection -
DEVandBROWSERfromesm-env - QueryClient integration - Uses
useQueryClientandonlineManager
Next Steps
Explore Advanced Features
Learn about SSR, persistence, and more advanced patterns.Advanced Guides →
Production Deployment
Learn best practices for deploying Svelte Query apps.Best Practices →