Ability to clear selector caches
See original GitHub issueHi there, we have an app using v0.1.2
of Recoil and tried today to upgrade to v0.2.0
but ran into an issue. It seems that atom state is being shared across different instances of RecoilRoot
which makes it difficult to test certain types of default
values.
For example, we have an atomFamily
that derives the default values based on URL params. In our tests, we set up the URL state and then access the atomFamily
. With this caching we are now seeing, this means that only the first test works properly as the subsequent tests do not actually retrieve the value from the URL.
Here is a simplified reproduction for clarity.
I know in the documentation there is note about this:
Note that caches, such as selector caches, may be shared across roots.
But you’ll note in the reproduction above, that even using reset()
doesn’t appear to invalidate the cache. (I also tried using key
, but that yielded the same results.)
Is this intended behavior? If so, what would be the recommended approach to fixing this? Is there some method to clear the Recoil caches or force the RecoilRoot to not use the cache?
Thanks in advance for your help!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:25 (8 by maintainers)
Top GitHub Comments
It’s been a little bit since I followed up on this, but happy to report that with the new “refresh” API and this example in the docs, we were able to get our app upgraded to the latest version of Recoil and all tests fixed/passing.
Thanks to everyone that contributed to this!
@trentmwillis Where has
testingSnapshot
meant to come from in the example?