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): account for edge case when payload of DELETE_NODE is undefined #27929

Merged
merged 1 commit into from
Nov 9, 2020
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
7 changes: 7 additions & 0 deletions packages/gatsby/src/redux/reducers/__tests__/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ describe(`create node`, () => {
})

describe(`delete node`, () => {
it(`accounts for undefined payload`, () => {
const runDeleteNode = (): void => {
reducer(state, { type: `DELETE_NODE`, payload: undefined })
}
expect(runDeleteNode).not.toThrow(`Cannot read property 'id' of undefined`)
})

it.todo(`marks page query as dirty when it has this node as a dependency`)
it.todo(`marks static query as dirty when it has this node as a dependency`)
it.todo(
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/src/redux/reducers/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export function queriesReducer(
case `CREATE_NODE`:
case `DELETE_NODE`: {
const node = action.payload
if (!node) {
return state
}
const queriesByNode = state.byNode.get(node.id) ?? []
const queriesByConnection =
state.byConnection.get(node.internal.type) ?? []
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@ export interface IAddChildNodeToParentNodeAction {

export interface IDeleteNodeAction {
type: `DELETE_NODE`
payload: IGatsbyNode
// FIXME: figure out why payload can be undefined here
payload: IGatsbyNode | void
}

export interface IDeleteNodesAction {
Expand Down