fix: prevent LateInitializationError when accessing untracked val#171
Conversation
…dValue Computed values are lazy — the selector only runs on first .value access. Accessing untrackedValue before that threw a LateInitializationError because the late field was never populated. - hasValue now triggers computation if not yet initialized - untrackedValue adds an assert with a helpful message - Add _initialized flag to track whether the selector has run
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 3 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR implements initialization tracking for the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #171 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 931 935 +4
=========================================
+ Hits 931 935 +4
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/solidart/lib/src/core/computed.dart (1)
126-128: Comment is misleading about initialization state.Line 126 says computed is “always initialized”, but Line 111 starts
_initializedasfalse. Please reword to avoid confusion for future maintenance.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/solidart/lib/src/core/computed.dart` around lines 126 - 128, The comment above the Computed implementation is misleading: it states a computed signal is "always initialized" while the private field `_initialized` is initialized to `false`; update the comment near the `Computed` class / the `_initialized` field (and the `hasValue` behavior comment) to accurately reflect that the computed's value is lazy and `_initialized` starts as false until the first access triggers evaluation, e.g., change "always initialized" to "structurally initialized but value is lazy" or similar concise wording so `_initialized`'s semantics match the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/solidart/lib/src/core/computed.dart`:
- Around line 187-192: The assert-only guard using _initialized must be replaced
with a runtime check that throws a clear exception when the computed hasn't been
initialized to avoid release-mode crashes: in the Computed class replace the
assert on _initialized (that returns _untrackedValue) with an if-check that
throws a StateError (or LateInitializationError with a helpful message) when
!_initialized, and likewise add a runtime guard in the value getter (and any
direct accesses to _untrackedValue, e.g., hasValue logic) to throw if the
computed is disposed or uninitialized instead of directly returning
_untrackedValue; reference symbols: _initialized, _untrackedValue, value getter,
and any disposed flag used by Computed.
---
Nitpick comments:
In `@packages/solidart/lib/src/core/computed.dart`:
- Around line 126-128: The comment above the Computed implementation is
misleading: it states a computed signal is "always initialized" while the
private field `_initialized` is initialized to `false`; update the comment near
the `Computed` class / the `_initialized` field (and the `hasValue` behavior
comment) to accurately reflect that the computed's value is lazy and
`_initialized` starts as false until the first access triggers evaluation, e.g.,
change "always initialized" to "structurally initialized but value is lazy" or
similar concise wording so `_initialized`'s semantics match the comment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3281cfc7-46ff-4e8a-af2f-bb5d322ee82f
📒 Files selected for processing (4)
packages/solidart/CHANGELOG.mdpackages/solidart/lib/src/core/computed.dartpackages/solidart/pubspec.yamlpackages/solidart/test/solidart_test.dart
Clarify comment about computed value computation.
closes #170
Accessing untrackedValue before that threw a LateInitializationError because the late field was never populated.
Summary by CodeRabbit
Bug Fixes
LateInitializationErrorwhen accessing computed values prematurely. Lazy computation now properly triggers on property access, and attempting incorrect access patterns now returns clearer error messages.Tests