Skip to content

Commit

Permalink
fix(base): support restoring cross dataset references (#7776)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge authored Nov 7, 2024
1 parent 547637e commit b681744
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 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,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,
[]
Expand Down Expand Up @@ -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) =>
Expand Down

0 comments on commit b681744

Please sign in to comment.