From 1b811dfabc3fa8567058631853d72a0fe795c4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Thu, 7 Nov 2024 08:54:27 -0500 Subject: [PATCH] fix(base): support restoring cross dataset references --- .../src/datastores/history/createHistoryStore.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/@sanity/base/src/datastores/history/createHistoryStore.ts b/packages/@sanity/base/src/datastores/history/createHistoryStore.ts index 2c02b37ca00..c3044511b7f 100644 --- a/packages/@sanity/base/src/datastores/history/createHistoryStore.ts +++ b/packages/@sanity/base/src/datastores/history/createHistoryStore.ts @@ -120,7 +120,12 @@ const getAllRefIds = (doc) => jsonReduce( doc, (acc, node) => - node && typeof node === 'object' && '_ref' in node && !acc.includes(node._ref) + node && + typeof node === 'object' && + '_ref' in node && + // exclude cross dataset refs + !('_dataset' in node) && + !acc.includes(node._ref) ? [...acc, node._ref] : acc, [] @@ -149,7 +154,13 @@ function jsonMap(value, mapFn) { const mapRefNodes = (doc, mapFn) => jsonMap(doc, (node) => { - return node && typeof node === 'object' && typeof node._ref === 'string' ? mapFn(node) : node + return node && + typeof node === 'object' && + typeof node._ref === 'string' && + // exclude cross dataset refs + !('_dataset' in node) + ? mapFn(node) + : node }) export const removeMissingReferences = (doc, existingIds) =>