Skip to content

#1313 Fixed missing ref re-assignment for conditionally rendered elements#1314

Merged
JohannesKlauss merged 4 commits into
JohannesKlauss:mainfrom
oleksandr-danylchenko:#1313-fix-ref-assignment-for-conditionally-rendered
May 1, 2026
Merged

#1313 Fixed missing ref re-assignment for conditionally rendered elements#1314
JohannesKlauss merged 4 commits into
JohannesKlauss:mainfrom
oleksandr-danylchenko:#1313-fix-ref-assignment-for-conditionally-rendered

Conversation

@oleksandr-danylchenko
Copy link
Copy Markdown
Contributor

@oleksandr-danylchenko oleksandr-danylchenko commented Feb 4, 2026

Issue

Fixes #1313

Relations

This PR is a revival of the #1132 initially suggested by @zeorin.

Changes Made

  1. Replaced the plain mutable ref with the reactive state. Its set state function acts as a "ref callback", causing the keyboard listeners to re-attach on the conditional element's rendering.
  2. Added test coverage for re-attaching the listeners to the conditionally rendered element and previously broken tabbing behavior.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 4, 2026

@oleksandr-danylchenko is attempting to deploy a commit to the Johannes Klauss' projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@zeorin zeorin left a comment

Choose a reason for hiding this comment

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

Implement a ref callback cleanup.

Comment thread packages/react-hotkeys-hook/src/lib/useHotkeys.ts Outdated
oleksandr-danylchenko added a commit to oleksandr-danylchenko/react-hotkeys-hook that referenced this pull request Feb 5, 2026
@oleksandr-danylchenko oleksandr-danylchenko force-pushed the #1313-fix-ref-assignment-for-conditionally-rendered branch from 08156d4 to 7a6fc14 Compare February 5, 2026 09:59
Copy link
Copy Markdown
Contributor

@zeorin zeorin left a comment

Choose a reason for hiding this comment

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

Apart from my remaining comment about explicitly importing RefCallback as a type, LGTM!

Comment thread packages/react-hotkeys-hook/src/lib/useHotkeys.ts Outdated
oleksandr-danylchenko added a commit to oleksandr-danylchenko/react-hotkeys-hook that referenced this pull request Feb 10, 2026
@oleksandr-danylchenko oleksandr-danylchenko force-pushed the #1313-fix-ref-assignment-for-conditionally-rendered branch from 7a6fc14 to 24a08f9 Compare February 10, 2026 09:36
@oleksandr-danylchenko oleksandr-danylchenko force-pushed the #1313-fix-ref-assignment-for-conditionally-rendered branch from 24a08f9 to e2063ea Compare February 10, 2026 09:37
@JohannesKlauss JohannesKlauss merged commit 0a77e50 into JohannesKlauss:main May 1, 2026
1 check failed
@oleksandr-danylchenko oleksandr-danylchenko deleted the #1313-fix-ref-assignment-for-conditionally-rendered branch May 1, 2026 11:51
mergify Bot pushed a commit to doxynix/doxynix that referenced this pull request May 4, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [@tanstack/eslint-plugin-query](https://tanstack.com/query) ([source](https://redirect.github.com/TanStack/query/tree/HEAD/packages/eslint-plugin-query)) | [`5.100.6` → `5.100.7`](https://renovatebot.com/diffs/npm/@tanstack%2feslint-plugin-query/5.100.6/5.100.7) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@tanstack%2feslint-plugin-query/5.100.7?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@tanstack%2feslint-plugin-query/5.100.6/5.100.7?slim=true) |
| [@tanstack/react-query](https://tanstack.com/query) ([source](https://redirect.github.com/TanStack/query/tree/HEAD/packages/react-query)) | [`5.100.6` → `5.100.7`](https://renovatebot.com/diffs/npm/@tanstack%2freact-query/5.100.6/5.100.7) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@tanstack%2freact-query/5.100.7?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@tanstack%2freact-query/5.100.6/5.100.7?slim=true) |
| [@tanstack/react-query-devtools](https://tanstack.com/query) ([source](https://redirect.github.com/TanStack/query/tree/HEAD/packages/react-query-devtools)) | [`5.100.6` → `5.100.7`](https://renovatebot.com/diffs/npm/@tanstack%2freact-query-devtools/5.100.6/5.100.7) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@tanstack%2freact-query-devtools/5.100.7?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@tanstack%2freact-query-devtools/5.100.6/5.100.7?slim=true) |
| [react-hotkeys-hook](https://react-hotkeys-hook.vercel.app/) ([source](https://redirect.github.com/JohannesKlauss/react-keymap-hook)) | [`5.2.4` → `5.3.0`](https://renovatebot.com/diffs/npm/react-hotkeys-hook/5.2.4/5.3.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/react-hotkeys-hook/5.3.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-hotkeys-hook/5.2.4/5.3.0?slim=true) |

---

### Release Notes

<details>
<summary>TanStack/query (@&#8203;tanstack/eslint-plugin-query)</summary>

### [`v5.100.7`](https://redirect.github.com/TanStack/query/blob/HEAD/packages/eslint-plugin-query/CHANGELOG.md#51007)

[Compare Source](https://redirect.github.com/TanStack/query/compare/@tanstack/eslint-plugin-query@5.100.6...@tanstack/eslint-plugin-query@5.100.7)

</details>

<details>
<summary>TanStack/query (@&#8203;tanstack/react-query)</summary>

### [`v5.100.7`](https://redirect.github.com/TanStack/query/blob/HEAD/packages/react-query/CHANGELOG.md#51007)

[Compare Source](https://redirect.github.com/TanStack/query/compare/@tanstack/react-query@5.100.6...@tanstack/react-query@5.100.7)

##### Patch Changes

- Updated dependencies \[]:
  - [@&#8203;tanstack/query-core](https://redirect.github.com/tanstack/query-core)@&#8203;5.100.7

</details>

<details>
<summary>TanStack/query (@&#8203;tanstack/react-query-devtools)</summary>

### [`v5.100.7`](https://redirect.github.com/TanStack/query/blob/HEAD/packages/react-query-devtools/CHANGELOG.md#51007)

[Compare Source](https://redirect.github.com/TanStack/query/compare/@tanstack/react-query-devtools@5.100.6...@tanstack/react-query-devtools@5.100.7)

##### Patch Changes

- docs(devtools): align logo, panel, and 'buttonPosition' union descriptions across docs and JSDoc ([#&#8203;10617](https://redirect.github.com/TanStack/query/pull/10617))

- Updated dependencies \[]:
  - [@&#8203;tanstack/query-devtools](https://redirect.github.com/tanstack/query-devtools)@&#8203;5.100.7
  - [@&#8203;tanstack/react-query](https://redirect.github.com/tanstack/react-query)@&#8203;5.100.7

</details>

<details>
<summary>JohannesKlauss/react-keymap-hook (react-hotkeys-hook)</summary>

### [`v5.3.0`](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/releases/tag/v5.3.0)

[Compare Source](https://redirect.github.com/JohannesKlauss/react-keymap-hook/compare/v5.2.4...v5.3.0)

#### What's Changed

- chore(deps): update dependency vite to v7.3.2 \[security] by [@&#8203;renovate](https://redirect.github.com/renovate)\[bot] in [JohannesKlauss/react-hotkeys-hook#1321](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1321)
- fix: prevent mod hotkey from triggering on Super/Windows key on non-macOS platforms by [@&#8203;samhoseinkhani](https://redirect.github.com/samhoseinkhani) in [JohannesKlauss/react-hotkeys-hook#1325](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1325)
- Update all non-major dependencies by [@&#8203;renovate](https://redirect.github.com/renovate)\[bot] in [JohannesKlauss/react-hotkeys-hook#1326](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1326)
- [#&#8203;1313](https://redirect.github.com/JohannesKlauss/react-keymap-hook/issues/1313) Fixed missing `ref` re-assignment for conditionally rendered elements by [@&#8203;oleksandr-danylchenko](https://redirect.github.com/oleksandr-danylchenko) in [JohannesKlauss/react-hotkeys-hook#1314](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1314)
- Add Key Blacklist Support to useRecordHotkeys by [@&#8203;vedmakk](https://redirect.github.com/vedmakk) in [JohannesKlauss/react-hotkeys-hook#1268](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1268)
- Update dependency [@&#8203;eslint/js](https://redirect.github.com/eslint/js) to v10 by [@&#8203;renovate](https://redirect.github.com/renovate)\[bot] in [JohannesKlauss/react-hotkeys-hook#1327](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1327)

#### New Contributors

- [@&#8203;samhoseinkhani](https://redirect.github.com/samhoseinkhani) made their first contribution in [JohannesKlauss/react-hotkeys-hook#1325](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1325)
- [@&#8203;oleksandr-danylchenko](https://redirect.github.com/oleksandr-danylchenko) made their first contribution in [JohannesKlauss/react-hotkeys-hook#1314](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1314)
- [@&#8203;vedmakk](https://redirect.github.com/vedmakk) made their first contribution in [JohannesKlauss/react-hotkeys-hook#1268](https://redirect.github.com/JohannesKlauss/react-hotkeys-hook/pull/1268)

**Full Changelog**: <JohannesKlauss/react-hotkeys-hook@v5.2.4...v5.3.0>

</details>

---

### Configuration

📅 **Schedule**: (in timezone Europe/Moscow)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://redirect.github.com/renovatebot/renovate).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ref used for scoping the useHotkeys breaks the tabbing behavior when assigned to conditionally rendered element

3 participants