From 5ec117d00f6526446b0789429f4d8c174021c7eb 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/@sanity/base/src/datastores/history/createHistoryStore.ts b/packages/@sanity/base/src/datastores/history/createHistoryStore.ts index 2c02b37ca006..e4569355a101 100644 --- a/packages/@sanity/base/src/datastores/history/createHistoryStore.ts +++ b/packages/@sanity/base/src/datastores/history/createHistoryStore.ts @@ -120,7 +120,11 @@ 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 && + !('_dataset' in node) && + !acc.includes(node._ref) ? [...acc, node._ref] : acc, [] @@ -149,7 +153,12 @@ 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' && + !('_dataset' in node) + ? mapFn(node) + : node }) export const removeMissingReferences = (doc, existingIds) =>