Skip to content

Commit

Permalink
fix(initial): when your index has objects without contentDigest, thos…
Browse files Browse the repository at this point in the history
…e should be skipped

fixes #167
  • Loading branch information
Haroenv committed Nov 29, 2022
1 parent e622693 commit a9c1bd2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function fetchExistingObjects(index, reporter, cache) {
batch: batch => {
if (Array.isArray(batch)) {
batch.forEach(hit => {
if (hit.internal.contentDigest) {
if (hit.internal?.contentDigest) {
hits[hit.objectID] = hit;
}
});
Expand Down Expand Up @@ -260,15 +260,15 @@ async function runIndexQueries(
if (queryResultsMap.hasOwnProperty(id)) {
// key matches fresh objects, so compare match fields
const newObj = queryResultsMap[id];
if (!newObj.internal.contentDigest) {
if (!newObj.internal?.contentDigest) {
reporter.panicOnBuild(
'the objects must have internal.contentDigest. Current object:\n' +
JSON.stringify(newObj, null, 2)
);
}

if (
existingObj.internal.contentDigest !== newObj.internal.contentDigest
existingObj.internal?.contentDigest !== newObj.internal.contentDigest
) {
// contentDigest differs, so index new object
toIndex[id] = newObj;
Expand All @@ -283,7 +283,7 @@ async function runIndexQueries(
// not in any query
!allObjectsMap.hasOwnProperty(id) &&
// managed by this plugin
existingObj.internal.contentDigest
existingObj.internal?.contentDigest
) {
toRemove[id] = true;
}
Expand Down

0 comments on commit a9c1bd2

Please sign in to comment.