Skip to content

Commit 8fe3b10

Browse files
fix: solid-query-devtools and panel query client (#9763)
* fixed solid-query-devtools and panel * Added changeset * Fixed typo
1 parent 9df1308 commit 8fe3b10

File tree

9 files changed

+97
-4
lines changed

9 files changed

+97
-4
lines changed

.changeset/breezy-cobras-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/solid-query-devtools': patch
3+
---
4+
5+
Fixed client prop not working on SolidQueryDevtools and SolidQueryDevtoolsPanel

packages/solid-query-devtools/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build",
2929
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build",
3030
"test:build": "publint --strict && attw --pack",
31+
"test:lib": "vitest --retry=3",
32+
"test:lib:dev": "pnpm run test:lib --watch",
3133
"build": "tsup --tsconfig tsconfig.prod.json",
3234
"build:dev": "tsup --watch"
3335
},
@@ -64,6 +66,7 @@
6466
"@tanstack/query-devtools": "workspace:*"
6567
},
6668
"devDependencies": {
69+
"@solidjs/testing-library": "^0.8.10",
6770
"@tanstack/solid-query": "workspace:*",
6871
"npm-run-all2": "^5.0.0",
6972
"solid-js": "^1.9.7",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { render } from '@solidjs/testing-library'
3+
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
4+
import SolidQueryDevtools from '../devtools'
5+
6+
describe('SolidQueryDevtools', () => {
7+
it('should throw an error if no query client has been set', () => {
8+
expect(() => render(() => <SolidQueryDevtools />)).toThrow(
9+
'No QueryClient set, use QueryClientProvider to set one',
10+
)
11+
})
12+
13+
it('should not throw an error if query client is provided via context', () => {
14+
const queryClient = new QueryClient()
15+
16+
expect(() =>
17+
render(() => (
18+
<QueryClientProvider client={queryClient}>
19+
<SolidQueryDevtools />
20+
</QueryClientProvider>
21+
)),
22+
).not.toThrow()
23+
})
24+
25+
it('should not throw an error if query client is provided via props', () => {
26+
const queryClient = new QueryClient()
27+
28+
expect(() =>
29+
render(() => <SolidQueryDevtools client={queryClient} />),
30+
).not.toThrow()
31+
})
32+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { render } from '@solidjs/testing-library'
3+
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
4+
import SolidQueryDevtoolsPanel from '../devtoolsPanel'
5+
6+
describe('SolidQueryDevtoolsPanel', () => {
7+
it('should throw an error if no query client has been set', () => {
8+
expect(() => render(() => <SolidQueryDevtoolsPanel />)).toThrow(
9+
'No QueryClient set, use QueryClientProvider to set one',
10+
)
11+
})
12+
13+
it('should not throw an error if query client is provided via context', () => {
14+
const queryClient = new QueryClient()
15+
16+
expect(() =>
17+
render(() => (
18+
<QueryClientProvider client={queryClient}>
19+
<SolidQueryDevtoolsPanel />
20+
</QueryClientProvider>
21+
)),
22+
).not.toThrow()
23+
})
24+
25+
it('should not throw an error if query client is provided via props', () => {
26+
const queryClient = new QueryClient()
27+
28+
expect(() =>
29+
render(() => <SolidQueryDevtoolsPanel client={queryClient} />),
30+
).not.toThrow()
31+
})
32+
})

packages/solid-query-devtools/src/devtools.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ interface DevtoolsOptions {
4848
}
4949

5050
export default function SolidQueryDevtools(props: DevtoolsOptions) {
51-
const queryClient = useQueryClient()
52-
const client = createMemo(() => props.client || queryClient)
51+
const queryClient = useQueryClient(props.client)
52+
const client = createMemo(() => queryClient)
5353
let ref!: HTMLDivElement
5454
const devtools = new TanstackQueryDevtools({
5555
client: client(),

packages/solid-query-devtools/src/devtoolsPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export interface DevtoolsPanelOptions {
4242
}
4343

4444
export default function SolidQueryDevtoolsPanel(props: DevtoolsPanelOptions) {
45-
const queryClient = useQueryClient()
46-
const client = createMemo(() => props.client || queryClient)
45+
const queryClient = useQueryClient(props.client)
46+
const client = createMemo(() => queryClient)
4747
let ref!: HTMLDivElement
4848
const { errorTypes, styleNonce, shadowDOMTarget, hideDisabledQueries } = props
4949
const devtools = new TanstackQueryDevtoolsPanel({
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import '@testing-library/jest-dom/vitest'
2+
import { cleanup } from '@solidjs/testing-library'
3+
import { afterEach } from 'vitest'
4+
5+
// https://github.com/solidjs/solid-testing-library
6+
afterEach(() => cleanup())

packages/solid-query-devtools/vite.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { defineConfig } from 'vite'
22
import solid from 'vite-plugin-solid'
33

4+
import packageJson from './package.json'
5+
46
export default defineConfig({
57
plugins: [solid()],
68
// fix from https://github.com/vitest-dev/vitest/issues/6992#issuecomment-2509408660
@@ -14,4 +16,14 @@ export default defineConfig({
1416
},
1517
},
1618
},
19+
test: {
20+
name: packageJson.name,
21+
dir: './src',
22+
watch: false,
23+
environment: 'jsdom',
24+
setupFiles: ['test-setup.ts'],
25+
coverage: { enabled: true, provider: 'istanbul', include: ['src/**/*'] },
26+
typecheck: { enabled: true },
27+
restoreMocks: true,
28+
},
1729
})

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)