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

fix(gatsby): fix ceateNode hanging in custom resolvers #26716

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions packages/gatsby/src/state-machines/develop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
SOURCE_FILE_CHANGED: {
actions: [forwardTo(`run-queries`), `markSourceFilesDirty`],
},
ADD_NODE_MUTATION: {
actions: [forwardTo(`run-queries`)],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than forwarding it to the child machine, it should run the action in the current machine. See the initializingData state for an example.

Copy link
Contributor

Choose a reason for hiding this comment

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

The trouble here is that this is not supposed to run them immediately: the reason we do this deferral is so that nodes aren't mutated during query runs. Changing this would mean that we'd be back to how it was without any deferral. Now that might be what we want to do after all, but at that point it would be better to remove the whole deferral system.

I think we need a different way of solving this though, which is probably a more granular way of dealing with deferred resolver mutations, i.e. not waiting until waiting, but bailing and drainign earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's what I thought. This was just a quick and direct attempt to address this problem but I see that it defeats the whole purpose of node deferring. We can definitely have a call/chat tomorrow as I'd like to get more context (haha) on our state charts in general. CC @wardpeet

},
invoke: {
id: `run-queries`,
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/src/state-machines/query-running/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IQueryRunningContext } from "./types"
import { DoneInvokeEvent, assign, ActionFunctionMap } from "xstate"
import { enqueueFlush } from "../../utils/page-data"
import { callApi, markNodesDirty } from "../develop/actions"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Importing from develop actions doesn't feel like the correct thing to do. So I am open to suggestions here!


export const flushPageData = (): void => {
enqueueFlush()
Expand All @@ -20,6 +21,8 @@ export const queryActions: ActionFunctionMap<
IQueryRunningContext,
DoneInvokeEvent<any>
> = {
callApi,
markNodesDirty,
assignDirtyQueries,
flushPageData,
}
3 changes: 3 additions & 0 deletions packages/gatsby/src/state-machines/query-running/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const queryStates: MachineConfig<IQueryRunningContext, any, any> = {
SOURCE_FILE_CHANGED: {
target: `extractingQueries`,
},
ADD_NODE_MUTATION: {
actions: [`markNodesDirty`, `callApi`],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunely this won't do what you expect. As this is a child machine, the action is run against the context of the child machine, so marking nodes as dirty won't do anything.

},
context: {},
states: {
Expand Down