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

Conversation

vladar
Copy link
Contributor

@vladar vladar commented Aug 31, 2020

Description

A follow up for #25479 and #26138

This PR fixes a problem with query hanging when createNode is called and awaited within a custom resolver.

Before this PR createNode in a custom resolver was deferred until the machine reached the waiting state. But it couldn't reach this state because the custom resolver awaited for createNode to complete and so the query could never finish and leave the runningQueries state.

After this PR createNode calls (and other node mutation actions) are not deferred when the machine is in the runningQueries state.

Caveat: One downside of it is that now if some node is created outside of the query running loop (i.e. in some watcher or subscription) but DURING query running - it won't be deferred.

Related Issues

Fixes #26530

@vladar vladar requested a review from ascorbic August 31, 2020 10:52
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 31, 2020
@@ -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!

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 31, 2020

Gatsby Cloud Build Report

client-only-paths

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 17s

Performance

Lighthouse report

Metric Score
Performance 💚 100
Accessibility 🔶 85
Best Practices 💚 100
SEO 🔶 70

🔗 View full report

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 31, 2020

Gatsby Cloud Build Report

using-styled-components

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 19s

Performance

Lighthouse report

Metric Score
Performance 💚 100
Accessibility 💚 90
Best Practices 💚 100
SEO 💚 90

🔗 View full report

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 31, 2020

Gatsby Cloud Build Report

using-reach-skip-nav

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 22s

Performance

Lighthouse report

Metric Score
Performance 💚 100
Accessibility 💚 100
Best Practices 💚 100
SEO 🔶 82

🔗 View full report

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 31, 2020

Gatsby Cloud Build Report

gatsby

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 21m

@vladar vladar removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 31, 2020
@vladar
Copy link
Contributor Author

vladar commented Aug 31, 2020

Turns out we have specific tests for queues a node mutation during query running here. So this might be an invalid fix but then what would be the correct one?

Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

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

Unfortunately I think we're going to need to work out a different way of solving this. Could we have a call tomorrow?

@@ -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.

@@ -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

@vladar
Copy link
Contributor Author

vladar commented Aug 31, 2020

I am gonna close this PR. Looking forward for the follow-up.

@vladar vladar closed this Aug 31, 2020
@vladar vladar deleted the vladar/fix-node-mutations-in-query branch October 29, 2020 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gatsby develop: page query hanging
2 participants