From 143406b8127064171b27115fdb5b5fa9de3218d3 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Thu, 16 Jan 2025 14:30:47 -0600 Subject: [PATCH] Fix relayStylePaginationWithNodes losing the first page of data --- src/lib/apollo/relayStylePaginationWithNodes.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/apollo/relayStylePaginationWithNodes.tsx b/src/lib/apollo/relayStylePaginationWithNodes.tsx index d757e1d7f..7a23f1665 100644 --- a/src/lib/apollo/relayStylePaginationWithNodes.tsx +++ b/src/lib/apollo/relayStylePaginationWithNodes.tsx @@ -77,6 +77,16 @@ export function relayStylePaginationWithNodes( incoming, { args, isReference, readField }, ) { + // `merge` can be called multiple times with the same incoming data as Apollo recursively + // merges data at various levels in the tree. If the incoming data is the same as the existing + // data, simply ignore it. + if ( + incoming.pageInfo?.endCursor && + incoming.pageInfo?.endCursor === existing.pageInfo.endCursor + ) { + return existing; + } + const incomingEdges = incoming.edges ? incoming.edges.map((edge) => { if (isReference((edge = { ...edge }))) {