-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add preact query devtools #10119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preact query devtools #10119
Changes from all commits
a65ce3c
0bdd161
60f8160
66a90f4
ff96999
009d731
80ba43b
4a9bf8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@tanstack/preact-query-devtools": minor | ||
| "@tanstack/preact-query": minor | ||
| --- | ||
|
|
||
| feat: Add preact query devtools |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| --- | ||
| 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. | ||
|
Comment on lines
+71
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the documented option signatures with the actual component API.
Suggested doc fix-- `initialIsOpen: boolean`
+- `initialIsOpen?: boolean`
- Set this `true` if you want the dev tools to default to being open
@@
-- `errorTypes?: { name: string; initializer: (query: Query) => TError}`
+- `errorTypes?: Array<DevtoolsErrorType>`
- 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.🤖 Prompt for AI Agents |
||
| - `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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation is missing The 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "ignoreRules": ["no-resolution"] | ||
| } |
| 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', | ||
| }, | ||
| }, | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| { | ||
| "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", | ||
| "eslint-config-preact": "^2.0.0", | ||
| "npm-run-all2": "^5.0.0", | ||
| "preact": "^10.28.0", | ||
| "typescript-eslint": "^8.54.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "@tanstack/preact-query": "workspace:^", | ||
| "preact": "^10.0.0" | ||
| } | ||
| } |
| 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 } }, | ||
| }, | ||
| ] |
| 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' })], | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.