Hey, I'm trying to work my way through a tiny project whilst upskilling in FE & Remix. I'm probably doing something really dumb but I've been messing about for a while now on this to no avail - it's a Zod/Loader/Cachified issue for context.
My code works without a schema validation fine, but as soon as I introduce the schema validation either by checkValue within the cache or as a function which takes the response.json() as an argument and then validates the response - it tells me that the response.json() is all of a sudden undefined!?!
const dataLRU = new LRUCache<string, CacheEntry>({max: 30_000})
const dataCache = lruCacheAdapter(dataLRU)
export default function getById(id: string) {
return cachified({
// checkValue: zodSchema,
cache: dataCache,
key: id.toString(),
async getFreshValue() {
const response = await fetch(`url/${id}`)
return await response.json()
},
ttl: 300_000
})
}
This is a working example of my setup, a loader is calling getById and passing an ID and it's returning and caching the response as expected. As soon as I uncomment the checkValue: zodSchema line, i'm getting an error telling me that the input is undefined (I think).
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",