diff --git a/apps/workflows-dashboard/package.json b/apps/workflows-dashboard/package.json index dd1a34b3d9..5f4ca4ff1a 100644 --- a/apps/workflows-dashboard/package.json +++ b/apps/workflows-dashboard/package.json @@ -45,6 +45,7 @@ "react": "^18.2.0", "react-custom-scrollbars": "^4.2.1", "react-dom": "^18.2.0", + "react-error-boundary": "^4.0.13", "react-hook-form": "^7.43.9", "react-json-view": "^1.21.3", "react-router-dom": "^6.11.2", diff --git a/apps/workflows-dashboard/src/components/organisms/XstateVisualizer/XstateVisualizer.tsx b/apps/workflows-dashboard/src/components/organisms/XstateVisualizer/XstateVisualizer.tsx index 47365ad0ee..1552f2b843 100644 --- a/apps/workflows-dashboard/src/components/organisms/XstateVisualizer/XstateVisualizer.tsx +++ b/apps/workflows-dashboard/src/components/organisms/XstateVisualizer/XstateVisualizer.tsx @@ -2,6 +2,7 @@ import { deserializeStateDefinition } from '@/components/organisms/XstateVisuali import { inspect } from '@xstate/inspect'; import { useInterpret, useMachine } from '@xstate/react'; import { memo, useLayoutEffect, useMemo, useRef } from 'react'; +import { withErrorBoundary } from 'react-error-boundary'; import { createMachine } from 'xstate'; interface Props { @@ -9,38 +10,45 @@ interface Props { state?: string; } -export const XstateVisualizer = memo(({ stateDefinition, state }: Props) => { - const _machine = useMemo( - () => - createMachine( - deserializeStateDefinition({ - ...stateDefinition, - initial: state || stateDefinition.initial, - }), - ), - [stateDefinition, state], - ); - const [stateMachine] = useMachine(_machine); +export const XstateVisualizer = memo( + withErrorBoundary( + ({ stateDefinition, state }: Props) => { + const _machine = useMemo( + () => + createMachine( + deserializeStateDefinition({ + ...stateDefinition, + initial: state || stateDefinition.initial, + }), + ), + [stateDefinition, state], + ); + const [stateMachine] = useMachine(_machine); - useInterpret(_machine, { devTools: true }); + useInterpret(_machine, { devTools: true }); - const iframeRef = useRef(null); + const iframeRef = useRef(null); - useLayoutEffect(() => { - if (!iframeRef.current) return; + useLayoutEffect(() => { + if (!iframeRef.current) return; - inspect({ iframe: iframeRef.current }); - }, [iframeRef, state, stateMachine.value]); + inspect({ iframe: iframeRef.current }); + }, [iframeRef, state, stateMachine.value]); - return ( -
-