diff --git a/packages/gatsby/src/query/query-compiler.js b/packages/gatsby/src/query/query-compiler.js index d07d436d82753..51f70de376e5c 100644 --- a/packages/gatsby/src/query/query-compiler.js +++ b/packages/gatsby/src/query/query-compiler.js @@ -435,7 +435,9 @@ const determineUsedFragmentsForDefinition = ( ) => { const { def, name, isFragment, filePath } = definition const cachedUsedFragments = fragmentsUsedByFragment.get(name) - if (cachedUsedFragments) { + + // `cachedUsedFragments` could be a Set with size 0 which happens to be truthy + if (cachedUsedFragments?.size) { return { usedFragments: cachedUsedFragments, missingFragments: [] } } else { const usedFragments = new Set()