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
11 changes: 11 additions & 0 deletions .changeset/query-devtools-trusted-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@tanstack/query-devtools': patch
'@tanstack/angular-query-devtools': patch
'@tanstack/preact-query-devtools': patch
'@tanstack/react-query-devtools': patch
'@tanstack/solid-query-devtools': patch
'@tanstack/svelte-query-devtools': patch
'@tanstack/vue-query-devtools': patch
---

Add a `trustedTypesPolicy` option, so the devtools render on pages that enforce `require-trusted-types-for 'script'`.
12 changes: 8 additions & 4 deletions docs/framework/angular/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ export const appConfig: ApplicationConfig = {
`initialIsOpen`, and `theme` accept either their documented static value or a
signal containing that value.

`styleNonce`, `shadowDOMTarget`, and `hideDisabledQueries` are construction-time
options and do not accept signals.
`styleNonce`, `shadowDOMTarget`, `trustedTypesPolicy`, and `hideDisabledQueries`
are construction-time options and do not accept signals.

- `loadDevtools?: 'auto' | boolean`
- Omit or `'auto'`: load devtools only in development mode.
Expand All @@ -207,6 +207,8 @@ options and do not accept signals.
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down Expand Up @@ -255,8 +257,8 @@ See the [devtools panel example](./examples/devtools-panel-angular-router) for b

The callback is reactive: `hostElement`, `client`, `errorTypes`, `onClose`, and `theme` are applied whenever a signal read in the callback changes.

`styleNonce`, `shadowDOMTarget`, and `hideDisabledQueries` are construction-time
options, read when the panel is created.
`styleNonce`, `shadowDOMTarget`, `trustedTypesPolicy`, and `hideDisabledQueries`
are construction-time options, read when the panel is created.

- `hostElement?: ElementRef | null`
- The element to render the devtools panel in. When it is `undefined` or `null`, the devtools panel is not created, or is destroyed if it exists.
Expand All @@ -270,6 +272,8 @@ options, read when the panel is created.
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down
4 changes: 4 additions & 0 deletions docs/framework/preact/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function App() {
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down Expand Up @@ -134,6 +136,8 @@ function App() {
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down
4 changes: 4 additions & 0 deletions docs/framework/react/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ function App() {
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down Expand Up @@ -140,6 +142,8 @@ function App() {
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down
4 changes: 4 additions & 0 deletions docs/framework/solid/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function App() {
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`. The devtools bundle their own Solid runtime, so this is separate from the policy your app sets with `setTrustedTypesPolicy` from `solid-js/web` (1.9.20+).
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down Expand Up @@ -136,6 +138,8 @@ function App() {
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`. The devtools bundle their own Solid runtime, so this is separate from the policy your app sets with `setTrustedTypesPolicy` from `solid-js/web` (1.9.20+).
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down
2 changes: 2 additions & 0 deletions docs/framework/svelte/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Place the following code as high in your Svelte app as you can. The closer it is
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down
4 changes: 4 additions & 0 deletions docs/framework/vue/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down Expand Up @@ -127,6 +129,8 @@ const isOpen = ref(false)
- Deprecated. The devtools no longer add a `<style>` element, so they need no nonce. This option does nothing.
- `shadowDOMTarget?: ShadowRoot`
- The shadow root to add the devtools styles to. By default, the styles are added to the shadow root the devtools render in, or to the document when they do not render in a shadow root.
- `trustedTypesPolicy?: { createHTML: (html: string) => unknown }`
- The Trusted Types policy the devtools use to create their HTML templates. Pass one when your page enforces `require-trusted-types-for 'script'`. The devtools only pass it their own markup, so a policy that returns its input is enough, for example `trustedTypes.createPolicy('devtools', { createHTML: (html) => html })`.
- `hideDisabledQueries?: boolean`
- Defaults to `false`.
- Set this to true to hide disabled queries from the devtools panel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const injectDevtoolsPanel: InjectDevtoolsPanel = (
errorTypes = [],
theme,
shadowDOMTarget,
trustedTypesPolicy,
hideDisabledQueries,
onClose,
hostElement,
Expand Down Expand Up @@ -92,6 +93,7 @@ export const injectDevtoolsPanel: InjectDevtoolsPanel = (
errorTypes,
theme,
shadowDOMTarget,
trustedTypesPolicy,
hideDisabledQueries,
onClose,
onlineManager,
Expand Down
6 changes: 6 additions & 0 deletions packages/angular-query-devtools/src/devtools-panel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export interface DevtoolsPanelOptions {
* they do not render in a shadow root.
*/
shadowDOMTarget?: ShadowRoot
/**
* The Trusted Types policy the devtools use to create their HTML templates.
* Pass one when your page enforces `require-trusted-types-for 'script'`.
* The devtools only pass it their own markup.
*/
trustedTypesPolicy?: { createHTML: (html: string) => unknown }
/**
* Set this to true to hide disabled queries from the devtools panel.
*/
Expand Down
11 changes: 9 additions & 2 deletions packages/angular-query-devtools/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export interface DevtoolsOptions {
* they do not render in a shadow root.
*/
shadowDOMTarget?: ShadowRoot
/**
* The Trusted Types policy the devtools use to create their HTML templates.
* Pass one when your page enforces `require-trusted-types-for 'script'`.
* The devtools only pass it their own markup.
*/
trustedTypesPolicy?: { createHTML: (html: string) => unknown }
/**
* Set this to true to hide disabled queries from the devtools panel.
*/
Expand Down Expand Up @@ -87,8 +93,9 @@ export interface DevtoolsOptions {
/**
* Returns devtools options. The function runs once in an Angular injection
* context, so it can call `inject()`. Pass signals as option values to make
* mutable options reactive. `styleNonce`, `shadowDOMTarget`, and
* `hideDisabledQueries` are read only when the devtools are constructed.
* mutable options reactive. `styleNonce`, `shadowDOMTarget`,
* `trustedTypesPolicy`, and `hideDisabledQueries` are read only when the
* devtools are constructed.
*/
export type WithDevtoolsFn = () => DevtoolsOptions

Expand Down
1 change: 1 addition & 0 deletions packages/angular-query-devtools/src/with-devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const withDevtools: WithDevtools = (withDevtoolsFn) =>
initialIsOpen: resolveOption(options.initialIsOpen),
errorTypes: resolveOption(options.errorTypes),
shadowDOMTarget: options.shadowDOMTarget,
trustedTypesPolicy: options.trustedTypesPolicy,
hideDisabledQueries: options.hideDisabledQueries,
theme: resolveOption(options.theme),
})
Expand Down
8 changes: 8 additions & 0 deletions packages/preact-query-devtools/src/PreactQueryDevtools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export interface DevtoolsOptions {
* they do not render in a shadow root.
*/
shadowDOMTarget?: ShadowRoot
/**
* The Trusted Types policy the devtools use to create their HTML templates.
* Pass one when your page enforces `require-trusted-types-for 'script'`.
* The devtools only pass it their own markup.
*/
trustedTypesPolicy?: { createHTML: (html: string) => unknown }
/**
* Use this to hide disabled queries from the devtools panel.
*/
Expand Down Expand Up @@ -78,6 +84,7 @@ export function PreactQueryDevtools(props: DevtoolsOptions): VNode | null {
initialIsOpen,
errorTypes,
shadowDOMTarget,
trustedTypesPolicy,
hideDisabledQueries,
theme,
} = props
Expand All @@ -93,6 +100,7 @@ export function PreactQueryDevtools(props: DevtoolsOptions): VNode | null {
initialIsOpen,
errorTypes,
shadowDOMTarget,
trustedTypesPolicy,
hideDisabledQueries,
theme,
}),
Expand Down
15 changes: 14 additions & 1 deletion packages/preact-query-devtools/src/PreactQueryDevtoolsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export interface DevtoolsPanelOptions {
* they do not render in a shadow root.
*/
shadowDOMTarget?: ShadowRoot
/**
* The Trusted Types policy the devtools use to create their HTML templates.
* Pass one when your page enforces `require-trusted-types-for 'script'`.
* The devtools only pass it their own markup.
*/
trustedTypesPolicy?: { createHTML: (html: string) => unknown }
/**
* Custom styles for the devtools panel container.
* @default { height: '100%', display: 'flex', flexDirection: 'column' }
Expand Down Expand Up @@ -62,7 +68,13 @@ export function PreactQueryDevtoolsPanel(
): VNode | null {
const queryClient = useQueryClient(props.client)
const ref = useRef<HTMLDivElement>(null)
const { errorTypes, shadowDOMTarget, hideDisabledQueries, theme } = props
const {
errorTypes,
shadowDOMTarget,
trustedTypesPolicy,
hideDisabledQueries,
theme,
} = props
const [devtools] = useState(
() =>
new TanstackQueryDevtoolsPanel({
Expand All @@ -75,6 +87,7 @@ export function PreactQueryDevtoolsPanel(
initialIsOpen: true,
errorTypes,
shadowDOMTarget,
trustedTypesPolicy,
onClose: props.onClose,
hideDisabledQueries,
theme,
Expand Down
2 changes: 1 addition & 1 deletion packages/query-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@tanstack/match-sorter-utils": "^9.1.2",
"@tanstack/query-core": "workspace:*",
"@tanstack/solid-virtual": "^3.13.52",
"solid-js": "^1.9.15",
"solid-js": "^1.9.20",
"solid-transition-group": "^0.2.3",
"superjson": "^2.2.6"
},
Expand Down
16 changes: 15 additions & 1 deletion packages/query-devtools/src/TanstackQueryDevtools.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal, lazy } from 'solid-js'
import { render } from 'solid-js/web'
import { render, setTrustedTypesPolicy } from 'solid-js/web'
import type {
QueryClient,
onlineManager as TOnlineManager,
Expand Down Expand Up @@ -28,6 +28,12 @@ export interface TanstackQueryDevtoolsConfig extends QueryDevtoolsProps {
* root the devtools render in, or to the document when they do not render in a shadow root.
*/
shadowDOMTarget?: ShadowRoot
/**
* The Trusted Types policy the devtools use to create their HTML templates.
* Pass one when your page enforces `require-trusted-types-for 'script'`.
* The devtools only pass it their own markup.
*/
trustedTypesPolicy?: { createHTML: (html: string) => unknown }
}

class TanstackQueryDevtools {
Expand All @@ -37,6 +43,7 @@ class TanstackQueryDevtools {
#version: string
#isMounted = false
#shadowDOMTarget?: ShadowRoot
#trustedTypesPolicy?: { createHTML: (html: string) => unknown }
#buttonPosition: Signal<DevtoolsButtonPosition | undefined>
#position: Signal<DevtoolsPosition | undefined>
#initialIsOpen: Signal<boolean | undefined>
Expand All @@ -57,6 +64,7 @@ class TanstackQueryDevtools {
initialIsOpen,
errorTypes,
shadowDOMTarget,
trustedTypesPolicy,
hideDisabledQueries,
theme,
} = config
Expand All @@ -65,6 +73,7 @@ class TanstackQueryDevtools {
this.#version = version
this.#onlineManager = onlineManager
this.#shadowDOMTarget = shadowDOMTarget
this.#trustedTypesPolicy = trustedTypesPolicy
this.#buttonPosition = createSignal(buttonPosition)
this.#position = createSignal(position)
this.#initialIsOpen = createSignal(initialIsOpen)
Expand Down Expand Up @@ -101,6 +110,11 @@ class TanstackQueryDevtools {
if (this.#isMounted) {
throw new Error('Devtools is already mounted')
}
// Solid creates each template once, so set the policy before rendering.
// It is shared by every devtools instance, so never reset it.
if (this.#trustedTypesPolicy) {
setTrustedTypesPolicy(this.#trustedTypesPolicy)
}
const dispose = render(() => {
const [btnPosition] = this.#buttonPosition
const [pos] = this.#position
Expand Down
Loading
Loading