Skip to content

Commit c63713f

Browse files
AlemTuzlakautofix-ci[bot]TkDodooscartbeaumont
authored
feat: add solid devtools panel export to solid devtools (#9551)
* feat: add solid devtools panel export to solid devtools * ci: apply automated fixes * fix knip + eslint --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc> Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
1 parent 6402d75 commit c63713f

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

packages/react-query-devtools/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ export const ReactQueryDevtoolsPanel: (typeof DevtoolsPanel)['ReactQueryDevtools
1616
return null
1717
}
1818
: DevtoolsPanel.ReactQueryDevtoolsPanel
19+
20+
export type DevtoolsPanelOptions = DevtoolsPanel.DevtoolsPanelOptions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { createEffect, createMemo, onCleanup, onMount } from 'solid-js'
2+
import { onlineManager, useQueryClient } from '@tanstack/solid-query'
3+
import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
4+
import type { DevtoolsErrorType } from '@tanstack/query-devtools'
5+
import type { QueryClient } from '@tanstack/solid-query'
6+
7+
export interface DevtoolsPanelOptions {
8+
/**
9+
* Custom instance of QueryClient
10+
*/
11+
client?: QueryClient
12+
/**
13+
* Use this so you can define custom errors that can be shown in the devtools.
14+
*/
15+
errorTypes?: Array<DevtoolsErrorType>
16+
/**
17+
* 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.
18+
*/
19+
styleNonce?: string
20+
/**
21+
* Use this so you can attach the devtool's styles to specific element in the DOM.
22+
*/
23+
shadowDOMTarget?: ShadowRoot
24+
25+
/**
26+
* Custom styles for the devtools panel
27+
* @default { height: '500px' }
28+
* @example { height: '100%' }
29+
* @example { height: '100%', width: '100%' }
30+
*/
31+
style?: CSSStyleValue
32+
33+
/**
34+
* Callback function that is called when the devtools panel is closed
35+
*/
36+
onClose?: () => unknown
37+
/**
38+
* Set this to true to hide disabled queries from the devtools panel.
39+
*/
40+
hideDisabledQueries?: boolean
41+
}
42+
43+
export default function SolidQueryDevtoolsPanel(props: DevtoolsPanelOptions) {
44+
const queryClient = useQueryClient()
45+
const client = createMemo(() => props.client || queryClient)
46+
let ref!: HTMLDivElement
47+
const { errorTypes, styleNonce, shadowDOMTarget, hideDisabledQueries } = props
48+
const devtools = new TanstackQueryDevtoolsPanel({
49+
client: client(),
50+
queryFlavor: 'Solid Query',
51+
version: '5',
52+
onlineManager,
53+
buttonPosition: 'bottom-left',
54+
position: 'bottom',
55+
initialIsOpen: true,
56+
errorTypes,
57+
styleNonce,
58+
shadowDOMTarget,
59+
onClose: props.onClose,
60+
hideDisabledQueries,
61+
})
62+
createEffect(() => {
63+
devtools.setClient(client())
64+
})
65+
createEffect(() => {
66+
devtools.setOnClose(props.onClose ?? (() => {}))
67+
})
68+
69+
createEffect(() => {
70+
devtools.setErrorTypes(props.errorTypes || [])
71+
})
72+
73+
onMount(() => {
74+
devtools.mount(ref)
75+
onCleanup(() => devtools.unmount())
76+
})
77+
78+
return (
79+
<div
80+
style={{ height: '500px', ...props.style }}
81+
class="tsqd-parent-container"
82+
ref={ref}
83+
/>
84+
)
85+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import { isDev } from 'solid-js/web'
22
import clientOnly from './clientOnly'
33
import type SolidQueryDevtoolsComp from './devtools'
4+
import type SolidQueryDevtoolsCompPanel from './devtoolsPanel'
45

56
export const SolidQueryDevtools: typeof SolidQueryDevtoolsComp = isDev
67
? clientOnly(() => import('./devtools'))
78
: function () {
89
return null
910
}
11+
12+
export const SolidQueryDevtoolsPanel: typeof SolidQueryDevtoolsCompPanel = isDev
13+
? clientOnly(() => import('./devtoolsPanel'))
14+
: function () {
15+
return null
16+
}
17+
18+
export type { DevtoolsPanelOptions } from './devtoolsPanel'

0 commit comments

Comments
 (0)