Skip to content

Commit

Permalink
fix(base): support restoring cross dataset references
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Nov 7, 2024
1 parent 547637e commit 5ec117d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/@sanity/base/src/datastores/history/createHistoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
[]
Expand Down Expand Up @@ -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) =>
Expand Down

0 comments on commit 5ec117d

Please sign in to comment.