accessing store multiple time, in batch() causes infinite loop
Calling store's function within the loop causes infinite rendering. The batch function is inside
createEffect
.
How could I avoid an infinite loop, while still updating the objects 1 by 1 ?5 Replies
Are you required to track
collection.cards
I am not exactly certain. I have a grid of cards, each card has its own picture which is retrieved by some async call to supabase.
I thought about making a request for each card and updating the store in order to cache the generated signedUrl for the picture
Not exactly your question, but do you know that the batch only batches up to the first
await
(after which point the callback/effect has ended from solid's point of view)?no, didn't know 🤔
Solid's global listener stack doesn't really work properly if you have other things executing at the same time as the effect (which is what may happen with async code), so it doesn't even try to handle it. The moment a function returns (which, in an async function, happens at the first await), the effect is over, even though it has returned a promise that can be awaited
Anyway, I think that means that every time you update a card, it immediately triggers the effect (before it even continues to the rest of the cards), and isn't caught by the batch
BTW, all effects are already wrapped in a batch, so explicitly batching only makes a difference outside effects (like in an event handler)