Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add before unload handler (#14663)

boojack3a096779f7b5
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index 85765b4427..3ab490c9b5 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -722,5 +722,8 @@ defineExpose({
get editor() {
return monacoEditorRef.value;
},
+ get isEditing() {
+ return state.isEditing;
+ },
});
</script>
diff --git a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
index 60483a49f2..3104a60a30 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/StatementSection.vue
@@ -10,9 +10,7 @@
</template>
<script setup lang="ts">
-import { computed } from "vue";
-import { ref } from "vue";
-import { nextTick } from "vue";
+import { computed, nextTick, ref, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import { TaskTypeListWithStatement } from "@/types";
import { Task_Type } from "@/types/proto/v1/rollout_service";
@@ -66,4 +64,24 @@ const scrollToLineByHash = (hash: string) => {
);
});
};
+
+const beforeUnloadHandler = (e: BeforeUnloadEvent) => {
+ // For created issues and not editing, no need to prompt.
+ if (!isCreating.value && !editorViewRef.value?.isEditing) {
+ return;
+ }
+
+ // For creating issues or editing task statement, prompt to confirm leaving.
+ e.preventDefault();
+ // Included for legacy support, e.g. Chrome/Edge < 119
+ e.returnValue = true;
+};
+
+onMounted(() => {
+ window.addEventListener("beforeunload", beforeUnloadHandler);
+});
+
+onUnmounted(() => {
+ window.removeEventListener("beforeunload", beforeUnloadHandler);
+});
</script>