From 27e2518ddefbae92b1911a400799a710c799563c Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Fri, 24 May 2024 16:01:16 -0400 Subject: [PATCH] Fire off "Cancel" modelingMachine event before unmount (#2520) Co-authored-by: Jess Frazelle --- src/components/ModelingMachineProvider.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index 57f5d7aa1..3edc251df 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -637,6 +637,12 @@ export const ModelingMachineProvider = ({ kclManager.registerExecuteCallback(() => { modelingSend({ type: 'Re-execute' }) }) + + // Before this component unmounts, call the 'Cancel' + // event to clean up any state in the modeling machine. + return () => { + modelingSend({ type: 'Cancel' }) + } }, [modelingSend]) // Give the state back to the editorManager. @@ -659,6 +665,10 @@ export const ModelingMachineProvider = ({ actor: modelingActor, commandBarConfig: modelingMachineConfig, allCommandsRequireNetwork: true, + // TODO for when sketch tools are in the toolbar: This was added when we used one "Cancel" event, + // but we need to support "SketchCancel" and basically + // make this function take the actor or state so it + // can call the correct event. onCancel: () => modelingSend({ type: 'Cancel' }), })