Skip to content

fix: effect re-entrancy#174

Merged
nank1ro merged 4 commits into
mainfrom
fix/effect-re-entrancy
May 21, 2026
Merged

fix: effect re-entrancy#174
nank1ro merged 4 commits into
mainfrom
fix/effect-re-entrancy

Conversation

@nank1ro
Copy link
Copy Markdown
Owner

@nank1ro nank1ro commented May 21, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed effect re-entrancy that could cause initialization errors when a signal is updated during an effect’s initial run.
  • Tests

    • Added tests covering effect re-entrancy and safe lazy initialization during effect setup.
  • Chores

    • Package version bumps: solidart → 2.8.6, flutter_solidart → 2.7.4, solidart_hooks → 3.1.4.
  • Documentation

    • Changelog entries added documenting the fix.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@nank1ro has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 31 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3ae026fd-c5dc-4ee3-afcd-9b7dfe0a0ab2

📥 Commits

Reviewing files that changed from the base of the PR and between 7094d6c and ddb4322.

📒 Files selected for processing (1)
  • packages/solidart/test/reentrancy_test.dart

Walkthrough

Effect.run() now opens a reactive batch after switching to the internal subscriber and closes it in finally (before restoring the previous subscriber), preventing signal writes during the first effect run from re-entering the effect. Tests validate both re-entrancy and late-initialization edge cases; package versions and changelogs are updated.

Changes

Effect re-entrancy batching fix

Layer / File(s) Summary
Effect batching implementation
packages/solidart/lib/src/core/effect.dart
Effect.run() now starts a reactive batch after setting the current subscriber and guarantees reactiveSystem.endBatch() is called in the finally block before restoring the previous subscriber, grouping updates during _internalEffect.run() to prevent re-entrancy.
Re-entrancy test validation
packages/solidart/test/reentrancy_test.dart
Adds two tests: one ensuring the effect callback does not re-enter when a subscribed signal is written during the first run, and another verifying a late final read inside the effect remains safe when the effect-triggered write occurs during initialization.
Version and changelog updates
packages/solidart/CHANGELOG.md, packages/solidart/pubspec.yaml, packages/flutter_solidart/CHANGELOG.md, packages/flutter_solidart/pubspec.yaml, packages/solidart_hooks/CHANGELOG.md, packages/solidart_hooks/pubspec.yaml
Bumps solidart 2.8.5→2.8.6 with changelog entry; flutter_solidart 2.7.3→2.7.4 and solidart dep ^2.8.5→^2.8.6; solidart_hooks 3.1.3→3.1.4 and flutter_solidart dep ^2.7.3→^2.7.4, each with changelog entries.

🎯 2 (Simple) | ⏱️ ~10 minutes


🐰 A batch of updates hops in today,
No more effects re-entering mid-play,
With signals all grouped in atomic grace,
Late values now safe in their proper place,
Three packages hop up in harmony's way!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: effect re-entrancy' directly and clearly describes the main change: fixing an effect re-entrancy issue that prevents mid-execution writes from causing LateInitializationError.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/effect-re-entrancy

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (46cac53) to head (ddb4322).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #174   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines          937       939    +2     
=========================================
+ Hits           937       939    +2     
Files with missing lines Coverage Δ
packages/solidart/lib/src/core/effect.dart 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/solidart/test/reentrancy_test.dart (1)

4-72: ⚡ Quick win

Consider resetting SolidartConfig.autoDispose in tearDown.

Both test cases modify SolidartConfig.autoDispose but don't reset it, which could affect test isolation if tests run sequentially in the same process.

♻️ Proposed fix to reset config after each test
 void main() {
   group('effect re-entrancy during initial run', () {
+    late bool originalAutoDispose;
+    
+    setUp(() {
+      originalAutoDispose = SolidartConfig.autoDispose;
+    });
+    
+    tearDown(() {
+      SolidartConfig.autoDispose = originalAutoDispose;
+    });
+
     test(
       '''a signal write during the effect first run does not re-enter the effect callback while it is still on the stack''',
       () {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/solidart/test/reentrancy_test.dart` around lines 4 - 72, Each test
mutates SolidartConfig.autoDispose and doesn't restore it; capture the original
value (e.g. var _prev = SolidartConfig.autoDispose) at the start of each test
and register an addTearDown that restores it (addTearDown(() =>
SolidartConfig.autoDispose = _prev)); update both tests (the ones creating
Effect and using SolidartConfig.autoDispose) so the global config is restored
after each run.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/solidart/test/reentrancy_test.dart`:
- Around line 4-72: Each test mutates SolidartConfig.autoDispose and doesn't
restore it; capture the original value (e.g. var _prev =
SolidartConfig.autoDispose) at the start of each test and register an
addTearDown that restores it (addTearDown(() => SolidartConfig.autoDispose =
_prev)); update both tests (the ones creating Effect and using
SolidartConfig.autoDispose) so the global config is restored after each run.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85e3f424-5a34-49be-9b9f-b8ddb85a150c

📥 Commits

Reviewing files that changed from the base of the PR and between 46cac53 and 125a2ae.

📒 Files selected for processing (8)
  • packages/flutter_solidart/CHANGELOG.md
  • packages/flutter_solidart/pubspec.yaml
  • packages/solidart/CHANGELOG.md
  • packages/solidart/lib/src/core/effect.dart
  • packages/solidart/pubspec.yaml
  • packages/solidart/test/reentrancy_test.dart
  • packages/solidart_hooks/CHANGELOG.md
  • packages/solidart_hooks/pubspec.yaml

@nank1ro nank1ro merged commit 000ee13 into main May 21, 2026
2 checks passed
@nank1ro nank1ro deleted the fix/effect-re-entrancy branch May 21, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant