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

未关闭
#288 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
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 分钟
30 天内合并 PR
68

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/hotkeys 的其他 Issue

查看 TanStack/hotkeys 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。