From a502083f0f9fce0e429e4f604d7cabce38bc0f01 Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Fri, 4 Aug 2023 20:25:49 +0200 Subject: [PATCH] feat: prevent 'beforeunload' event in editor --- src/app/editor/page.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/editor/page.tsx b/src/app/editor/page.tsx index b83e894..4a3ab07 100644 --- a/src/app/editor/page.tsx +++ b/src/app/editor/page.tsx @@ -1,11 +1,12 @@ 'use client' -import {ReactFlowProvider} from "reactflow"; -import React from "react"; +import {ReactFlowProvider, useReactFlow} from "reactflow"; +import React, {useEffect} from "react"; import HeaderBar, {CANVAS_HEIGHT} from "@/components/editor/headerbar/HeaderBar"; import useEditorPageState from "@/stores/editor/EditorPageStore"; import {Alert, Snackbar} from "@mui/material"; import Engine from "@/components/editor/Engine"; +import useReactFlowStore from "@/stores/editor/ReactFlowStore"; export default function Canvas() { @@ -21,6 +22,17 @@ export default function Canvas() { setIsSnackBarOpen(false) } + useEffect(() => { + window.addEventListener('beforeunload', preventReload) + return () => { + window.removeEventListener('beforeunload', preventReload) + } + }, []) + + const preventReload = (e: Event) => { + e.preventDefault() + } + return