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

Đang mở
#288 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
angular, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
TypeScript
Star
761
Fork
50
Merge trung bình
6 giờ 51 phút
Pull request đã merge (30 ngày)
68

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/hotkeys

Tất cả issue của TanStack/hotkeys

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.