From bc7a81845916bec382212b61fdcb6984e8e28844 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Tue, 3 Dec 2024 15:30:50 +0100 Subject: [PATCH] fix: `TypeError: Cannot read properties of undefined (reading 'data')` in `autoAnswerableFlag` (#4033) --- editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts index a0f502d524..8f2f901869 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/preview.ts @@ -505,8 +505,8 @@ export const previewStore: StateCreator< const node = flow[id]; if (!node) return; - const { type, data, edges } = node; // Only Question & Checklist nodes that have an fn & edges are eligible for auto-answering + const { type, data, edges } = node; if ( !type || !SUPPORTED_DECISION_TYPES.includes(type) || @@ -630,9 +630,12 @@ export const previewStore: StateCreator< */ autoAnswerableFlag: (filterId: NodeId) => { const { breadcrumbs, flow } = get(); - const { type, data, edges } = flow[filterId]; + + const node = flow[filterId]; + if (!node) return; // Only Filter nodes that have an fn & edges are eligible for auto-answering + const { type, data, edges } = node; if (!type || type !== TYPES.Filter || !data?.fn || !edges) return; // Get all options (aka flags or edges or Answer nodes) for this node