refine
refine copied to clipboard
[BUG] accessControlProvider cacheTime does not seem to be working
Describe the bug
Hi, I have the following Refine setup:
<Refine
routerProvider={routerProvider}
authProvider={authProviderClient}
dataProvider={dataProvider}
liveProvider={liveProvider(supabaseBrowserClient)}
notificationProvider={useNotificationProvider}
accessControlProvider={{
can,
options: {
buttons: {
hideIfUnauthorized: true,
},
queryOptions: {
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 5 * 60 * 1000, // 5 minutes
}
}
}}
i18nProvider={i18nProvider}
resources={[
{
name: "home",
list: "/",
options: {
hide: true,
}
},
{
name: "admin",
list: "/admin",
meta: { role: "admin" },
options: {
hide: true,
}
},
{
name: "agent",
list: "/agent",
meta: { role: "agent" },
options: {
hide: true,
}
},
{
name: "customer_support",
list: "/customer-support",
meta: { role: "customer_support" },
options: {
hide: true,
}
},
{
name: "printing_house",
list: "/printing-house",
meta: { role: "printing_house" },
show: "/printing-house/show/:id",
options: {
// hide: true,
}
},
>
{children}
<RefineKbar />
</Refine>
When I'm loading a page -- for example -- /printing-house, the can function runs every time for each resource and if the current route is wrapped with CanAccess then it waits for the execution of the can function for all resources, which makes loading of pages very slow...
I tried using cacheTime to cahce the results but does not seem to do anything. The can function still runs for each resource and the slow behavior keeps occuring.
Steps To Reproduce
- Copy my setup
- Wrap a route with CanAccess
- Initial load
- Reload page and see if can still runs again and if it's slow
Expected behavior
Resource control needs to be determined on first run and then cached for the cache time.
Packages
- @refinedev/antd
- @refinedev/nextjs
Additional Context
Additionally, I was wondering if there is a way to prioritize checking access for the current resource and then showing it immediately instead of having to wait for all the checks. That would solve the issue as well.