Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to skip cache persistence #29047

Merged
merged 1 commit into from
Jan 18, 2021
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
19 changes: 19 additions & 0 deletions packages/gatsby/src/redux/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,23 @@ describe(`redux db`, () => {

expect(mockWrittenContent.has(legacyLocation)).toBe(false)
})

describe(`GATSBY_DISABLE_CACHE_PERSISTENCE`, () => {
beforeAll(() => {
process.env.GATSBY_DISABLE_CACHE_PERSISTENCE = `truthy`
})

afterAll(() => {
delete process.env.GATSBY_DISABLE_CACHE_PERSISTENCE
})
it(`shouldn't write redux cache to disk when GATSBY_DISABLE_CACHE_PERSISTENCE env var is used`, async () => {
expect(initialComponentsState).toEqual(new Map())

store.getState().nodes = getFakeNodes()

await saveState()

expect(writeToCache).not.toBeCalled()
})
})
})
7 changes: 7 additions & 0 deletions packages/gatsby/src/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export const store: GatsbyReduxStore = configureStore(readState())

// Persist state.
export const saveState = (): void => {
if (process.env.GATSBY_DISABLE_CACHE_PERSISTENCE) {
// do not persist cache if above env var is set.
// this is to temporarily unblock builds that hit the v8.serialize related
// Node.js buffer size exceeding kMaxLength fatal crashes
return undefined
}

const state = store.getState()

return writeToCache({
Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export async function initialize({
store: Store<IGatsbyState, AnyAction>
workerPool: JestWorker
}> {
if (process.env.GATSBY_DISABLE_CACHE_PERSISTENCE) {
reporter.info(
`GATSBY_DISABLE_CACHE_PERSISTENCE is enabled. Cache won't be persisted. Next builds will not be able to reuse any work done by current session.`
)
telemetry.trackFeatureIsUsed(`DisableCachePersistence`)
}
if (!args) {
reporter.panic(`Missing program args`)
}
Expand Down