From 48f3e68ba5e996a8efbb77b576cdf4073fad3090 Mon Sep 17 00:00:00 2001 From: Cody Olsen <81981+stipsan@users.noreply.github.com> Date: Mon, 20 Jan 2025 11:15:30 +0100 Subject: [PATCH] fix(presentation): avoid duplicate key warning (#8319) --- packages/sanity/src/presentation/loader/LoaderQueries.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/sanity/src/presentation/loader/LoaderQueries.tsx b/packages/sanity/src/presentation/loader/LoaderQueries.tsx index 103e69e051b..cdeaaba6f33 100644 --- a/packages/sanity/src/presentation/loader/LoaderQueries.tsx +++ b/packages/sanity/src/presentation/loader/LoaderQueries.tsx @@ -262,8 +262,12 @@ const Turbo = memo(function Turbo(props: TurboProps) { } } const nextBatchSlice = [...nextBatch].slice(0, LIVE_QUERY_CACHE_BATCH_SIZE) - if (nextBatchSlice.length === 0) return - setBatch((prevBatch) => [...prevBatch.slice(-LIVE_QUERY_CACHE_BATCH_SIZE), nextBatchSlice]) + if (nextBatchSlice.length === 0) return undefined + const raf = requestAnimationFrame(() => + // eslint-disable-next-line max-nested-callbacks + setBatch((prevBatch) => [...prevBatch.slice(-LIVE_QUERY_CACHE_BATCH_SIZE), nextBatchSlice]), + ) + return () => cancelAnimationFrame(raf) }, [batch, cache, turboIds]) // Use the same listen instance and patch documents as they come in