From b681744a3e8ce0cdea6b16a8c9f754f1d3e22485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Thu, 7 Nov 2024 09:10:49 -0500 Subject: [PATCH] fix(base): support restoring cross dataset references (#7776) --- .../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) =>