Skip to content

Commit a6ecfb2

Browse files
authored
fix(gatsby): purge jobsV2 results when cache is corrupt (#27700)
1 parent 878a8ab commit a6ecfb2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ import {
55
IGatsbyCompleteJobV2,
66
} from "../types"
77

8-
export const jobsV2Reducer = (
9-
state: IGatsbyState["jobsV2"] = {
8+
const initialState = (): IGatsbyState["jobsV2"] => {
9+
return {
1010
incomplete: new Map(),
1111
complete: new Map(),
12-
},
12+
}
13+
}
14+
15+
export const jobsV2Reducer = (
16+
state = initialState(),
1317
action: ActionsUnion
1418
): IGatsbyState["jobsV2"] => {
1519
switch (action.type) {
20+
case `DELETE_CACHE`:
21+
return action.cacheIsCorrupt ? initialState() : state
22+
1623
case `CREATE_JOB_V2`: {
1724
const { job, plugin } = action.payload
1825

packages/gatsby/src/redux/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ export interface ISetResolvedThemesAction {
574574

575575
export interface IDeleteCacheAction {
576576
type: `DELETE_CACHE`
577+
cacheIsCorrupt?: boolean
577578
}
578579

579580
export interface IRemovePageDataAction {

packages/gatsby/src/services/initialize.ts

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export async function initialize({
278278
// been loaded from the file system cache).
279279
store.dispatch({
280280
type: `DELETE_CACHE`,
281+
cacheIsCorrupt,
281282
})
282283

283284
// in future this should show which plugin's caches are purged

0 commit comments

Comments
 (0)