Skip to content

Commit

Permalink
feat(gatsby): allow to skip cache persistence (#29047)
Browse files Browse the repository at this point in the history
This is meant as a workaround for `Assertion 'length <= kMaxLength' failed` fatal crashes
  • Loading branch information
pieh committed Jan 18, 2021
1 parent 48db6ac commit bd5b5f7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/gatsby/src/redux/__tests__/index.js
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
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
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

0 comments on commit bd5b5f7

Please sign in to comment.