Skip to content

Commit

Permalink
fix(gatsby): fix incorrect "inconsistent node counters" invariant #35020
Browse files Browse the repository at this point in the history
 (#35025)

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
imjoshin and pieh authored Mar 3, 2022
1 parent c621381 commit 8644398
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions packages/gatsby/src/datastore/__tests__/run-fast-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,5 +532,52 @@ describe(`edge cases (yay)`, () => {
expect(run).toThrow(
`Invariant violation: inconsistent node counters detected`
)

store.dispatch({
type: `DELETE_NODE`,
payload: badNode,
})
})

it(`works with subsequent, different filters (issue #34910)`, () => {
// shared filter cache
const filtersCache = new Map()

{
const filter1 = {
slog: { $eq: `def` }, // matches id_2 and id_4
}

const result1 = applyFastFilters(
createDbQueriesFromObject(filter1),
[typeName],
filtersCache,
[],
[]
)

expect(result1.length).toEqual(2)
expect(result1[0].id).toEqual(`id_2`)
expect(result1[1].id).toEqual(`id_4`)
}

{
const filter2 = {
slog: { $eq: `def` }, // matches id_2 and id_4
// important - new filter element
deep: { flat: { search: { chain: { $eq: 500 } } } }, // matches id_2
}

const result2 = applyFastFilters(
createDbQueriesFromObject(filter2),
[typeName],
filtersCache,
[`string`], // important - new sort field
[]
)

expect(result2.length).toEqual(1)
expect(result2[0].id).toEqual(`id_2`)
}
})
})
2 changes: 1 addition & 1 deletion packages/gatsby/src/datastore/in-memory/indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ export function intersectNodesByCounter(
} else if (counterA > counterB) {
pointerB++
} else {
if (a[pointerA] !== b[pointerB]) {
if (a[pointerA].id !== b[pointerB].id) {
throw new Error(
`Invariant violation: inconsistent node counters detected`
)
Expand Down

0 comments on commit 8644398

Please sign in to comment.