-
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
Merged
Merged
Changes from 35 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
d61316e
Inital work to move component query handling to xstate + fix bug with…
KyleAMathews 5db0b2c
Expand model to include we don't want to immediately extract queries …
KyleAMathews 2abcb2c
Rearrange states so more in order of possible events
KyleAMathews 799391f
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews bbbd20b
Document two program statuses
KyleAMathews 5f53d33
Move responsibility for running queries for pages to the page compone…
KyleAMathews d8fb163
Handle page components changing
KyleAMathews 97226e6
Let state machine know when a query has been run and only re-run quer…
KyleAMathews 9347c2f
Handle babel error state when extracing queries
KyleAMathews d242435
Make name more explicit
KyleAMathews a124367
Ignore static query results
KyleAMathews aaf8bf3
Clarify comment
KyleAMathews 53eea1c
empty strings are falsy 🤦♂️
KyleAMathews 0e4d4df
Handled in last commit
KyleAMathews df226de
Only handle clean ids for static queries (for now until model static …
KyleAMathews 6f60428
In hacky/temp way (until modeling pages directly), check if a new pag…
KyleAMathews 8631558
Mark new actions as private
KyleAMathews e5525b4
Move action to bootstrap per @stefanprobst's suggestion
KyleAMathews 647b2dd
Extract page component machine into new 'machines' directory
KyleAMathews c3bb339
Fix check that there's a query in a non-page component
KyleAMathews 3e0ddcf
Add xstate as a dependency
KyleAMathews 9343d8e
Update snapshots
KyleAMathews 0e4c346
Add initial tests for page component machine
KyleAMathews fd4edaa
Listen for query queue to empty to know queries are done
KyleAMathews 50e9b0f
Comment out machine logging
KyleAMathews 0066cad
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews 10298a4
Restore usage of getCodeFromRelayError
KyleAMathews b98ea2a
Don't need to re-set service on Map
KyleAMathews 836ef5e
Small fixes
KyleAMathews 3b2006f
Update packages/gatsby/src/redux/reducers/components.js
wardpeet 4f994f6
Don't run queries until hit query running stage in bootstrap
KyleAMathews 2fb8794
Switch page components out of bootstrap state right after bootstrap q…
KyleAMathews 1d3074f
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews cb23533
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews beebbea
During bootstrap, only run page queries that are 'clean' (i.e. we hav…
KyleAMathews 17d34d9
Handle deleting pages in machine so it knows to re-run its query if r…
KyleAMathews 37baf68
Move simple set context actions to top-level so don't have to repeat …
KyleAMathews 5100484
Simplify logic for running queries for new pages
KyleAMathews a8c32e1
run queries for pages created after bootstrap
pieh 9daeae2
Capture more types of graphql extraction errors
KyleAMathews c299ae6
Merge remote-tracking branch 'upstream/master' into xstate-components
DSchau 36bda2e
DELETE_PAGE action use `component` not `componentPath`
pieh 1adc63d
Page components shouldn't control extraction — moving that to them me…
KyleAMathews 7932e8e
Now that we're not tracking query extracting, add event for when babe…
KyleAMathews f4bb7c2
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews 20fcf49
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews 03f4b37
Move graphql/babel event handling to top-level as we should always re…
KyleAMathews 8dfe393
Move action call to after findGraphQLTags as we cache babel extraction
KyleAMathews cedc761
trivial change
KyleAMathews b3fd97b
Merge remote-tracking branch 'origin/master' into xstate-components
KyleAMathews 83eedb2
yarn.lock change
KyleAMathews 76475f5
Trivial change so can publish
KyleAMathews 67ef857
Update from master
KyleAMathews File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,17 @@ exports.queueQueryForPathname = pathname => { | |
// Afterwards we listen "API_RUNNING_QUEUE_EMPTY" and check | ||
// for dirty nodes before running queries. | ||
exports.runInitialQueries = async () => { | ||
await runQueries() | ||
|
||
active = true | ||
await runQueries(true) | ||
return | ||
} | ||
|
||
const runQueries = async () => { | ||
const runQueries = async (initial = false) => { | ||
// Don't run queries until bootstrap gets to "run graphql queries" | ||
if (!active) { | ||
return | ||
} | ||
|
||
// Find paths dependent on dirty nodes | ||
queuedDirtyActions = _.uniq(queuedDirtyActions, a => a.payload.id) | ||
const dirtyIds = findDirtyIds(queuedDirtyActions) | ||
|
@@ -45,11 +49,25 @@ const runQueries = async () => { | |
const cleanIds = findIdsWithoutDataDependencies() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably need to restore this? For now |
||
|
||
// Construct paths for all queries to run | ||
const pathnamesToRun = _.uniq([ | ||
...runQueriesForPathnamesQueue, | ||
...dirtyIds, | ||
...cleanIds, | ||
]) | ||
let pathnamesToRun = _.uniq([...dirtyIds, ...cleanIds]) | ||
|
||
// If this is the initial run, remove pathnames from `runQueriesForPathnamesQueue` | ||
// if they're also not in the dirtyIds or cleanIds. | ||
// | ||
// We do this because the page component reducer/machine always | ||
// adds pages to runQueriesForPathnamesQueue but during bootstrap | ||
// we may not want to run those page queries if their data hasn't | ||
// changed since the last time we ran Gatsby. | ||
KyleAMathews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let diffedPathnames = [...runQueriesForPathnamesQueue] | ||
if (initial) { | ||
diffedPathnames = _.intersection( | ||
[...runQueriesForPathnamesQueue], | ||
pathnamesToRun | ||
) | ||
} | ||
|
||
// Combine. | ||
pathnamesToRun = _.union(diffedPathnames, pathnamesToRun) | ||
|
||
runQueriesForPathnamesQueue.clear() | ||
|
||
|
@@ -58,6 +76,8 @@ const runQueries = async () => { | |
return | ||
} | ||
|
||
exports.runQueries = runQueries | ||
|
||
emitter.on(`CREATE_NODE`, action => { | ||
queuedDirtyActions.push(action) | ||
}) | ||
|
@@ -66,12 +86,6 @@ emitter.on(`DELETE_NODE`, action => { | |
queuedDirtyActions.push({ payload: action.payload }) | ||
}) | ||
|
||
emitter.on(`CREATE_PAGE`, action => { | ||
if (action.contextModified) { | ||
exports.queueQueryForPathname(action.payload.path) | ||
} | ||
}) | ||
|
||
const runQueuedActions = async () => { | ||
if (active && !running) { | ||
try { | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.