Skip to content

Commit 359aade

Browse files
committed
Add preact query devtools
1 parent 6252715 commit 359aade

20 files changed

+706
-0
lines changed

.changeset/icy-deserts-shine.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/preact-query-devtools': minor
3+
---
4+
5+
Initial release

docs/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@
183183
"label": "Quick Start",
184184
"to": "framework/preact/quick-start"
185185
},
186+
{
187+
"label": "Devtools",
188+
"to": "framework/preact/devtools"
189+
},
186190
{
187191
"label": "TypeScript",
188192
"to": "framework/preact/typescript"

docs/framework/preact/devtools.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
id: devtools
3+
title: Devtools
4+
---
5+
6+
Wave your hands in the air and shout hooray because Preact Query comes with dedicated devtools! 🥳
7+
8+
When you begin your Preact Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of Preact Query and will likely save you hours of debugging if you find yourself in a pinch!
9+
10+
> For Chrome, Firefox, and Edge users: Third-party browser extensions are available for debugging TanStack Query directly in browser DevTools. These provide the same functionality as the framework-specific devtools packages:
11+
>
12+
> - <img alt="Chrome logo" src="https://www.google.com/chrome/static/images/chrome-logo.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Chrome](https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai)
13+
> - <img alt="Firefox logo" src="https://upload.wikimedia.org/wikipedia/commons/a/a0/Firefox_logo%2C_2019.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Firefox](https://addons.mozilla.org/en-US/firefox/addon/tanstack-query-devtools/)
14+
> - <img alt="Edge logo" src="https://upload.wikimedia.org/wikipedia/commons/9/98/Microsoft_Edge_logo_%282019%29.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Edge](https://microsoftedge.microsoft.com/addons/detail/tanstack-query-devtools/edmdpkgkacmjopodhfolmphdenmddobj)
15+
16+
## Install and Import the Devtools
17+
18+
The devtools are a separate package that you need to install:
19+
20+
```bash
21+
npm i @tanstack/preact-query-devtools
22+
```
23+
24+
or
25+
26+
```bash
27+
pnpm add @tanstack/preact-query-devtools
28+
```
29+
30+
or
31+
32+
```bash
33+
yarn add @tanstack/preact-query-devtools
34+
```
35+
36+
or
37+
38+
```bash
39+
bun add @tanstack/preact-query-devtools
40+
```
41+
42+
You can import the devtools like this:
43+
44+
```tsx
45+
import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
46+
```
47+
48+
By default, Preact 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.
49+
50+
## Floating Mode
51+
52+
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.
53+
54+
Place the following code as high in your Preact app as you can. The closer it is to the root of the page, the better it will work!
55+
56+
```tsx
57+
import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
58+
59+
function App() {
60+
return (
61+
<QueryClientProvider client={queryClient}>
62+
{/* The rest of your application */}
63+
<PreactQueryDevtools initialIsOpen={false} />
64+
</QueryClientProvider>
65+
)
66+
}
67+
```
68+
69+
### Options
70+
71+
- `initialIsOpen: boolean`
72+
- Set this `true` if you want the dev tools to default to being open
73+
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
74+
- Defaults to `bottom-right`
75+
- The position of the Preact Query logo to open and close the devtools panel
76+
- `position?: "top" | "bottom" | "left" | "right"`
77+
- Defaults to `bottom`
78+
- The position of the Preact Query devtools panel
79+
- `client?: QueryClient`,
80+
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
81+
- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
82+
- 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.
83+
- `styleNonce?: string`
84+
- 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.
85+
- `shadowDOMTarget?: ShadowRoot`
86+
- Default behavior will apply the devtool's styles to the head tag within the DOM.
87+
- 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.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ignoreRules": ["no-resolution"]
3+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @ts-check
2+
// @ts-ignore: no types for eslint-config-preact
3+
import preact from 'eslint-config-preact'
4+
// eslint-config-preact uses typescript-eslint under the hood
5+
import tseslint from 'typescript-eslint'
6+
7+
import rootConfig from './root.eslint.config.js'
8+
9+
export default [
10+
...rootConfig,
11+
...preact,
12+
{
13+
files: ['**/*.{ts,tsx}'],
14+
languageOptions: {
15+
parser: tseslint.parser,
16+
parserOptions: {
17+
project: true,
18+
},
19+
},
20+
plugins: {
21+
'typescript-eslint': tseslint.plugin,
22+
},
23+
rules: {
24+
// Disable base rule to prevent overload false positives
25+
'no-redeclare': 'off',
26+
'no-duplicate-imports': 'off',
27+
'no-unused-vars': 'off',
28+
'import/order': 'off',
29+
'sort-imports': 'off',
30+
'no-import-assign': 'off',
31+
// TS-aware version handles overloads correctly
32+
'@typescript-eslint/no-redeclare': 'error',
33+
'@typescript-eslint/array-type': 'off',
34+
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
35+
'@typescript-eslint/no-unnecessary-condition': 'off',
36+
},
37+
},
38+
]
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"name": "@tanstack/preact-query-devtools",
3+
"version": "0.0.0",
4+
"description": "Developer tools to interact with and visualize the TanStack/preact-query cache",
5+
"author": "tannerlinsley",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/TanStack/query.git",
10+
"directory": "packages/preact-query-devtools"
11+
},
12+
"homepage": "https://tanstack.com/query",
13+
"funding": {
14+
"type": "github",
15+
"url": "https://github.com/sponsors/tannerlinsley"
16+
},
17+
"scripts": {
18+
"clean": "premove ./build ./coverage ./dist-ts",
19+
"compile": "tsc --build",
20+
"test:eslint": "eslint --concurrency=auto ./src",
21+
"test:types": "npm-run-all --serial test:types:*",
22+
"test:types:ts50": "node ../../node_modules/typescript50/lib/tsc.js --build tsconfig.legacy.json",
23+
"test:types:ts51": "node ../../node_modules/typescript51/lib/tsc.js --build tsconfig.legacy.json",
24+
"test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js --build tsconfig.legacy.json",
25+
"test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build tsconfig.legacy.json",
26+
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build tsconfig.legacy.json",
27+
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build tsconfig.legacy.json",
28+
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build tsconfig.legacy.json",
29+
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build tsconfig.legacy.json",
30+
"test:types:tscurrent": "tsc --build",
31+
"test:lib": "vitest",
32+
"test:lib:dev": "pnpm run test:lib --watch",
33+
"test:build": "publint --strict && attw --pack",
34+
"build": "tsup --tsconfig tsconfig.prod.json",
35+
"build:dev": "tsup --watch"
36+
},
37+
"type": "module",
38+
"types": "build/legacy/index.d.ts",
39+
"main": "build/legacy/index.cjs",
40+
"module": "build/legacy/index.js",
41+
"exports": {
42+
".": {
43+
"@tanstack/custom-condition": "./src/index.ts",
44+
"import": {
45+
"types": "./build/modern/index.d.ts",
46+
"default": "./build/modern/index.js"
47+
},
48+
"require": {
49+
"types": "./build/modern/index.d.cts",
50+
"default": "./build/modern/index.cjs"
51+
}
52+
},
53+
"./production": {
54+
"import": {
55+
"types": "./build/modern/production.d.ts",
56+
"default": "./build/modern/production.js"
57+
},
58+
"require": {
59+
"types": "./build/modern/production.d.cts",
60+
"default": "./build/modern/production.cjs"
61+
}
62+
},
63+
"./build/modern/production.js": {
64+
"import": {
65+
"types": "./build/modern/production.d.ts",
66+
"default": "./build/modern/production.js"
67+
},
68+
"require": {
69+
"types": "./build/modern/production.d.cts",
70+
"default": "./build/modern/production.cjs"
71+
}
72+
},
73+
"./package.json": "./package.json"
74+
},
75+
"sideEffects": false,
76+
"files": ["build", "src", "!src/__tests__"],
77+
"dependencies": {
78+
"@tanstack/query-devtools": "workspace:*"
79+
},
80+
"devDependencies": {
81+
"@preact/preset-vite": "^2.10.2",
82+
"@tanstack/preact-query": "workspace:*",
83+
"@testing-library/preact": "^3.2.4",
84+
"npm-run-all2": "^5.0.0",
85+
"preact": "^10.28.0",
86+
"typescript-eslint": "^8.54.0"
87+
},
88+
"peerDependencies": {
89+
"@tanstack/preact-query": "workspace:^",
90+
"preact": "^10.0.0"
91+
}
92+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// @ts-check
2+
3+
// @ts-ignore Needed due to moduleResolution Node vs Bundler
4+
import { tanstackConfig } from '@tanstack/eslint-config'
5+
import pluginCspell from '@cspell/eslint-plugin'
6+
import vitest from '@vitest/eslint-plugin'
7+
8+
export default [
9+
...tanstackConfig,
10+
{
11+
name: 'tanstack/temp',
12+
plugins: {
13+
cspell: pluginCspell,
14+
},
15+
rules: {
16+
'cspell/spellchecker': [
17+
'warn',
18+
{
19+
cspell: {
20+
words: [
21+
'Promisable', // Our public interface
22+
'TSES', // @typescript-eslint package's interface
23+
'codemod', // We support our codemod
24+
'combinate', // Library name
25+
'datatag', // Query options tagging
26+
'extralight', // Our public interface
27+
'jscodeshift',
28+
'refetches', // Query refetch operations
29+
'retryer', // Our public interface
30+
'solidjs', // Our target framework
31+
'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
32+
'tanstack', // Our package scope
33+
'todos', // Too general word to be caught as error
34+
'tsqd', // Our public interface (TanStack Query Devtools shorthand)
35+
'tsup', // We use tsup as builder
36+
'typecheck', // Field of vite.config.ts
37+
'vue-demi', // dependency of @tanstack/vue-query
38+
'ɵkind', // Angular specific
39+
'ɵproviders', // Angular specific
40+
],
41+
},
42+
},
43+
],
44+
'@typescript-eslint/no-empty-function': 'off',
45+
'@typescript-eslint/no-unsafe-function-type': 'off',
46+
'no-case-declarations': 'off',
47+
'prefer-const': 'off',
48+
},
49+
},
50+
{
51+
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
52+
plugins: { vitest },
53+
rules: {
54+
...vitest.configs.recommended.rules,
55+
'vitest/no-standalone-expect': [
56+
'error',
57+
{
58+
additionalTestBlockFunctions: ['testIf'],
59+
},
60+
],
61+
},
62+
settings: { vitest: { typecheck: true } },
63+
},
64+
]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// @ts-check
2+
3+
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions'
4+
5+
/**
6+
* @param {Object} opts - Options for building configurations.
7+
* @param {string[]} opts.entry - The entry array.
8+
* @returns {import('tsup').Options}
9+
*/
10+
export function modernConfig(opts) {
11+
return {
12+
entry: opts.entry,
13+
format: ['cjs', 'esm'],
14+
target: ['chrome91', 'firefox90', 'edge91', 'safari15', 'ios15', 'opera77'],
15+
outDir: 'build/modern',
16+
dts: true,
17+
sourcemap: true,
18+
clean: true,
19+
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'js' })],
20+
}
21+
}
22+
23+
/**
24+
* @param {Object} opts - Options for building configurations.
25+
* @param {string[]} opts.entry - The entry array.
26+
* @returns {import('tsup').Options}
27+
*/
28+
export function legacyConfig(opts) {
29+
return {
30+
entry: opts.entry,
31+
format: ['cjs', 'esm'],
32+
target: ['es2020', 'node16'],
33+
outDir: 'build/legacy',
34+
dts: true,
35+
sourcemap: true,
36+
clean: true,
37+
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'js' })],
38+
}
39+
}

0 commit comments

Comments
 (0)