Skip to content

fix(core): defer focus events in _changeFocus to prevent re-entrancy#1634

Merged
Karanjot786 merged 2 commits into
Karanjot786:mainfrom
ionfwsrijan:fix/1629-focusmanager-reentrancy
Jun 21, 2026
Merged

fix(core): defer focus events in _changeFocus to prevent re-entrancy#1634
Karanjot786 merged 2 commits into
Karanjot786:mainfrom
ionfwsrijan:fix/1629-focusmanager-reentrancy

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Description

_changeFocus() emits blur and focus events synchronously. Any subscriber can call unregister(), which mutates _focusables and adjusts _currentIndex. After handlers return, _changeFocus unconditionally overwrites _currentIndex = newIndex with the original pre-unregister value, corrupting focus state.

Fix

Deferred event emission (Approach A): collect blur/focus events into a queue, update _currentIndex first, then flush events. This ensures any re-entrant unregister() or focusNext() calls see the finalized _currentIndex.

Tests

  • unregister in blur handler does not corrupt _currentIndex
  • unregister in focus handler does not cause out-of-bounds access
  • re-entrant focusNext from focus handler does not corrupt state

Closes #1629

@ionfwsrijan ionfwsrijan requested a review from Karanjot786 as a code owner June 19, 2026 06:18
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@ionfwsrijan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 21 minutes and 32 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b8e0afc-8fca-4d76-b23f-6d1369b86e01

📥 Commits

Reviewing files that changed from the base of the PR and between 4b874c0 and 506fadb.

📒 Files selected for processing (2)
  • packages/core/src/events/FocusManager.test.ts
  • packages/core/src/events/FocusManager.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:core @termuijs/core type:testing +10 pts. Tests. labels Jun 19, 2026
@ionfwsrijan ionfwsrijan changed the title fix(core): defer focus events in _changeFocus to prevent re-entrancy … fix(core): defer focus events in _changeFocus to prevent re-entrancy Jun 19, 2026
@ionfwsrijan

Copy link
Copy Markdown
Contributor Author

@Karanjot786 Please review this

@Karanjot786 Karanjot786 merged commit 25d508f into Karanjot786:main Jun 21, 2026
6 checks passed
@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. level:intermediate +35 pts. Moderate task. quality:clean x 1.2 multiplier. Clean implementation. labels Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core gssoc:approved Approved PR. Earns +50 base points. level:intermediate +35 pts. Moderate task. quality:clean x 1.2 multiplier. Clean implementation. type:bug +10 pts. Bug fix. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] FocusManager _changeFocus re-entrancy causes _currentIndex corruption when handlers call unregister

2 participants