Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
"label": "Quick Start",
"to": "framework/preact/quick-start"
},
{
"label": "Devtools",
"to": "framework/preact/devtools"
},
{
"label": "TypeScript",
"to": "framework/preact/typescript"
Expand Down
87 changes: 87 additions & 0 deletions docs/framework/preact/devtools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like most of the docs are the same as react-query-devtools, can we use them like so:

---
id: installation
title: Installation
ref: docs/framework/react/installation.md
replace: { 'React': 'Preact', 'react-query': 'preact-query' }
---

and then have sections separated using

[//]: # 'Example'
<Code here>
[//]: # 'Example'

id: devtools
title: Devtools
---

Wave your hands in the air and shout hooray because Preact Query comes with dedicated devtools! 🥳

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!

> 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:
>
> - <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)
> - <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/)
> - <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)

## Install and Import the Devtools

The devtools are a separate package that you need to install:

```bash
npm i @tanstack/preact-query-devtools
```

or

```bash
pnpm add @tanstack/preact-query-devtools
```

or

```bash
yarn add @tanstack/preact-query-devtools
```

or

```bash
bun add @tanstack/preact-query-devtools
```

You can import the devtools like this:

```tsx
import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'
```

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.

## Floating Mode

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.

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!

```tsx
import { PreactQueryDevtools } from '@tanstack/preact-query-devtools'

function App() {
return (
<QueryClientProvider client={queryClient}>
{/* The rest of your application */}
<PreactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
)
}
```

### Options

- `initialIsOpen: boolean`
- Set this `true` if you want the dev tools to default to being open
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
- Defaults to `bottom-right`
- The position of the Preact Query logo to open and close the devtools panel
- `position?: "top" | "bottom" | "left" | "right"`
- Defaults to `bottom`
- The position of the Preact Query devtools panel
- `client?: QueryClient`,
- Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
- 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.
- `styleNonce?: string`
- 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.
- `shadowDOMTarget?: ShadowRoot`
- Default behavior will apply the devtool's styles to the head tag within the DOM.
- 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.
Comment on lines +69 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Documentation is missing hideDisabledQueries and theme options.

The DevtoolsOptions interface in PreactQueryDevtools.tsx includes hideDisabledQueries and theme props, but this Options section doesn't list them. Consider adding them for completeness.

🤖 Prompt for AI Agents
In `@docs/framework/preact/devtools.md` around lines 69 - 87, The Options docs
omit the hideDisabledQueries and theme props present on the DevtoolsOptions
interface in PreactQueryDevtools.tsx; update this Options section to document
both: add a `hideDisabledQueries?: boolean` entry describing that it hides
queries in the UI that are disabled, and add a `theme?: "light" | "dark" |
string` (or whatever variants the implementation accepts) entry describing theme
selection and default. Reference the DevtoolsOptions interface/props in
PreactQueryDevtools.tsx to ensure wording and default values match the
implementation.

3 changes: 3 additions & 0 deletions packages/preact-query-devtools/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["no-resolution"]
}
38 changes: 38 additions & 0 deletions packages/preact-query-devtools/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @ts-check
// @ts-ignore: no types for eslint-config-preact
import preact from 'eslint-config-preact'
// eslint-config-preact uses typescript-eslint under the hood
import tseslint from 'typescript-eslint'

import rootConfig from './root.eslint.config.js'

export default [
...rootConfig,
...preact,
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
plugins: {
'typescript-eslint': tseslint.plugin,
},
rules: {
// Disable base rule to prevent overload false positives
'no-redeclare': 'off',
'no-duplicate-imports': 'off',
'no-unused-vars': 'off',
'import/order': 'off',
'sort-imports': 'off',
'no-import-assign': 'off',
// TS-aware version handles overloads correctly
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
},
},
]
90 changes: 90 additions & 0 deletions packages/preact-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"name": "@tanstack/preact-query-devtools",
"version": "5.91.0",
"description": "Developer tools to interact with and visualize the TanStack/preact-query cache",
"author": "tannerlinsley",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/TanStack/query.git",
"directory": "packages/preact-query-devtools"
},
"homepage": "https://tanstack.com/query",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/tannerlinsley"
},
"scripts": {
"clean": "premove ./build ./coverage ./dist-ts",
"compile": "tsc --build",
"test:eslint": "eslint --concurrency=auto ./src",
"test:types": "npm-run-all --serial test:types:*",
"test:types:ts50": "node ../../node_modules/typescript50/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts51": "node ../../node_modules/typescript51/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts52": "node ../../node_modules/typescript52/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts53": "node ../../node_modules/typescript53/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --build tsconfig.legacy.json",
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --build tsconfig.legacy.json",
"test:types:tscurrent": "tsc --build",
"test:build": "publint --strict && attw --pack",
"build": "tsup --tsconfig tsconfig.prod.json",
"build:dev": "tsup --watch"
},
"type": "module",
"types": "build/legacy/index.d.ts",
"main": "build/legacy/index.cjs",
"module": "build/legacy/index.js",
"exports": {
".": {
"@tanstack/custom-condition": "./src/index.ts",
"import": {
"types": "./build/modern/index.d.ts",
"default": "./build/modern/index.js"
},
"require": {
"types": "./build/modern/index.d.cts",
"default": "./build/modern/index.cjs"
}
},
"./production": {
"import": {
"types": "./build/modern/production.d.ts",
"default": "./build/modern/production.js"
},
"require": {
"types": "./build/modern/production.d.cts",
"default": "./build/modern/production.cjs"
}
},
"./build/modern/production.js": {
"import": {
"types": "./build/modern/production.d.ts",
"default": "./build/modern/production.js"
},
"require": {
"types": "./build/modern/production.d.cts",
"default": "./build/modern/production.cjs"
}
},
"./package.json": "./package.json"
},
"sideEffects": false,
"files": ["build", "src", "!src/__tests__"],
"dependencies": {
"@tanstack/query-devtools": "workspace:*"
},
"devDependencies": {
"@preact/preset-vite": "^2.10.2",
"@tanstack/preact-query": "workspace:*",
"@testing-library/preact": "^3.2.4",
"npm-run-all2": "^5.0.0",
"preact": "^10.28.0",
"typescript-eslint": "^8.54.0"
},
"peerDependencies": {
"@tanstack/preact-query": "workspace:^",
"preact": "^10.0.0"
}
}
64 changes: 64 additions & 0 deletions packages/preact-query-devtools/root.eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// @ts-check

// @ts-ignore Needed due to moduleResolution Node vs Bundler
import { tanstackConfig } from '@tanstack/eslint-config'
import pluginCspell from '@cspell/eslint-plugin'
import vitest from '@vitest/eslint-plugin'

export default [
...tanstackConfig,
{
name: 'tanstack/temp',
plugins: {
cspell: pluginCspell,
},
rules: {
'cspell/spellchecker': [
'warn',
{
cspell: {
words: [
'Promisable', // Our public interface
'TSES', // @typescript-eslint package's interface
'codemod', // We support our codemod
'combinate', // Library name
'datatag', // Query options tagging
'extralight', // Our public interface
'jscodeshift',
'refetches', // Query refetch operations
'retryer', // Our public interface
'solidjs', // Our target framework
'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
'tanstack', // Our package scope
'todos', // Too general word to be caught as error
'tsqd', // Our public interface (TanStack Query Devtools shorthand)
'tsup', // We use tsup as builder
'typecheck', // Field of vite.config.ts
'vue-demi', // dependency of @tanstack/vue-query
'ɵkind', // Angular specific
'ɵproviders', // Angular specific
],
},
},
],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'no-case-declarations': 'off',
'prefer-const': 'off',
},
},
{
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/no-standalone-expect': [
'error',
{
additionalTestBlockFunctions: ['testIf'],
},
],
},
settings: { vitest: { typecheck: true } },
},
]
39 changes: 39 additions & 0 deletions packages/preact-query-devtools/root.tsup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-check

import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions'

/**
* @param {Object} opts - Options for building configurations.
* @param {string[]} opts.entry - The entry array.
* @returns {import('tsup').Options}
*/
export function modernConfig(opts) {
return {
entry: opts.entry,
format: ['cjs', 'esm'],
target: ['chrome91', 'firefox90', 'edge91', 'safari15', 'ios15', 'opera77'],
outDir: 'build/modern',
dts: true,
sourcemap: true,
clean: true,
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'js' })],
}
}

/**
* @param {Object} opts - Options for building configurations.
* @param {string[]} opts.entry - The entry array.
* @returns {import('tsup').Options}
*/
export function legacyConfig(opts) {
return {
entry: opts.entry,
format: ['cjs', 'esm'],
target: ['es2020', 'node16'],
outDir: 'build/legacy',
dts: true,
sourcemap: true,
clean: true,
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'js' })],
}
}
Loading