Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/gatsby/src/redux/reducers/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ export function queriesReducer(
state.deletedQueries.add(action.payload.path)
return state
}
case `DELETED_STALE_PAGE_DATA_FILES`: {
// this action is a hack/hot fix
// it should be removed/reverted when we start persisting pages state
for (const queryId of action.payload.pagePathsToClear) {
for (const component of state.trackedComponents.values()) {
component.pages.delete(queryId)
}
state = clearNodeDependencies(state, queryId)
state = clearConnectionDependencies(state, queryId)
state.trackedQueries.delete(queryId)
}

return state
}
case `API_FINISHED`: {
if (action.payload.apiName !== `createPages`) {
return state
Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export type ActionsUnion =
| IDisableTypeInferenceAction
| ISetProgramAction
| ISetProgramExtensions
| IDeletedStalePageDataFiles

export interface IApiFinishedAction {
type: `API_FINISHED`
Expand Down Expand Up @@ -804,3 +805,10 @@ interface ISetProgramExtensions {
type: `SET_PROGRAM_EXTENSIONS`
payload: Array<string>
}

interface IDeletedStalePageDataFiles {
type: `DELETED_STALE_PAGE_DATA_FILES`
payload: {
pagePathsToClear: Set<string>
}
}
12 changes: 11 additions & 1 deletion packages/gatsby/src/utils/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,20 @@ export async function handleStalePageData(): Promise<void> {
})

const deletionPromises: Array<Promise<void>> = []
pageDataFilesFromPreviousBuilds.forEach(pageDataFilePath => {
const pagePathsToClear = new Set<string>()
for (const pageDataFilePath of pageDataFilesFromPreviousBuilds) {
if (!expectedPageDataFiles.has(pageDataFilePath)) {
const stalePageDataContent = await fs.readJson(pageDataFilePath)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this adds fs operation - but just for page-data files that are marked as stale and scheduled for deletion. This is to grab page.path.

Alternatively we could try to derive page.path from location of page-data file, but this is not deterministic due to all the variations of leading and trailing slashes ... and it also would be more convoluted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice trick to get this path! 😄

pagePathsToClear.add(stalePageDataContent.path)
deletionPromises.push(fs.remove(pageDataFilePath))
}
}

store.dispatch({
type: `DELETED_STALE_PAGE_DATA_FILES`,
payload: {
pagePathsToClear,
},
})

await Promise.all(deletionPromises)
Expand Down