CODAP-1117: fix MobX constraint violation in cachedFnWithArgsFactory#2393
CODAP-1117: fix MobX constraint violation in cachedFnWithArgsFactory#2393
Conversation
Replace observable.map cache with observable version counters (per-key and global) paired with a plain Map, so the getter never writes to an observable. This follows the same pattern as observableCachedFnFactory from PR #2377, avoiding the anti-pattern of modifying observables during computed/view evaluation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #2393 +/- ##
===========================================
- Coverage 85.45% 69.25% -16.21%
===========================================
Files 753 753
Lines 41500 41509 +9
Branches 10235 10235
===========================================
- Hits 35462 28745 -6717
- Misses 6028 12758 +6730
+ Partials 10 6 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
codap-v3
|
||||||||||||||||||||||||||||
| Project |
codap-v3
|
| Branch Review |
main
|
| Run status |
|
| Run duration | 05m 22s |
| Commit |
|
| Committer | Kirk Swenson |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
73
|
|
|
0
|
|
|
300
|
| View all changes introduced in this branch ↗︎ | |
There was a problem hiding this comment.
Pull request overview
This PR fixes a MobX constraint violation in cachedFnWithArgsFactory by removing observable writes from within the cached getter, aligning the implementation with the version-counter pattern introduced for observableCachedFnFactory (PR #2377).
Changes:
- Replaces the observable-map cache with a plain
Mapplus observable version counters (per-key + global) so the getter only reads observables. - Implements per-key invalidation via an observable map of key versions and global invalidation via an observable box counter.
- Adds unit tests to verify per-key reaction isolation (
invalidate()) and full invalidation behavior (invalidateAll()).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| v3/src/utilities/mst-utils.ts | Refactors cachedFnWithArgsFactory to use MobX version counters + non-observable cache storage to avoid observable writes during derivation. |
| v3/src/utilities/mst-utils.test.ts | Adds MobX reaction-based tests to confirm invalidate() only affects the targeted key and invalidateAll() affects all keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Simplify cache-miss check (lint fix) and add note about running git commands from the repo root to avoid v3/v3 path errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
scytacki
left a comment
There was a problem hiding this comment.
This looks good to me. Just a comment about how the test is assuming synchronous reactions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
cachedFnWithArgsFactorywhere the getter wrote to anobservable.mapduring computed/view evaluationMap, so the getter only reads observables — matching the pattern established byobservableCachedFnFactoryin PR CODAP-1086: Fix formula recalculation when items are added via plugins #2377observable.map) handleinvalidate(); a global version counter (observable.box) handlesinvalidateAll()invalidateAll()behaviorAddresses CODAP-1117
Test plan
cachedFnWithArgsFactorytests passinvalidate()only triggers reactions for the affected keyinvalidateAll()triggers reactions for all keysdata-configuration-modeltests pass (consumer ofcachedFnWithArgsFactory)🤖 Generated with Claude Code