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

Remove component query from store when a user deletes it fixes #4032 #4041

Merged
merged 1 commit into from
Feb 15, 2018
Merged
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
24 changes: 20 additions & 4 deletions packages/gatsby/src/internal-plugins/query-runner/query-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,28 @@ const watch = rootDir => {
const debounceCompile = _.debounce(() => {
queryCompiler().then(queries => {
const components = store.getState().components

// If a component previously with a query now doesn't — update the
// store.
const noQueryComponents = Object.values(components).filter(
c => c.query !== `` && !queries.has(c.componentPath)
)
noQueryComponents.forEach(({ componentPath }) => {
boundActionCreators.replaceComponentQuery({
query: ``,
componentPath,
})
runQueriesForComponent(componentPath)
})

// Update the store with the new queries and re-run queries that were
// changed.
queries.forEach(({ text }, id) => {
// Queries can be parsed from non page/layout components e.g. components
// with fragments so ignore those.
// Queries can be parsed from non page/layout components
// e.g. components with fragments so ignore those.
//
// If the query has changed, set the new query in the store and run
// its queries.
// If the query has changed, set the new query in the
// store and run its queries.
if (components[id] && text !== components[id].query) {
boundActionCreators.replaceComponentQuery({
query: text,
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/redux/reducers/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (state = {}, action) => {
state[action.payload.componentPath],
{
componentPath: action.payload.componentPath,
query: ``,
}
)
return state
Expand Down