Skip to content

Commit ed2e574

Browse files
committed
fix(core): hide graph until initial fitview is done (#1459)
* fix(core): hide graph until initial fitview is done * chore(changeset): add * fix(core): wait for fit view to finish
1 parent 0c5dfdd commit ed2e574

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.changeset/cyan-vans-attend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Hide viewport until initial fit view is finished
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<script lang="ts" setup>
2+
import { computed } from 'vue'
23
import { useVueFlow } from '../../composables'
34
4-
const { viewport } = useVueFlow()
5+
const { viewport, fitViewOnInit, fitViewOnInitDone } = useVueFlow()
6+
7+
const isHidden = computed(() => {
8+
if (fitViewOnInit.value) {
9+
return !fitViewOnInitDone.value
10+
}
11+
12+
return false
13+
})
14+
15+
const transform = computed(() => `translate(${viewport.value.x}px,${viewport.value.y}px) scale(${viewport.value.zoom})`)
516
</script>
617

718
<script lang="ts">
@@ -12,10 +23,7 @@ export default {
1223
</script>
1324

1425
<template>
15-
<div
16-
class="vue-flow__transformationpane vue-flow__container"
17-
:style="{ transform: `translate(${viewport.x}px,${viewport.y}px) scale(${viewport.zoom})` }"
18-
>
26+
<div class="vue-flow__transformationpane vue-flow__container" :style="{ transform, opacity: isHidden ? 0 : undefined }">
1927
<slot />
2028
</div>
2129
</template>

packages/core/src/store/actions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ export function useActions(
173173
}
174174

175175
if (!state.fitViewOnInitDone && state.fitViewOnInit) {
176-
viewportHelper.value.fitView()
177-
state.fitViewOnInitDone = true
176+
viewportHelper.value.fitView().then(() => {
177+
state.fitViewOnInitDone = true
178+
})
178179
}
179180

180181
if (changes.length) {

0 commit comments

Comments
 (0)