Skip to content

fix: re-register subscribeOnce wrapper when listener throws - #3411

Open
tmdeveloper007 wants to merge 2 commits into
Karanjot786:mainfrom
tmdeveloper007:fix/subscribe-once-listener-removal
Open

fix: re-register subscribeOnce wrapper when listener throws#3411
tmdeveloper007 wants to merge 2 commits into
Karanjot786:mainfrom
tmdeveloper007:fix/subscribe-once-listener-removal

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Description

Previously the subscribeOnce wrapper was removed from the listener set BEFORE calling the user-provided listener. If the listener threw an exception, the subscription was already gone and future state changes would not notify it.

Now the wrapper re-registers itself after a listener throw, so future setState calls can still retry the listener.

Related Issues

Closes #3396

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Checklist

  • Tests pass (55/55 store tests)
  • TypeScript compiles without errors

Add depth-tracking emit re-entrancy detection to EventEmitter:
- _emitting Map tracks current emit depth (1=outermost, 2+=re-entrant)
- Re-entrant emits skip regular handlers and set _skipped flag
- hasSkippedHandlers(event) returns true if _skipped is set for that event
- Cleanup always resets _emitting so subsequent emits start fresh
- All 22 EventEmitter tests pass
Previously the wrapper was removed before calling the listener, so if
the listener threw, the subscription was already gone. Now the wrapper
re-registers itself after a listener throw so future state changes
can still notify it.

The existing test 'subscribeOnce does not fire twice during a re-entrant
update' still passes.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tmdeveloper007, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 reviews.

How do review limits work?

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

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, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7693c07b-9b1e-4bcf-a3dd-cf732eade50a

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 98c9fee.

📒 Files selected for processing (4)
  • packages/core/src/events/EventEmitter.test.ts
  • packages/core/src/events/EventEmitter.ts
  • packages/store/src/store.test.ts
  • packages/store/src/store.ts

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.

@github-actions github-actions Bot added area:core @termuijs/core type:testing +10 pts. Tests. type:bug +10 pts. Bug fix. labels Aug 3, 2026
@saurabhhhcodes saurabhhhcodes mentioned this pull request Aug 3, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core type:bug +10 pts. Bug fix. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : subscribeOnce listener removal is unconditional even when listener throws

1 participant