Skip to content

Commit c2fff6f

Browse files
authored
Don't throw error if query not in page/layout component fixes #2030 (#3294)
* Don't throw error if query not in page/layout component fixes #2030 We were throwing errors for what actually wasn't an error. Which is confusing enough but also, to add insult to injury, the error message is inscrutable. This PR removes the invalid check. * remove unused import
1 parent b2227c7 commit c2fff6f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

packages/gatsby/src/internal-plugins/query-runner/query-watcher.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const { store } = require(`../../redux/`)
1515
const { boundActionCreators } = require(`../../redux/actions`)
1616
const queryCompiler = require(`./query-compiler`).default
1717
const queue = require(`./query-queue`)
18-
const invariant = require(`invariant`)
1918
const normalize = require(`normalize-path`)
2019

2120
exports.extractQueries = () => {
@@ -88,14 +87,12 @@ const watch = rootDir => {
8887
queryCompiler().then(queries => {
8988
const components = store.getState().components
9089
queries.forEach(({ text }, id) => {
91-
invariant(
92-
components[id],
93-
`${id} not found in the store components: ${JSON.stringify(
94-
components
95-
)}`
96-
)
97-
98-
if (text !== components[id].query) {
90+
// Queries can be parsed from non page/layout components e.g. components
91+
// with fragments so ignore those.
92+
//
93+
// If the query has changed, set the new query in the store and run
94+
// its queries.
95+
if (components[id] && text !== components[id].query) {
9996
boundActionCreators.replaceComponentQuery({
10097
query: text,
10198
componentPath: id,

0 commit comments

Comments
 (0)