From 7c81d1a75988956b4211b58a320036a80be02068 Mon Sep 17 00:00:00 2001 From: Felix Henninger Date: Thu, 9 Apr 2020 09:24:02 +0200 Subject: [PATCH] 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. --- packages/builder/src/reducers/components.js | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/reducers/components.js b/packages/builder/src/reducers/components.js index 1ae6d92f3..46e766042 100644 --- a/packages/builder/src/reducers/components.js +++ b/packages/builder/src/reducers/components.js @@ -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':