-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): Move page component state & side effect handling to xstate #11897
Conversation
… major relay-compilier update
…while bootstrapping + initiate extracting queries from machine when new page component is created
@@ -55,21 +55,22 @@ function formatError(message: string, filePath: string, codeFrame: string) { | |||
} | |||
|
|||
function extractError(error: Error): { message: string, docName: string } { | |||
const docRegex = /Invariant Violation: (RelayParser|GraphQLParser): (.*). Source: document `(.*)` file:/g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex broke when we moved to Relay Compiler v2.
* Report that a query has been extracted from a component. Used by | ||
* query-compilier.js. | ||
* | ||
* @param {Object} $0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to use actions more for internal communication but don't want them all to show up here (https://www.gatsbyjs.org/docs/actions/)
Thinking we could start marking actions as private
to get around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for using actions more (and less event emitting). Can we move them to the actions
folder that already exists (but only has the page dependencies stuff), and export a subset that can be used in node APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, that's pretty much what we talked about yesterday. One idea is to have public-actions and private-actions files. Other could be, have extra export here:
gatsby/packages/gatsby/src/redux/actions.js
Lines 1186 to 1189 in 9e92a39
/** | |
* All action creators wrapped with a dispatch. - *DEPRECATED* | |
*/ | |
exports.boundActionCreators = bindActionCreators(actions, store.dispatch) |
const boundActionCreators = bindActionCreators(actions, store.dispatch)
exports.boundActionCreators = boundActionCreators
/**
* This will be used in `api-runner-node.js`
*/
exports.publicBoundActionCreators = _.pick(boundActionCreators, [
`createNode`,
`createPage`,
// and all other actions that should be public
])
But it's not in scope for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like just using pick :)
) | ||
|
||
const services = new Map() | ||
let programStatus = `BOOTSTRAPPING` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want to move to an enum.
…ies if the page query changes
@@ -157,3 +157,7 @@ emitter.on(`DELETE_PAGE`, action => { | |||
const node = getNode(nodeId) | |||
boundActionCreators.deleteNode({ node }) | |||
}) | |||
|
|||
emitter.on(`BOOTSTRAP_FINISHED`, () => | |||
boundActionCreators.setProgramStatus(`BOOTSTRAP_FINISHED`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that'd make more sense 👍
@@ -42,13 +42,14 @@ const runQueries = async () => { | |||
|
|||
// Find ids without data dependencies (i.e. no queries have been run for | |||
// them before) and run them. | |||
const cleanIds = findIdsWithoutDataDependencies() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably need to restore this? For now
…queries in a machine as well)
…e has been created and run its query
@KyleAMathews @pieh didn't have as much time today as I would've liked, but got through some of these. Definitely a few issues thus far that need fixing. I'll look into actually fixing these tomorrow afternoon. Here's what I found thus far: Issues4.iv) Deleting a page seems to hard fail
Misc. / Possibly Unrelated
|
Should be fixed in 36bda2e
This is bigger one - with approach change in here with emitting |
Gotta another plane ride so I can work on the static query stuff. |
…ant changes to static queries weren't being run
…l successfully extracts queries so we can know to leave babe error state
Made good progress on the train. Fixed the static query bug (by eliminating tracking extraction in the page component machine as you suggested @pieh). I filled out the test plan a bunch more and from my manual tests, everything is currently working 🎉
|
Checked and https://github.com/rexxars/gatsby-node-update-bugs are also fixed |
Niiiice. Let me know when you've got an alpha for this and I'll run my sites against it. Super stoked to see this! |
…spond the same way
same. Happy to run the mdx examples and such against it too. |
Sweet thanks! Release |
[removed] whatever is happening is not due to this alpha. Apparently something else broke in my setup. 😕 |
Looking forward to this one. I've been working on a follow up PR that eliminates some of the eventing and global state by making the query runner queue constructable. I'll create a PR once this is merged. https://github.com/gatsbyjs/gatsby/compare/xstate-components...Moocar:query-runner-refactor?expand=1 |
Tests passed — manually tested this on a number of sites + my manual checklist above. Merging and publishing. I'll create an issue for turning the checklist into automated tests. |
@KyleAMathews 🎉 awesome news! |
|
Internally within Gatsby, some of our most complex logic is around creating and managing page components — there's quite a few states a page component can be in e.g. while bootstrapping, extracting queries, running queries for its pages, etc.
The code for handling this has been some of the most annoying and bug prone code to work in.
XState has been on list of things to try in core for quite a while as it's perfect for these sorts of things. @m-allanson did a small PR adding it for ludicrious mode last year #4555 and it's been problem free there.
Visualization
TODOs
Follow up questions/work
Fix bug #2b in https://github.com/rexxars/gatsby-node-update-bugs the old page is now deleted due to fix: check for dirty pages when nodes are deleted (so queries are ru-run and data is removed from pages) #11831 — to fix running the query again, we need to model new pagespageContext
changing not triggering rebuilds