Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Skip updates to missing components
Browse files Browse the repository at this point in the history
This fixes an issue that arose in deea1f, where we started flushing pending updates to the canvas editor when unmounting it. Deleting a component removes it from the application state and also unmounts the canvas editor, causing an update to a non-existent component and resulting in an invalid application state. We discussed several different places in which to check for the existence of the data, and this choice is debatable, but it's the simplest; the commit also adds a note to indicate that this might require revisiting.
  • Loading branch information
FelixHenninger committed Apr 9, 2020
1 parent af3200c commit 7c81d1a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/builder/src/reducers/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,24 @@ export default (state=defaultState, action) => {
}

case 'UPDATE_COMPONENT':
return {
...state,
[action.id]: {
...state[action.id],
...action.data,
},
if (state[action.id]) {
return {
...state,
[action.id]: {
...state[action.id],
...action.data,
},
}
} else {
console.log(`Skipping update to missing component ${ action.id }`)
// TODO: This fallback is designed to catch a very specific bug
// that occured when flushing pending updates to a deleted component.
// In principle, the same issue is present with all other reducers,
// although it is extremely unlikely to occur.
// In the long run, it may be worthwhile moving this check into
// component logic, or, alternatively, making it universal to
// all actions (e.g. by checking at the top of this reducer).
return state
}

case 'ADD_FILES':
Expand Down

0 comments on commit 7c81d1a

Please sign in to comment.