Skip to content
Draft
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
14 changes: 14 additions & 0 deletions .changeset/devtools-tanstack-hotkeys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@tanstack/devtools': minor
---

Handle every devtools keyboard shortcut with TanStack Hotkeys.

- **Breaking:** `openHotkey` is a hotkey string in TanStack Hotkeys syntax, such as `'Control+~'` (the default) or `'Mod+Shift+D'`. Arrays such as `['Control', '~']` are no longer accepted.
- **Breaking:** `inspectHotkey` takes modifier names only. `CtrlOrMeta` is now `Mod`, which is Command on macOS and Control on other platforms. The default is `['Shift', 'Alt', 'Mod']`.
- Saved settings in the old format are ignored, and the config or the default applies instead.
- The Settings tab records the open shortcut from a key press, and rejects a shortcut that the app already registered with TanStack Hotkeys.
- Escape no longer closes the devtools when it closes an open dialog or popover of the app. Escape while moving a pane with the keyboard cancels the move and leaves the panel open.
- Alt+M for magnetic trigger mode now works on macOS, and it no longer fires while you type in a text field.
- The devtools hotkeys are in the `tanstack-devtools` scope. In an app that also uses TanStack Hotkeys, an enabled devtools hotkey runs instead of the app's global hotkey for the same key, such as Escape while the panel is open. An app with an exclusive scope can keep the devtools hotkeys working with `exclusive: { allow: ['tanstack-devtools'] }`.
- `@tanstack/hotkeys` is a new dependency, and `@solid-primitives/keyboard` is removed. An app that already uses TanStack Hotkeys shares one hotkey manager with the devtools.
23 changes: 15 additions & 8 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,29 @@ The `config` object is mainly focused around user interaction with the devtools
{ panelLocation: 'top' | 'bottom' }
```

- `openHotkey` - The hotkey set to open the devtools
- `openHotkey` - The hotkey that opens and closes the devtools, written in [TanStack Hotkeys](https://tanstack.com/hotkeys) syntax. `Mod` is Command on macOS and Control on other platforms. The hotkey does not fire while you type in a text field. The default is `'Control+~'`.

```ts
type ModifierKey = 'Alt' | 'Control' | 'Meta' | 'Shift' | 'CtrlOrMeta';
type KeyboardKey = ModifierKey | (string & {});
import type { Hotkey } from '@tanstack/hotkeys'

{ openHotkey: Array<KeyboardKey> }
{ openHotkey: Hotkey }
```

- `inspectHotkey` - The hotkey set to open the source inspector
- `inspectHotkey` - The modifier keys to hold for the [source inspector](./source-inspector). The inspector is active while you hold exactly these keys. The default is `['Shift', 'Alt', 'Mod']`.

```ts
type ModifierKey = 'Alt' | 'Control' | 'Meta' | 'Shift' | 'CtrlOrMeta';
type KeyboardKey = ModifierKey | (string & {});
type ResolvableModifier = 'Control' | 'Shift' | 'Alt' | 'Meta' | 'Mod'

{ inspectHotkey: Array<KeyboardKey> }
{ inspectHotkey: Array<ResolvableModifier> }
```

If your app also uses TanStack Hotkeys, the devtools share its hotkey manager and register their hotkeys in the `tanstack-devtools` scope:

- While a devtools hotkey is enabled, it runs instead of your app's global hotkey for the same key. For example, while the devtools panel is open, Escape closes the panel and your app's global `Escape` hotkey doesn't run.
- While your app has an exclusive scope active, the devtools hotkeys don't fire. To keep them, add the devtools scope to `allow`:

```tsx
<HotkeysProvider scope="editor" exclusive={{ allow: ['tanstack-devtools'] }}>
```

- `requireUrlFlag` - Requires a flag present in the url to enable devtools
Expand Down
9 changes: 3 additions & 6 deletions docs/source-inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ The Vite plugin uses oxc-parser to parse your JSX/TSX files during development.

## Activating the Inspector

There are two ways to activate the source inspector:
Hold the `inspectHotkey` keys to show the inspector overlay. The default is Shift+Alt+Ctrl, or Shift+Option+Command on macOS. The overlay stays while you hold exactly those keys.

- **Hotkey**: Hold Shift+Alt+Ctrl (or Shift+Alt+Meta on Mac) — this is the default `inspectHotkey`. While held, the inspector overlay appears.
- **Settings panel**: The inspect hotkey can be customized in the devtools Settings tab.

The hotkey can also be configured programmatically:
To change the keys, use the **Source Inspector** buttons in the devtools **Settings** tab, or set `inspectHotkey` in the config. `Mod` is Command on macOS and Control on other platforms:

```ts
<TanStackDevtools
config={{
inspectHotkey: ['Shift', 'Alt', 'CtrlOrMeta'],
inspectHotkey: ['Shift', 'Alt', 'Mod'],
}}
/>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/vite-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ graph TD

The "Go to Source" feature lets you click on any element in your browser and open its source file in your editor at the exact line where it's defined. It works by injecting `data-tsd-source` attributes into your components via an AST transformation during development. These attributes encode the file path and line number of each element.

To use it, activate the source inspector by holding the inspect hotkey (default: Shift+Alt+Ctrl/Meta). An overlay will highlight elements under your cursor and display their source location. Clicking on a highlighted element opens the corresponding file in your editor at the exact line, powered by `launch-editor` under the hood.
To use it, activate the source inspector by holding the inspect hotkey (default: Shift+Alt+Ctrl, or Shift+Option+Command on macOS). An overlay will highlight elements under your cursor and display their source location. Clicking on a highlighted element opens the corresponding file in your editor at the exact line, powered by `launch-editor` under the hood.

For a complete guide on configuration and usage, see the [Source Inspector](./source-inspector) docs.

Expand Down
19 changes: 3 additions & 16 deletions e2e/apps/react-vite/tests/hotkey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { test, expect } from '@playwright/test'
import { DevtoolsPage } from '@tanstack/devtools-e2e'

// The shell's open hotkey is ["Control", "~"] and it is matched against
// `KeyboardEvent.key` via @solid-primitives/keyboard. Playwright's
// `keyboard.press('~')` would require Shift (which adds an extra key and breaks
// the match), so we dispatch the exact keydown events the shell listens for:
// Control first (so the modifier becomes the first held key), then "~" with
// ctrlKey set. This mirrors a real Ctrl+~ press without the Shift artifact.
// The default open hotkey is 'Control+~'. On a US keyboard `~` is Shift+`,
// and TanStack Hotkeys matches the Shift that typing `~` needs.
async function pressOpenHotkey(page: import('@playwright/test').Page) {
await page.evaluate(() => {
window.dispatchEvent(
new KeyboardEvent('keydown', { key: 'Control', ctrlKey: true }),
)
window.dispatchEvent(
new KeyboardEvent('keydown', { key: '~', ctrlKey: true }),
)
window.dispatchEvent(new KeyboardEvent('keyup', { key: '~' }))
window.dispatchEvent(new KeyboardEvent('keyup', { key: 'Control' }))
})
await page.keyboard.press('Control+Shift+Backquote')
}

test.describe('open hotkey', () => {
Expand Down
13 changes: 2 additions & 11 deletions e2e/apps/react-vite/tests/open-as-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ import { test, expect } from '@playwright/test'
import { DevtoolsPage, SELECTORS } from '@tanstack/devtools-e2e'
import type { Page } from '@playwright/test'

// See hotkey.spec.ts: dispatch the exact keydown events of Control+~.
// See hotkey.spec.ts: the default open hotkey, Control+~.
async function pressOpenHotkey(page: Page) {
await page.evaluate(() => {
window.dispatchEvent(
new KeyboardEvent('keydown', { key: 'Control', ctrlKey: true }),
)
window.dispatchEvent(
new KeyboardEvent('keydown', { key: '~', ctrlKey: true }),
)
window.dispatchEvent(new KeyboardEvent('keyup', { key: '~' }))
window.dispatchEvent(new KeyboardEvent('keyup', { key: 'Control' }))
})
await page.keyboard.press('Control+Shift+Backquote')
}

/** Whether a click at the center of the close button reaches it. */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"size-limit": [
{
"path": "packages/devtools/dist/index.js",
"limit": "86 KB"
"limit": "102 KB"
},
{
"path": "packages/event-bus-client/dist/esm/plugin.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ From `packages/devtools-vite/src/index.ts`:

### Source Injection

Adds `data-tsd-source="<relative-path>:<line>:<column>"` attributes to every JSX opening element via oxc-parser + MagicString. This powers the "Go to Source" feature -- hold the inspect hotkey (default: Shift+Alt+Ctrl/Meta), hover over elements, click to open in editor.
Adds `data-tsd-source="<relative-path>:<line>:<column>"` attributes to every JSX opening element via oxc-parser + MagicString. This powers the "Go to Source" feature -- hold the inspect hotkey (default: Shift+Alt+Ctrl, or Shift+Option+Command on macOS), hover over elements, click to open in editor.

**Key behaviors:**

Expand Down
3 changes: 2 additions & 1 deletion packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@
"@neodrag/core": "3.0.0-next.11",
"@tanstack/devtools-client": "workspace:*",
"@tanstack/devtools-event-bus": "workspace:*",
"@tanstack/hotkeys": "^0.37.0",
"clsx": "^2.1.1",
"goober": "^2.1.16"
},
"devDependencies": {
"@babel/core": "^7.28.0",
"@solid-primitives/event-listener": "^3.0.0",
"@solid-primitives/keyboard": "^2.0.0",
"@solid-primitives/resize-observer": "^4.0.0",
"@solidjs/babel-plugin": "^2.0.0",
"@solidjs/testing-library": "^1.0.0-rc.2",
"@solidjs/vite-plugin": "^3.0.0",
"@solidjs/web": "^2.0.0",
"@tanstack/devtools-ui": "workspace:*",
"@tanstack/solid-hotkeys": "^0.27.0",
"solid-js": "^2.0.0",
"tsup": "^8.5.0",
"tsup-preset-solid": "^2.2.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools/skills/devtools-app-setup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ All config properties are optional. Defaults shown below:
position: 'bottom-right', // used when triggerMode is 'fixed': 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'middle-left' | 'middle-right'
triggerMode: 'floating', // 'floating' (default, draggable) | 'fixed'
panelLocation: 'bottom', // panel position: 'top' | 'bottom'
openHotkey: ['Control', '~'],
inspectHotkey: ['Shift', 'Alt', 'CtrlOrMeta'],
openHotkey: 'Control+~', // TanStack Hotkeys syntax; Mod is Cmd on macOS, Ctrl elsewhere
inspectHotkey: ['Shift', 'Alt', 'Mod'], // modifiers to hold for the source inspector
requireUrlFlag: false, // require URL param to show devtools
urlFlag: 'tanstack-devtools', // the URL param name when requireUrlFlag is true
theme: 'dark', // 'light' | 'dark' (defaults to system preference)
Expand Down
50 changes: 30 additions & 20 deletions packages/devtools/src/components/content-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createSignal } from 'solid-js'
import { createHotkeys } from '@tanstack/solid-hotkeys'
import {
createDevtoolsSettings,
createHeight,
Expand All @@ -24,26 +26,34 @@ export const ContentPanel = (props: {
Math.floor(window.innerHeight * PANEL_MAX_VIEWPORT_RATIO)
const clampedHeight = () =>
Math.min(maxHeight(), Math.max(PANEL_CLOSE_THRESHOLD, Math.round(height())))
const resizeWithKeyboard: JSX.EventHandlerUnion<
HTMLDivElement,
KeyboardEvent
> = (event) => {
const step = event.shiftKey ? 50 : 10
const grows =
(settings().panelLocation === 'bottom' && event.key === 'ArrowUp') ||
(settings().panelLocation === 'top' && event.key === 'ArrowDown')
const shrinks =
(settings().panelLocation === 'bottom' && event.key === 'ArrowDown') ||
(settings().panelLocation === 'top' && event.key === 'ArrowUp')
let nextHeight: number | undefined
if (grows) nextHeight = clampedHeight() + step
if (shrinks) nextHeight = clampedHeight() - step
if (event.key === 'Home') nextHeight = PANEL_CLOSE_THRESHOLD
if (event.key === 'End') nextHeight = maxHeight()
if (nextHeight === undefined) return
event.preventDefault()
const [resizeHandle, setResizeHandle] = createSignal<HTMLDivElement>()
const setHeight = (nextHeight: number) =>
props.handleHeightChange?.(Math.min(maxHeight(), nextHeight))
}
// The arrow towards the page grows the panel, by more with Shift. Home closes
// it and End makes it as tall as it gets.
const growBy = (step: number) => () =>
setHeight(
clampedHeight() + (settings().panelLocation === 'bottom' ? step : -step),
)
createHotkeys(
[
{ hotkey: 'ArrowUp', callback: growBy(10) },
{ hotkey: 'Shift+ArrowUp', callback: growBy(50) },
{ hotkey: 'ArrowDown', callback: growBy(-10) },
{ hotkey: 'Shift+ArrowDown', callback: growBy(-50) },
{ hotkey: 'Home', callback: () => setHeight(PANEL_CLOSE_THRESHOLD) },
{ hotkey: 'End', callback: () => setHeight(maxHeight()) },
],
() => ({
// The handle isn't rendered in the PiP window, but its ref keeps the old
// element.
target:
props.handleDragStart && pip().pipWindow === null
? (resizeHandle() ?? null)
: null,
meta: { name: 'Resize the devtools panel' },
}),
)

return (
<div
Expand All @@ -55,6 +65,7 @@ export const ContentPanel = (props: {
>
{props.handleDragStart && pip().pipWindow === null ? (
<div
ref={setResizeHandle}
data-testid="tsd-resize-handle"
class={styles().dragHandle(settings().panelLocation)}
onMouseDown={props.handleDragStart}
Expand All @@ -67,7 +78,6 @@ export const ContentPanel = (props: {
aria-valuemax={maxHeight()}
aria-valuenow={clampedHeight()}
tabindex={0}
onKeyDown={resizeWithKeyboard}
/>
) : null}
{props.children}
Expand Down
Loading
Loading