Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-actors-lose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/vue-query-devtools': minor
---

feat(vue-query-devtools): Add embedded panel mode
43 changes: 43 additions & 0 deletions docs/framework/vue/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bun add @tanstack/vue-query-devtools

By default, Vue Query Devtools are only included in bundles when `process.env.NODE_ENV === 'development'`, so you don't need to worry about excluding them during a production build.

## Floating Mode

Devtools will be mounted as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.

Place the following code as high in your Vue app as you can. The closer it is to the root of the page, the better it will work!
Expand Down Expand Up @@ -79,6 +81,47 @@ import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
- Default behavior will apply the devtool's styles to the head tag within the DOM.
- Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.

## Embedded Mode

Embedded mode will show the development tools as a fixed element in your application, so you can use our panel in your own development tools.

Place the following code as high in your React app as you can. The closer it is to the root of the page, the better it will work!

```vue
<script setup>
import { VueQueryDevtoolsPanel } from '@tanstack/vue-query-devtools'
const isDevtoolsOpen = ref(false)
function toggleDevtools() {
isDevtoolsOpen.value = !isDevtoolsOpen.value
}
</script>

<template>
<h1>The app!</h1>
<button @click="toggleDevtools">Open Devtools</button>
<VueQueryDevtoolsPanel v-if="isDevtoolsOpen" :onClose="toggleDevtools" />
</template>
```

### Options

- `style?: React.CSSProperties`
- Custom styles for the devtools panel
- Default: `{ height: '500px' }`
- Example: `{ height: '100%' }`
- Example: `{ height: '100%', width: '100%' }`
- `onClose?: () => unknown`
- Callback function that is called when the devtools panel is closed
- `client?: QueryClient`,
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
- Use this to predefine some errors that can be triggered on your queries. Initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
- `styleNonce?: string`
- Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
- `shadowDOMTarget?: ShadowRoot`
- Default behavior will apply the devtool's styles to the head tag within the DOM.
- Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.

## Traditional Devtools

Vue Query will seamlessly integrate with the [Official Vue devtools](https://github.com/vuejs/devtools-next), adding custom inspector and timeline events.
Expand Down
49 changes: 49 additions & 0 deletions packages/vue-query-devtools/src/devtoolsPanel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { computed, onMounted, onScopeDispose, ref, watchEffect } from 'vue'
import { onlineManager, useQueryClient } from '@tanstack/vue-query'
import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
import type { StyleValue } from 'vue'
import type { DevtoolsPanelOptions } from './types'

const props = defineProps<DevtoolsPanelOptions>()
const style = computed<StyleValue>(() => {
return {
height: '500px',
...props.style,
}
})

const div = ref<HTMLElement>()
const client = props.client || useQueryClient()
const devtools = new TanstackQueryDevtoolsPanel({
client,
queryFlavor: 'Vue Query',
version: '5',
onlineManager,
buttonPosition: 'bottom-left',
position: 'bottom',
initialIsOpen: true,
errorTypes: props.errorTypes,
styleNonce: props.styleNonce,
shadowDOMTarget: props.shadowDOMTarget,
hideDisabledQueries: props.hideDisabledQueries,
onClose: props.onClose,
})

watchEffect(() => {
devtools.setOnClose(props.onClose ?? (() => {}))
devtools.setErrorTypes(props.errorTypes || [])
})

onMounted(() => {
devtools.mount(div.value as HTMLElement)
})

onScopeDispose(() => {
devtools.unmount()
})
</script>

<template>
<div :style="style" className="tsqd-parent-container" ref="div"></div>
</template>
11 changes: 10 additions & 1 deletion packages/vue-query-devtools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import devtools from './devtools.vue'
import devtoolsPanel from './devtoolsPanel.vue'
import type { DefineComponent } from 'vue'
import type { DevtoolsOptions } from './types'
import type { DevtoolsOptions, DevtoolsPanelOptions } from './types'

export const VueQueryDevtools = (
process.env.NODE_ENV !== 'development'
Expand All @@ -9,3 +10,11 @@ export const VueQueryDevtools = (
}
: devtools
) as DefineComponent<DevtoolsOptions, {}, unknown>

export const VueQueryDevtoolsPanel = (
process.env.NODE_ENV !== 'development'
? function () {
return null
}
: devtoolsPanel
) as DefineComponent<DevtoolsPanelOptions, {}, unknown>
36 changes: 36 additions & 0 deletions packages/vue-query-devtools/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,39 @@ export interface DevtoolsOptions {
*/
hideDisabledQueries?: boolean
}

export interface DevtoolsPanelOptions {
/**
* Custom instance of QueryClient
*/
client?: QueryClient
/**
* Use this so you can define custom errors that can be shown in the devtools.
*/
errorTypes?: Array<DevtoolsErrorType>
/**
* Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
*/
styleNonce?: string
/**
* Use this so you can attach the devtool's styles to specific element in the DOM.
*/
shadowDOMTarget?: ShadowRoot

/**
* Custom styles for the devtools panel
* @default { height: '500px' }
* @example { height: '100%' }
* @example { height: '100%', width: '100%' }
*/
style?: React.CSSProperties

/**
* Callback function that is called when the devtools panel is closed
*/
onClose?: () => unknown
/**
* Set this to true to hide disabled queries from the devtools panel.
*/
hideDisabledQueries?: boolean
}
Loading