Hey all, I realize that the localStorage is not u...
# ask-questions
q
Hey all, I realize that the localStorage is not updating after expiring staleTTL. Any thoughts? It's requesting after this expiring directly from API on every reload, not updating the localStorage.
f
Hi Pedro, thanks for catching this. I think I found the issue. Working on a test case to reproduce it now
❤️ 1
1
q
Another thing I'd like to let you know is that when I change from
localStorage
to
sessionStorage
(Or any contract) on
setPolyfills
, it doesn't utilize the cache. It saves correctly, but it doesn't utilize it. Ex:
Copy code
const cache = new Map();

setPolyfills({
  localStorage: {
    getItem: (key) => cache.get(key),
    setItem: (key, value) => cache.set(key, value)
  }
});
f
The SDK only uses localStorage (or whatever polyfill you configure) once during the initial page load. After that, it uses its own in-memory cache and periodically syncs the state back to localStorage. If localStorage updates from someplace else, it won't get picked up automatically.
Basically, localStorage is only used to restore initial state across page views. After that, a fast in-memory cache is used instead
q
Basically, localStorage is only used to restore initial state across page views. After that, a fast in-memory cache is used instead (editado)
Thank you for the answer, but the problem is with that initial state, using whatever polyfill but localStorage, it doesn't use it for initialState. Instead, it requests again to the API on every refresh. With the localStorage config, it takes on the initial state until the staleTTL expires; after it the problem I've told you before occurs, it doesn't update the localStorage and never uses it again for new initial states.
f
When are you setting the polyfill? It must be set before creating the first
GrowthBook
instance. As for the staleTTL issue, I was able to reproduce the bug. I'll work on a fix today.
q
When are you setting the polyfill? It must be set before creating the first
GrowthBook
instance.
That was the problem, thank you.
As for the staleTTL issue, I was able to reproduce the bug. I'll work on a fix today.
Thank you so much.