Skip to content

Commit

Permalink
fix(gatsby): do not ignore source file changes during recompilation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vladar authored Nov 23, 2020
1 parent 45116d1 commit 4148877
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
13 changes: 11 additions & 2 deletions packages/gatsby/src/state-machines/develop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
},
// Recompile the JS bundle
recompiling: {
// Important: mark source files as clean when recompiling starts
// Doing this `onDone` will wipe all file change events that occur **during** recompilation
// See https://github.com/gatsbyjs/gatsby/issues/27609
entry: `markSourceFilesClean`,
invoke: {
src: `recompile`,
onDone: {
actions: `markSourceFilesClean`,
target: `waiting`,
},
onError: {
Expand Down Expand Up @@ -247,8 +250,14 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
data: ({
store,
nodeMutationBatch = [],
sourceFilesDirty,
}: IBuildContext): IWaitingContext => {
return { store, nodeMutationBatch, runningBatch: [] }
return {
store,
nodeMutationBatch,
sourceFilesDirty,
runningBatch: [],
}
},
// "done" means we need to rebuild
onDone: {
Expand Down
21 changes: 15 additions & 6 deletions packages/gatsby/src/state-machines/waiting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ export const waitingStates: MachineConfig<IWaitingContext, any, any> = {
},
states: {
idle: {
always: {
// If we already have queued node mutations, move
// immediately to batching
cond: (ctx): boolean => !!ctx.nodeMutationBatch.length,
target: `batchingNodeMutations`,
},
always: [
{
// If we already have queued node mutations, move
// immediately to batching
cond: (ctx): boolean => !!ctx.nodeMutationBatch.length,
target: `batchingNodeMutations`,
},
{
// If source files are dirty upon entering this state,
// move immediately to aggregatingFileChanges to force re-compilation
// See https://github.com/gatsbyjs/gatsby/issues/27609
target: `aggregatingFileChanges`,
cond: ({ sourceFilesDirty }): boolean => Boolean(sourceFilesDirty),
},
],
on: {
ADD_NODE_MUTATION: {
actions: `addNodeMutation`,
Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby/src/state-machines/waiting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export interface IWaitingContext {
nodeMutationBatch: Array<IMutationAction>
store?: Store<IGatsbyState, AnyAction>
runningBatch: Array<IMutationAction>
filesDirty?: boolean
webhookBody?: Record<string, unknown>
sourceFilesDirty?: boolean
}

0 comments on commit 4148877

Please sign in to comment.