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

Move the devtools panel to Solid 2, `@tanstack/devtools-ui` 0.8, and `@tanstack/devtools-utils` 0.8, the same as TanStack Devtools 0.17. The panel looks and works the same in every framework, and it needs Node 22.12 or newer.

`@tanstack/solid-hotkeys-devtools` now needs `solid-js` 2 and `@tanstack/solid-devtools` 0.9 or newer. Solid 1 apps can stay on `@tanstack/solid-hotkeys-devtools@0.13`.
12 changes: 12 additions & 0 deletions .changeset/solid-hotkeys-solid-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@tanstack/solid-hotkeys': minor
---

Move to Solid 2 and drop Solid 1. `@tanstack/solid-hotkeys` now needs `solid-js` 2 and Node 22.12 or newer. Solid 1 apps can stay on `@tanstack/solid-hotkeys@0.25`, the last release for Solid 1.

- The primitives keep their API. Effects that track reactive options read them in the compute half and apply them in the effect half.
- `HotkeysProvider` renders its context without JSX, so the adapter imports only `solid-js`, not `@solidjs/web`.
- `createHotkeyRegistrations` returns a store reconciled by registration `id`, so `<For>` rows keep their identity when registrations change.
- The internal store selector works like `useSelector` from `@tanstack/solid-store` 1.0: the store state is held in a signal and the selection is derived from it, so a selector that reads other signals tracks them for the current state.
- As with every Solid 2 signal, a value read right after a write outside a reactive scope updates after the next flush (`flush()` from `solid-js`, or the next microtask).
- Don't call `createHotkey` in a `ref` callback. Solid 2 runs ref callbacks outside the component's owner. Give the element its own component with a signal `target` instead.
1,142 changes: 619 additions & 523 deletions .intent/review-state.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ npm install @tanstack/preact-devtools @tanstack/preact-hotkeys-devtools

# Solid

Requires Solid 1.9.15 or newer within version 1.
Requires Solid 2 and `@tanstack/solid-devtools` 0.9 or newer. For Solid 1 (1.9.15 or newer), install `@tanstack/solid-hotkeys-devtools@0.13`, the last release for Solid 1.

```sh
npm install @tanstack/solid-devtools @tanstack/solid-hotkeys-devtools
Expand Down
16 changes: 12 additions & 4 deletions docs/framework/solid/guides/formatting-display.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ Pages rendered this way depend on the request's `User-Agent` header. If a CDN or

### SolidStart

> [!NOTE]
> SolidStart and Astro's Solid integration don't support Solid 2 yet. This section and its example use Solid 1 with `@tanstack/solid-hotkeys` 0.25, the last release for Solid 1.

`getRequestEvent()` from `solid-js/web` returns the current request on the server and `undefined` in the browser. Without a user agent, `detectPlatform` reads the browser's `navigator`, so the same code works on both sides:

```tsx
Expand Down Expand Up @@ -255,6 +258,9 @@ The [TanStack Start example](../examples/createFormatForDisplay-tanstack-start)

### Astro

> [!NOTE]
> SolidStart and Astro's Solid integration don't support Solid 2 yet. This section and its example use Solid 1 with `@tanstack/solid-hotkeys` 0.25, the last release for Solid 1.

Each Solid island is its own Solid app, so render the provider inside the island and pass the platform from the page. The page must render on demand to have a request: add `export const prerender = false`, or use `output: 'server'`.

```astro
Expand Down Expand Up @@ -291,14 +297,16 @@ The [Astro example](../examples/createFormatForDisplay-astro) shows this setup.
To skip server rendering for a label instead, render it after hydration. A component that first renders in the browser gets the browser's platform from `createFormatForDisplay` at once:

```tsx
import { Show, createSignal, onMount } from 'solid-js'
import { Show, createSignal, onSettled } from 'solid-js'
import { createFormatForDisplay } from '@tanstack/solid-hotkeys'
import type { JSX } from 'solid-js'
import type { JSX } from '@solidjs/web'
import type { Hotkey } from '@tanstack/solid-hotkeys'

function ClientOnly(props: { children: JSX.Element; fallback?: JSX.Element }) {
const [mounted, setMounted] = createSignal(false)
onMount(() => setMounted(true))
onSettled(() => {
setMounted(true)
})
return (
<Show when={mounted()} fallback={props.fallback}>
{props.children}
Expand All @@ -317,7 +325,7 @@ function ShortcutLabel(props: { hotkey: Hotkey }) {
</ClientOnly>
```

`onMount` runs only in the browser, after hydration, so the server and the first render in the browser both show the fallback. Framework wrappers do the same: TanStack Router's `<ClientOnly>` from `@tanstack/solid-router`, SolidStart's `clientOnly()`, or `client:only="solid-js"` on an Astro island. A fallback with the label's width keeps the layout from shifting.
`onSettled` runs only in the browser, after hydration, so the server and the first render in the browser both show the fallback. Framework wrappers do the same: TanStack Router's `<ClientOnly>` from `@tanstack/solid-router`, SolidStart's `clientOnly()`, or `client:only="solid-js"` on an Astro island. A fallback with the label's width keeps the layout from shifting.

Don't use `<NoHydration>` or an `isServer` check for labels. `<NoHydration>` keeps the server's label, and rendering different content on the server and in the browser breaks hydration.

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/guides/hotkeys-provider-and-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function Editor() {
// Also has a target: works only while focus is inside the outline
createHotkey('Delete', () => deleteHeading(), () => ({ target: outline() }))

return <nav ref={setOutline} tabIndex={0}>...</nav>
return <nav ref={setOutline} tabindex={0}>...</nav>
}
```

Expand Down
31 changes: 17 additions & 14 deletions docs/framework/solid/guides/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function RichTextEditor() {
() => ({ target: editor() }),
)

return <div ref={setEditor} contentEditable />
return <div ref={setEditor} contenteditable />
}
```

Expand Down Expand Up @@ -338,7 +338,7 @@ function Panel() {
createHotkey('Escape', () => closePanel(), () => ({ target: panel() }))

return (
<div ref={setPanel} tabIndex={0}>
<div ref={setPanel} tabindex={0}>
Panel content
</div>
)
Expand All @@ -348,34 +348,37 @@ function Panel() {
A `null` or `undefined` target waits until the element is attached. Only an omitted `target` listens on `document`, so a wrapper that forwards an unset `target` waits too. Set `target: document` to choose the document explicitly.

> [!NOTE]
> An element receives key presses only while it, or something inside it, has focus. Give it a `tabIndex` if it isn't focusable already.
> An element receives key presses only while it, or something inside it, has focus. Give it a `tabindex` if it isn't focusable already.

While focus is inside the element, its hotkeys run before hotkeys on `document`. With the default `stopPropagation: true`, a `document` hotkey for the same key doesn't run at all. A sequence with a target advances only on key presses inside the target.

### Elements that are removed

Solid doesn't call a `ref` with `null` when it removes an element, so a signal set by `ref` keeps the removed element, and the hotkey stays registered on it until the component unmounts. Keep the signal for an element the component always renders.

For an element inside `<Show>`, `<For>`, or another control flow that removes it, call `createHotkey` in the element's `ref` callback:
For an element inside `<Show>`, `<For>`, or another control flow that removes it, put the element and its `createHotkey` call in their own component. A `ref` callback runs outside the component's owner, so don't call `createHotkey` there:

```tsx
import { Show } from 'solid-js'
import { Show, createSignal } from 'solid-js'

function PanelBody() {
const [panel, setPanel] = createSignal<HTMLDivElement | null>(null)
createHotkey('Escape', () => closePanel(), () => ({ target: panel() }))
return (
<div ref={setPanel} tabindex={0}>
Panel content
</div>
)
}

function Panel(props: { open: boolean }) {
return (
<Show when={props.open}>
<div
ref={(el) => createHotkey('Escape', () => closePanel(), { target: el })}
tabIndex={0}
>
Panel content
</div>
<PanelBody />
</Show>
)
}
```

The `ref` callback runs inside the branch that renders the element. So the hotkey registers each time the element is created, and unregisters when Solid removes it.
The hotkey registers each time `<Show>` creates `PanelBody`, and unregisters when Solid removes it.

### A target is not a scope

Expand Down
19 changes: 3 additions & 16 deletions docs/framework/solid/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,16 @@ function Panel() {
createHotkey('Escape', () => closePanel(), () => ({ target: panel() }))

return (
<div ref={setPanel} tabIndex={0}>
<div ref={setPanel} tabindex={0}>
...
</div>
)
}
```

A `null` target waits until the element is attached. The hotkey fires while focus is on the element or inside it. If nothing there can take focus, give the element a `tabIndex`.
A `null` target waits until the element is attached. The hotkey fires while focus is on the element or inside it. If nothing there can take focus, give the element a `tabindex`.

Solid doesn't clear a ref when the element is removed, so the signal keeps a removed element. For an element inside `<Show>` or `<For>`, register the hotkey in the element's `ref` callback instead:

```tsx
<Show when={open()}>
<div
ref={(el) => createHotkey('Escape', () => closePanel(), { target: el })}
tabIndex={0}
>
...
</div>
</Show>
```

The callback runs each time the element is created, and the hotkey unregisters when the element is removed.
For an element inside `<Show>` or `<For>`, put the element and its `createHotkey` call in their own component, like `Panel` above. The hotkey unregisters when Solid removes the component.

## Add providers and scopes (optional)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: createHotkeyRegistrations
function createHotkeyRegistrations(): () => HotkeyRegistrationView[];
```

Defined in: [createHotkeyRegistrations.ts:23](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeyRegistrations.ts#L23)
Defined in: [createHotkeyRegistrations.ts:24](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeyRegistrations.ts#L24)

Solid primitive that reactively reads every hotkey registration, chords and
sequences, from the singleton HotkeyManager. Narrow each view with `kind`.
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/reference/functions/createHotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: createHotkeys
function createHotkeys(hotkeys, commonOptions?): void;
```

Defined in: [createHotkeys.ts:43](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeys.ts#L43)
Defined in: [createHotkeys.ts:42](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeys.ts#L42)

Solid primitive for registering several hotkeys at once: chords, sequences,
and app hotkeys. Pass an accessor for a reactive list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: useDefaultHotkeysOptions
function useDefaultHotkeysOptions(): HotkeysProviderOptions;
```

Defined in: [HotkeysProvider.tsx:199](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/HotkeysProvider.tsx#L199)
Defined in: [HotkeysProvider.tsx:205](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/HotkeysProvider.tsx#L205)

## Returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function useHotkeysContext():
| null;
```

Defined in: [HotkeysProvider.tsx:195](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/HotkeysProvider.tsx#L195)
Defined in: [HotkeysProvider.tsx:201](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/HotkeysProvider.tsx#L201)

## Returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: CreateHotkeyDefinition
type CreateHotkeyDefinition = AdapterHotkeyDefinition<CreateHotkeyTarget>;
```

Defined in: [createHotkeys.ts:23](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeys.ts#L23)
Defined in: [createHotkeys.ts:22](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeys.ts#L22)

One hotkey for `createHotkeys`. Chords accept `requireReset`; sequences
accept `timeout`; hotkeys of unknown kind accept only shared options.
4 changes: 3 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Start with the [Quick Start](./framework/preact/quick-start) guide and the Preac

# Solid

Use Solid 1.7 or newer within version 1. The devtools panel needs Solid 1.9.15 or newer.
Use Solid 2. `@tanstack/solid-hotkeys` 0.26 and `@tanstack/solid-hotkeys-devtools` 0.14 and newer need Solid 2, which needs Node 22.12 or newer.

For Solid 1 (1.7 or newer), install the last releases that support it: `@tanstack/solid-hotkeys@0.25` and, for the devtools panel (Solid 1.9.15 or newer), `@tanstack/solid-hotkeys-devtools@0.13`.

Start with the [Quick Start](./framework/solid/quick-start) guide and the Solid-specific [guides](./framework/solid/guides/hotkeys). If you want the integrated devtools panel, also install:

Expand Down
7 changes: 4 additions & 3 deletions e2e/adapters/apps/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"build": "vite build"
},
"dependencies": {
"@solidjs/web": "^2.0.3",
"@tanstack/solid-hotkeys": "workspace:*",
"solid-js": "^1.9.18"
"solid-js": "^2.0.3"
},
"devDependencies": {
"vite": "^8.3.7",
"vite-plugin-solid": "^2.11.15"
"@solidjs/vite-plugin": "^3.0.1",
"vite": "^8.3.7"
}
}
6 changes: 3 additions & 3 deletions e2e/adapters/apps/solid/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { render } from '@solidjs/web'
import {
createHeldKeys,
createHotkey,
Expand All @@ -6,8 +7,7 @@ import {
detectPlatform,
getHotkeyManager,
} from '@tanstack/solid-hotkeys'
import { Show, createSignal, onMount } from 'solid-js'
import { render } from 'solid-js/web'
import { Show, createSignal, onSettled } from 'solid-js'
import { exposeFixture, logCall, setRecorded } from '../../../shared/fixture'
import type { Hotkey } from '@tanstack/solid-hotkeys'

Expand All @@ -29,7 +29,7 @@ function App() {
const shiftHeld = createKeyHold('Shift')
const heldKeys = createHeldKeys()

onMount(() => {
onSettled(() => {
exposeFixture(
{ getHotkeyManager, detectPlatform },
{
Expand Down
2 changes: 1 addition & 1 deletion e2e/adapters/apps/solid/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import solid from '@solidjs/vite-plugin'
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'

export default defineConfig({
base: './',
Expand Down
6 changes: 0 additions & 6 deletions e2e/ssr/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,11 @@ export const examples: Array<SsrExample> = [
command: 'pnpm preview --port 4312',
static: true,
},
{
folder: 'solid/createFormatForDisplay-solid-start',
port: 4313,
command: 'pnpm start',
},
{
folder: 'solid/createFormatForDisplay-tanstack-start',
port: 4314,
command: 'pnpm preview --port 4314 --strictPort',
},
{ folder: 'solid/createFormatForDisplay-astro', port: 4315, command: astro },
{
folder: 'svelte/getFormatForDisplay-sveltekit',
port: 4316,
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectHeldKeys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectHotkey-sequences/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectHotkey/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectHotkeyRecorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectHotkeys-sequences/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectHotkeys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectKeyHold/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/keyboard-layouts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "^22.2.5",
"@angular/platform-browser-dynamic": "^22.2.5",
"@angular/router": "^22.2.5",
"@tanstack/angular-devtools": "^0.0.13",
"@tanstack/angular-devtools": "^0.0.14",
"@tanstack/angular-hotkeys": "^0.25.3",
"@tanstack/angular-hotkeys-devtools": "^0.5.14",
"rxjs": "~7.8.2",
Expand Down
Loading