Skip to content

fix(store): snapshot subscribers before notifying - #185

Merged
JosunLP merged 2 commits into
devfrom
fix/165-store-notify-snapshot
Jul 6, 2026
Merged

fix(store): snapshot subscribers before notifying#185
JosunLP merged 2 commits into
devfrom
fix/165-store-notify-snapshot

Conversation

@JosunLP

@JosunLP JosunLP commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #165 (High).

notifySubscribers iterated the live subscribers array while unsubscribe splices it, so a self-detaching watcher caused the next subscriber to be silently skipped for that notification cycle.

Fix

Iterate a snapshot ([...subscribers]), mirroring the existing $onAction listener-snapshot guard in the same file.

Verification

  • Regression test with the exact issue repro (subscriber A self-unsubscribes, subscriber B must still fire); fails without the fix, passes with it.
  • bun test tests/store.test.ts: 95 pass / 0 fail. tsc --noEmit clean.

🤖 Generated with Claude Code

notifySubscribers iterated the live subscribers array, so a callback
that unsubscribes during notification spliced the array under the
for...of iterator and silently skipped the next subscriber (and could
double-invoke one added mid-notify). $onAction already snapshots its
listeners; $subscribe now gets the same treatment.

Fixes #165

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added store Changes to the store module tests Chenges to the tests labels Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c427b4d6-dafb-4825-bd3e-7175711d3b36

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/165-store-notify-snapshot

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.

@JosunLP
JosunLP merged commit ebf8a93 into dev Jul 6, 2026
6 checks passed
@JosunLP
JosunLP deleted the fix/165-store-notify-snapshot branch July 6, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Changes to the store module tests Chenges to the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant