Skip to content

Commit 089f898

Browse files
committed
Do not mark page query as dirty when component has babel errors
1 parent 02e00fa commit 089f898

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/gatsby/src/redux/reducers/__tests__/queries.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,50 @@ describe(`query extraction`, () => {
465465
expect(state.trackedQueries.get(`/bar`)).toEqual({ dirty: 1 })
466466
})
467467

468+
it(`doesn't mark page query as dirty if component has babel errors`, () => {
469+
// extract to a valid state first and run to reset initial dirty flag
470+
state = editFooQuery(state, ComponentQueries.foo)
471+
state = reducer(
472+
state,
473+
queryExtractionBabelError(
474+
{ componentPath: `/foo.js`, error: new Error(`Babel error`) },
475+
{} as any
476+
)
477+
)
478+
expect(state.trackedQueries.get(`/foo`)?.dirty).toEqual(0) // sanity-check
479+
state = reducer(
480+
state,
481+
queryExtracted({ componentPath: `/foo.js`, query: `` }, {} as any)
482+
)
483+
expect(state.trackedQueries.get(`/foo`)?.dirty).toEqual(0)
484+
})
485+
486+
it(`recovers after component babel errors`, () => {
487+
// extract to a valid state first and run to reset initial dirty flag
488+
state = editFooQuery(state, ComponentQueries.foo)
489+
state = reducer(
490+
state,
491+
queryExtractionBabelError(
492+
{ componentPath: `/foo.js`, error: new Error(`Babel error`) },
493+
{} as any
494+
)
495+
)
496+
state = reducer(
497+
state,
498+
queryExtracted({ componentPath: `/foo.js`, query: `` }, {} as any)
499+
)
500+
expect(state.trackedQueries.get(`/foo`)?.dirty).toEqual(0) // sanity-check
501+
state = reducer(
502+
state,
503+
queryExtractedBabelSuccess({ componentPath: `/foo.js` }, {} as any)
504+
)
505+
state = reducer(
506+
state,
507+
queryExtracted(ComponentQueries.fooEdited, {} as any)
508+
)
509+
expect(state.trackedQueries.get(`/foo`)?.dirty).toEqual(2)
510+
})
511+
468512
it(`marks all page queries associated with the component as dirty when query text changes`, () => {
469513
state = editFooQuery(state, ComponentQueries.fooEdited)
470514

packages/gatsby/src/redux/reducers/queries.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ export function queriesReducer(
105105
// TODO: use hash instead of a query text
106106
const { componentPath, query } = action.payload
107107
const component = registerComponent(state, componentPath)
108+
if (hasFlag(component.errors, FLAG_ERROR_BABEL)) {
109+
return state
110+
}
108111
if (component.query !== query) {
109112
// Invalidate all pages associated with a component when query text changes
110113
component.pages.forEach(queryId => {

0 commit comments

Comments
 (0)