thetarnav
Resource with async cache
Whats the pattern for using resources with caching that may be async?
What I mean by that is that my
cache_get
function returns a promise so I cannot set it to the initialValue
option of resources.
I want to display the cached value while I fetch the actual, (the cached value is considered stale) so I cannot simply add it to the fetcher
.
I thought that using mutate
with res.latest
would give the desired behaviour, where Suspense
is only triggered when initially, and not-triggered when cached value is set.
Here are my two attempts:
one with transitions:
https://playground.solidjs.com/anonymous/6b0c7b0f-d2ec-458a-8536-883da3ae55a6
and one with additional signals:
https://playground.solidjs.com/anonymous/ef897a99-c8da-4a17-84a4-68772a0cb934
Although they do kinda work, they feel incorrect.
They both have the same problem that the "user" cannot easily control whether he wants to show the cached value or not. (As they could with res.latest
and initialValue
)
It seems that maybe calling mutate
should set resuorce into "refreshing"
state.6 replies
Check if the code runs in CSR or CSR + hydration
Is there a way to check if the code runs during hydration or just normal CSR, the same way you are able to check if you are on the server or clinet using
isServer
or export conditions?
This is mostly about authoring libraries, where you want to run different logic depending on if the env is SSR / CRS / CRS + hydration.
it's related to the issue here: https://github.com/solidjs-community/solid-primitives/issues/31047 replies