Angular (zoneless): `enabled` is applied in an effect, so a key matched before the next change detection sees the old value

オープン
#288 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
angular, typescript
領域
frontend

調査の方向性

Start with the Angular adapter's injectHotkeys implementation and trace how enabled reaches the hotkey manager's #isLive matching path. Use the linked StackBlitz reproduction to compare nested-scope behavior when enabled changes before another keydown. Done means the inner handler stops running after its scope is disabled and the parent handles subsequent keys; check whether a fix affects other adapters or core behavior.

索引モデルが issue の本文から書いたものです。

説明

TanStack Hotkeys version

@tanstack/angular-hotkeys 0.25.2 (@tanstack/hotkeys 0.33.0)

Framework/Library version

Angular 22.2.3

Describe the bug and the steps to reproduce it

injectHotkeys applies a reactive enabled from an Angular effect, so the manager only sees the new value after the next change detection. A key that arrives before then is matched against the old value. When one handler disables a nested scope, the next key runs that scope's handler instead of falling through to the parent.

Hand-typed keys usually leave time for change detection, so this mostly shows with programmatic events and automated tests. This is not #105 (callback form to avoid re-registration). The issue is when enabled is read, not how often the registration is updated.

Example: nested scopes bind ArrowDown. The inner one moves a row while row < 4, the outer one logs a "cross". Eight presses should give four moves, then four crosses.

Steps (fail every run in Chromium and Firefox):

  1. Click "Set row to 4, then one keydown, in one task". Expected cross at 4, actual move from 4.
  2. Click Reset, then "Dispatch 8 keydowns in one task". Expected 4 moves then 4 crosses, actual 8 moves.

Runs that gave the expected log, of 20 (Playwright 1.64.1, Chromium 156, Firefox 157):

Input Chromium Firefox
Steps 1 and 2 0 0
Eight keyboard.press 1 20
Eight keyboard.down (held) 0 20

Workaround: a capture-phase keydown listener on an ancestor that calls ApplicationRef.tick().

Possible fixes (ideas only, not checked against other adapters or the core):

  1. enabled?: boolean | (() => boolean), read when the key is matched (#isLive).
  2. A hook that runs before matching, so an adapter can flush pending effects.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/stackblitz-starters-xxhahcn7

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Maybe, I'll investigate and start debugging

Terms & Code of Conduct
  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
主要言語
TypeScript
スター
761
フォーク
50
平均マージ
6時間 51分
マージ済み PR(30日)
68

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/hotkeys のほかの issue

TanStack/hotkeys の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。