Replies: 1 comment 3 replies
-
if you need caching there, why not use query for that? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In TanStack/Router, there are two types of contexts: Router-level and Route-level contexts. However, only the initially provided Router context remains persistent. An application could benefit if dynamically added context values could also be persisted.
Let me explain a problem I’m currently facing.
I heavily rely on Server Functions, which are secured by middleware. This middleware redirects visitors to an authentication page if no session is present or, if unauthorized, to the homepage.
The issue is that I also need to restrict access to certain pages for unauthenticated or unauthorized visitors. My approach is to check whether a visitor has the required permissions. User permissions are available at
context.roles
, which is set in a layout route using thebeforeLoad
function. As described in the documentation,beforeLoad
is the recommended way to provide context specific to child components/routes. However, whenever a visitor navigates to a different page, all roles and permissions are re-fetched.I would like to implement a caching mechanism for route(r) contexts to avoid repeatedly fetching data. While I understand the importance of working with the latest dataset, I’d like a feature similar to loaders, where data can be marked as stale after a specific duration. This would allow contexts to retain their values for a set period before being refreshed.
Beta Was this translation helpful? Give feedback.
All reactions