Skip to content

Commit d09f3aa

Browse files
committed
fix: rebuild flamegraph on tree nodes updated
1 parent e4bba79 commit d09f3aa

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/devtools/src/app/components/chart/ModuleFlamegraph.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { TreeNodeInput } from 'nanovis'
33
import type { ModuleInfo, SessionContext } from '~~/shared/types'
44
import { Flamegraph, normalizeTreeNode } from 'nanovis'
5-
import { computed, defineProps, onMounted, ref, useTemplateRef } from 'vue'
5+
import { computed, defineProps, onMounted, ref, shallowRef, useTemplateRef, watch } from 'vue'
66
77
const props = defineProps<{
88
info: ModuleInfo
@@ -59,9 +59,10 @@ const hoverNode = ref<{
5959
const hoverX = ref<number>(0)
6060
const hoverY = ref<number>(0)
6161
const el = useTemplateRef<HTMLDivElement>('el')
62+
const flamegraph = shallowRef<Flamegraph | null>(null)
6263
63-
onMounted(() => {
64-
const flamegraph = new Flamegraph(tree.value, {
64+
function buildFlamegraph() {
65+
flamegraph.value = new Flamegraph(tree.value, {
6566
animate: true,
6667
palette: {
6768
fg: '#888',
@@ -88,13 +89,26 @@ onMounted(() => {
8889
}
8990
},
9091
})
92+
el.value!.appendChild(flamegraph.value!.el)
93+
}
9194
92-
el.value!.appendChild(flamegraph.el)
95+
function disposeFlamegraph() {
96+
flamegraph.value?.dispose()
97+
}
9398
99+
onMounted(() => {
100+
buildFlamegraph()
94101
return () => {
95-
flamegraph.dispose()
102+
disposeFlamegraph()
96103
}
97104
})
105+
106+
watch(tree, async () => {
107+
disposeFlamegraph()
108+
buildFlamegraph()
109+
}, {
110+
deep: true,
111+
})
98112
</script>
99113

100114
<template>

0 commit comments

Comments
 (0)