https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
q

quiet-monkey-7986

05/22/2023, 11:47 AM
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

future-teacher-7046

05/22/2023, 11:52 AM
Hi Pedro, thanks for catching this. I think I found the issue. Working on a test case to reproduce it now
❤️ 1
1
q

quiet-monkey-7986

05/22/2023, 12:28 PM
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

future-teacher-7046

05/22/2023, 12:32 PM
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

quiet-monkey-7986

05/22/2023, 1:22 PM
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

future-teacher-7046

05/22/2023, 1:24 PM
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

quiet-monkey-7986

05/22/2023, 1:37 PM
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.
17 Views