Skip to content

Commit b686153

Browse files
Merge branch 'main' into do/vue-query-devtools
2 parents b9304ab + 9b19eaa commit b686153

File tree

11 files changed

+45
-8
lines changed

11 files changed

+45
-8
lines changed

docs/react/devtools.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $ pnpm add @tanstack/react-query-devtools
2222
# or
2323
$ yarn add @tanstack/react-query-devtools
2424
```
25+
2526
For Next 13+ App Dir you must install it as a dev dependency for it to work.
2627

2728
You can import the devtools like this:
@@ -32,7 +33,6 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
3233

3334
By default, React 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.
3435

35-
3636
## Floating Mode
3737

3838
Floating Mode will mount the devtools 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.
@@ -66,6 +66,8 @@ function App() {
6666
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
6767
- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
6868
- 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.
69+
- `styleNonce?: string`
70+
- 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.
6971

7072
## Devtools in production
7173

docs/solid/devtools.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ function App() {
6262
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
6363
- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
6464
- 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.
65+
- `styleNonce?: string`
66+
- 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.

packages/query-devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-devtools",
3-
"version": "5.4.2",
3+
"version": "5.7.4",
44
"description": "Developer tools to interact with and visualize the TanStack Query cache",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-devtools/src/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render } from 'solid-js/web'
22
import { createSignal, lazy } from 'solid-js'
3+
import { setupStyleSheet } from './utils'
34
import type {
45
QueryClient,
56
onlineManager as TonlineManager,
@@ -14,14 +15,17 @@ import type {
1415
import type { Signal } from 'solid-js'
1516

1617
export type { DevtoolsButtonPosition, DevtoolsPosition, DevToolsErrorType }
17-
export interface TanstackQueryDevtoolsConfig extends QueryDevtoolsProps {}
18+
export interface TanstackQueryDevtoolsConfig extends QueryDevtoolsProps {
19+
styleNonce?: string
20+
}
1821

1922
class TanstackQueryDevtools {
2023
#client: Signal<QueryClient>
2124
#onlineManager: typeof TonlineManager
2225
#queryFlavor: string
2326
#version: string
2427
#isMounted = false
28+
#styleNonce?: string
2529
#buttonPosition: Signal<DevtoolsButtonPosition | undefined>
2630
#position: Signal<DevtoolsPosition | undefined>
2731
#initialIsOpen: Signal<boolean | undefined>
@@ -39,11 +43,13 @@ class TanstackQueryDevtools {
3943
position,
4044
initialIsOpen,
4145
errorTypes,
46+
styleNonce,
4247
} = config
4348
this.#client = createSignal(client)
4449
this.#queryFlavor = queryFlavor
4550
this.#version = version
4651
this.#onlineManager = onlineManager
52+
this.#styleNonce = styleNonce
4753
this.#buttonPosition = createSignal(buttonPosition)
4854
this.#position = createSignal(position)
4955
this.#initialIsOpen = createSignal(initialIsOpen)
@@ -80,7 +86,6 @@ class TanstackQueryDevtools {
8086
const [isOpen] = this.#initialIsOpen
8187
const [errors] = this.#errorTypes
8288
const [queryClient] = this.#client
83-
8489
let Devtools: typeof DevtoolsComponent
8590

8691
if (this.#Component) {
@@ -90,6 +95,7 @@ class TanstackQueryDevtools {
9095
this.#Component = Devtools
9196
}
9297

98+
setupStyleSheet(this.#styleNonce)
9399
return (
94100
<Devtools
95101
queryFlavor={this.#queryFlavor}

packages/query-devtools/src/utils.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,17 @@ export const deleteNestedDataByPath = (
310310

311311
return oldData
312312
}
313+
314+
// Sets up the goober stylesheet
315+
// Adds a nonce to the style tag if needed
316+
export const setupStyleSheet = (nonce?: string) => {
317+
if (!nonce) return
318+
const styleExists = document.querySelector('#_goober')
319+
if (styleExists) return
320+
const styleTag = document.createElement('style')
321+
const textNode = document.createTextNode('')
322+
styleTag.appendChild(textNode)
323+
styleTag.id = '_goober'
324+
styleTag.setAttribute('nonce', nonce)
325+
document.head.appendChild(styleTag)
326+
}

packages/react-query-devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/react-query-devtools",
3-
"version": "5.7.2",
3+
"version": "5.7.4",
44
"description": "Developer tools to interact with and visualize the TanStack/react-query cache",
55
"author": "tannerlinsley",
66
"license": "MIT",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export interface DevtoolsOptions {
3535
* Use this so you can define custom errors that can be shown in the devtools.
3636
*/
3737
errorTypes?: Array<DevToolsErrorType>
38+
/**
39+
* 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.
40+
*/
41+
styleNonce?: string
3842
}
3943

4044
export function ReactQueryDevtools(
@@ -43,7 +47,8 @@ export function ReactQueryDevtools(
4347
const queryClient = useQueryClient()
4448
const client = props.client || queryClient
4549
const ref = useRef<HTMLDivElement>(null)
46-
const { buttonPosition, position, initialIsOpen, errorTypes } = props
50+
const { buttonPosition, position, initialIsOpen, errorTypes, styleNonce } =
51+
props
4752
const [devtools] = useState(
4853
new TanstackQueryDevtools({
4954
client: client,
@@ -54,6 +59,7 @@ export function ReactQueryDevtools(
5459
position,
5560
initialIsOpen,
5661
errorTypes,
62+
styleNonce,
5763
}),
5864
)
5965

packages/solid-query-devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/solid-query-devtools",
3-
"version": "5.7.2",
3+
"version": "5.7.4",
44
"description": "Developer tools to interact with and visualize the TanStack/solid-query Query cache",
55
"author": "tannerlinsley",
66
"license": "MIT",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export interface DevtoolsOptions {
4444
* Use this so you can define custom errors that can be shown in the devtools.
4545
*/
4646
errorTypes?: Array<DevToolsErrorType>
47+
/**
48+
* 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.
49+
*/
50+
styleNonce?: string
4751
}
4852

4953
export default function SolidQueryDevtools(props: DevtoolsOptions) {
@@ -59,6 +63,7 @@ export default function SolidQueryDevtools(props: DevtoolsOptions) {
5963
position: props.position,
6064
initialIsOpen: props.initialIsOpen,
6165
errorTypes: props.errorTypes,
66+
styleNonce: props.styleNonce,
6267
})
6368

6469
createEffect(() => {

packages/svelte-query-devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/svelte-query-devtools",
3-
"version": "5.7.2",
3+
"version": "5.7.4",
44
"description": "Developer tools to interact with and visualize the TanStack/svelte-query cache",
55
"author": "Lachlan Collins",
66
"license": "MIT",

0 commit comments

Comments
 (0)