-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby): Move page component state & side effect handling to xst…
…ate (#11897) * Inital work to move component query handling to xstate + fix bug with major relay-compilier update * Expand model to include we don't want to immediately extract queries while bootstrapping + initiate extracting queries from machine when new page component is created * Rearrange states so more in order of possible events * Document two program statuses * Move responsibility for running queries for pages to the page component machine * Handle page components changing * Let state machine know when a query has been run and only re-run queries if the page query changes * Handle babel error state when extracing queries * Make name more explicit * Ignore static query results * Clarify comment * empty strings are falsy 🤦♂️ * Handled in last commit * Only handle clean ids for static queries (for now until model static queries in a machine as well) * In hacky/temp way (until modeling pages directly), check if a new page has been created and run its query * Mark new actions as private * Move action to bootstrap per @stefanprobst's suggestion * Extract page component machine into new 'machines' directory * Fix check that there's a query in a non-page component * Add xstate as a dependency * Update snapshots * Add initial tests for page component machine * Listen for query queue to empty to know queries are done * Comment out machine logging * Restore usage of getCodeFromRelayError * Don't need to re-set service on Map * Small fixes * Update packages/gatsby/src/redux/reducers/components.js Co-Authored-By: KyleAMathews <mathews.kyle@gmail.com> * Don't run queries until hit query running stage in bootstrap * Switch page components out of bootstrap state right after bootstrap query running is finished so if a stateful page changes, new queries are still run * During bootstrap, only run page queries that are 'clean' (i.e. we haven't seen them before) or 'dirty' (i.e. their tracked nodes changed since the last run) * Handle deleting pages in machine so it knows to re-run its query if re-added * Move simple set context actions to top-level so don't have to repeat across each state (thanks @pieh!) * Simplify logic for running queries for new pages We only want to run page queries in two circumstances: - the query has changed - the data has changed This is true whether in bootstrap or not. This commit simplifies the reducer / machine logic to not distinguish between whether in bootstrap or not. Also fixes the bug @pieh found where we we're re-running queries in bootstrap if the query had changed. * run queries for pages created after bootstrap * Capture more types of graphql extraction errors * DELETE_PAGE action use `component` not `componentPath` * Page components shouldn't control extraction — moving that to them meant changes to static queries weren't being run * Now that we're not tracking query extracting, add event for when babel successfully extracts queries so we can know to leave babe error state * Move graphql/babel event handling to top-level as we should always respond the same way * Move action call to after findGraphQLTags as we cache babel extraction * trivial change * yarn.lock change * Trivial change so can publish * Update from master
- Loading branch information
1 parent
090be3e
commit 91086d4
Showing
17 changed files
with
626 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
packages/gatsby/src/internal-plugins/query-runner/gatsby-node.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.