-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] - Add option to selectors to scope cache to RecoilRoot #2224
Comments
@brandonFaf can you link to a https://codesandbox.io/ that demonstrates this issue? ❤️ |
@FokkeZB There is one dynamic route that is /example/[id].
**Note: you will only see the suspense fallback show on the client I believe due to this issue
You will not see that the selector is running. Since the page isn’t cached (thats why you still see the console log for rendering the page) that means a new |
There is a workaround if you want to scope a selector by a Recoil store. You can create an atom with an atom effect that initializes it with the store ID (something like |
Thanks @drarmstr! Would the selector cache memory still be in use on the server, after a request completes? We just render a single More generally, are there patterns or best practices for using recoil server-side, with SSR or server components? Or is recoil really more designed for client-side usage, even it can be made to work server-side? Thanks! |
You can set the cache policy for the selector to be |
Thanks @drarmstr! Would the selector caches be eligible for GC when the server request completes? Or would we have lot of caches of size 1, gradually increasing per request? |
Hello friends,
Request
I would like to suggest an option to allow a selector to be cached respective to a
RecoilRoot
rather than the application.Context
From a strictly client side approach, caching globally/application level doesn't seem to cause any problems. However, I am trying to use recoil in a Server Side Rendered application using Nextjs 13. I am seeing an undesired behavior where a selector is not rerun on the server when rendering a page if it has been run because the page has been requested previously. It seems that the cache is not tied to a
RecoilRoot
, which makes sense based off of the documentation. This is undesireable because it increases the risk of cached data being accessed accidentally or stale data being rendered.Code Suggestion
I would suggest adding an option to a selector allowing a user to specify if the cache should be tied to a
RecoilRoot
.Questions
The text was updated successfully, but these errors were encountered: