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

Commit 7c81d1a

Browse files
Skip updates to missing components
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.
1 parent af3200c commit 7c81d1a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

packages/builder/src/reducers/components.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,24 @@ export default (state=defaultState, action) => {
206206
}
207207

208208
case 'UPDATE_COMPONENT':
209-
return {
210-
...state,
211-
[action.id]: {
212-
...state[action.id],
213-
...action.data,
214-
},
209+
if (state[action.id]) {
210+
return {
211+
...state,
212+
[action.id]: {
213+
...state[action.id],
214+
...action.data,
215+
},
216+
}
217+
} else {
218+
console.log(`Skipping update to missing component ${ action.id }`)
219+
// TODO: This fallback is designed to catch a very specific bug
220+
// that occured when flushing pending updates to a deleted component.
221+
// In principle, the same issue is present with all other reducers,
222+
// although it is extremely unlikely to occur.
223+
// In the long run, it may be worthwhile moving this check into
224+
// component logic, or, alternatively, making it universal to
225+
// all actions (e.g. by checking at the top of this reducer).
226+
return state
215227
}
216228

217229
case 'ADD_FILES':

0 commit comments

Comments
 (0)