Skip to content

Commit 9596f7e

Browse files
committed
fix(ui): plug rule diff editor leaks
1 parent 65a822a commit 9596f7e

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

ui-vue3/src/views/traffic/_shared/RuleDiffEditor.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
-->
1717

1818
<template>
19-
<div :id="editorId" class="rule-diff-editor" :style="{ height: editorHeight }"></div>
19+
<div ref="editorEl" class="rule-diff-editor" :style="{ height: editorHeight }"></div>
2020
</template>
2121

2222
<script lang="ts" setup>
23-
import { computed, onBeforeUnmount, onMounted, watch } from 'vue'
23+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
2424
import * as monaco from 'monaco-editor'
2525
2626
const props = defineProps({
@@ -32,36 +32,39 @@ const props = defineProps({
3232
type: String,
3333
default: ''
3434
},
35-
editorId: {
36-
type: String,
37-
default: 'rule-diff-editor'
38-
},
3935
height: {
4036
type: [String, Number],
4137
default: '420px'
4238
}
4339
})
4440
4541
let diffEditor: monaco.editor.IStandaloneDiffEditor | null = null
42+
const editorEl = ref<HTMLElement | null>(null)
4643
const editorHeight = computed(() =>
4744
typeof props.height === 'number' ? `${props.height}px` : props.height
4845
)
4946
47+
const disposeModels = () => {
48+
const model = diffEditor?.getModel()
49+
model?.original.dispose()
50+
model?.modified.dispose()
51+
}
52+
5053
const render = () => {
5154
if (!diffEditor) {
5255
return
5356
}
57+
disposeModels()
5458
const originalModel = monaco.editor.createModel(props.original || '', 'json')
5559
const modifiedModel = monaco.editor.createModel(props.modified || '', 'json')
5660
diffEditor.setModel({ original: originalModel, modified: modifiedModel })
5761
}
5862
5963
onMounted(() => {
60-
const el = document.getElementById(props.editorId)
61-
if (!el) {
64+
if (!editorEl.value) {
6265
return
6366
}
64-
diffEditor = monaco.editor.createDiffEditor(el, {
67+
diffEditor = monaco.editor.createDiffEditor(editorEl.value, {
6568
automaticLayout: true,
6669
renderSideBySide: true,
6770
readOnly: true,
@@ -76,6 +79,7 @@ watch(
7679
)
7780
7881
onBeforeUnmount(() => {
82+
disposeModels()
7983
diffEditor?.dispose()
8084
diffEditor = null
8185
})

ui-vue3/src/views/traffic/_shared/RuleHistoryDrawer.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ defineEmits(['update:open', 'view-json', 'diff-current', 'rollback'])
8989
9090
.history-item {
9191
padding: 4px 0 12px;
92-
93-
&.current {
94-
color: inherit;
95-
}
9692
}
9793
9894
.history-head,

ui-vue3/src/views/traffic/_shared/ruleVersion.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import {
2525
} from '@/api/service/traffic'
2626
import { HTTP_STATUS } from '@/base/http/constants'
2727

28-
export const currentVersionIdFromItems = (items: RuleVersion[]): number | undefined => {
29-
return items.find((item) => item.isCurrent)?.id || items[0]?.id
30-
}
31-
3228
export interface CurrentVersionState {
3329
id?: number
3430
versionNo?: number
@@ -42,13 +38,6 @@ export const currentVersionStateFromItems = (items: RuleVersion[]): CurrentVersi
4238
}
4339
}
4440

45-
export const fetchCurrentVersionId = async (
46-
kind: TrafficRuleKind,
47-
ruleName: string
48-
): Promise<number | undefined> => {
49-
return (await fetchCurrentVersionState(kind, ruleName)).id
50-
}
51-
5241
export const fetchCurrentVersionState = async (
5342
kind: TrafficRuleKind,
5443
ruleName: string

0 commit comments

Comments
 (0)