Skip to content

Commit 0bfb5f4

Browse files
committed
docs: add troubleshooting page
1 parent 83848f4 commit 0bfb5f4

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

docs/src/.vitepress/config.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export default defineConfigWithTheme<DefaultTheme.Config>({
191191
{ text: 'Node Resizer', link: '/guide/components/node-resizer' },
192192
],
193193
},
194+
{
195+
text: 'Troubleshooting',
196+
link: '/guide/troubleshooting',
197+
}
194198
],
195199
'/examples/': [
196200
{

docs/src/guide/troubleshooting.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: Troubleshooting
3+
---
4+
5+
# Troubleshooting
6+
7+
This section aims to help you understand, avoid, and fix errors that may occur when using Vue Flow.
8+
9+
## Errors and Fixes
10+
11+
Vue Flow can emit several error types to help diagnose and resolve issues.
12+
13+
### MISSING_VIEWPORT_DIMENSIONS
14+
- **Description:** The Vue Flow parent container needs a width and a height to render the graph.
15+
- **Fix:** Ensure the parent container of Vue Flow has defined width and height.
16+
17+
```vue
18+
<template>
19+
<!-- Ensure the parent container has a width and height -->
20+
<div style="width: 500px; height: 500px">
21+
<VueFlow v-model="elements" />
22+
</div>
23+
</template>
24+
```
25+
26+
### NODE_INVALID
27+
- **Description:** A node is considered invalid, potentially due to incorrect configuration.
28+
- **Fix:** Check the node configuration for correctness, ensuring all required properties are set.
29+
30+
```ts
31+
// Here's an example of some valid node configurations
32+
const nodes = ref([
33+
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
34+
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 } },
35+
{ id: '3', type: 'output', label: 'Node 3', position: { x: 400, y: 200 } },
36+
{ id: '4', type: 'special', label: 'Node 4', position: { x: 400, y: 200 } },
37+
])
38+
```
39+
40+
### NODE_NOT_FOUND
41+
- **Description:** A corresponding node could not be found when calling `useNode`.
42+
- **Fix:** Verify the node exists when you call `useNode` outside of a custom node component.
43+
44+
### NODE_MISSING_PARENT
45+
- **Description:** A node is missing a defined parent node, necessary for nested nodes.
46+
- **Fix:** Ensure the parent node exists before adding a child node for it.
47+
48+
```ts
49+
// Here's an example of a valid nested node configuration
50+
const nodes = ref([
51+
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
52+
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 }, parentNode: '1' },
53+
{ id: '3', type: 'output', label: 'Node 3', position: { x: 400, y: 200 }, parentNode: '1' },
54+
])
55+
```
56+
57+
### NODE_TYPE_MISSING
58+
- **Description:** A node's type has no corresponding component defined.
59+
- **Fix:** Define a component for every node-type you use to ensure correct rendering of your custom nodes.
60+
61+
### NODE_EXTENT_INVALID
62+
- **Description:** Only child nodes can use a parent extent, indicating an invalid configuration.
63+
- **Fix:** Ensure only child nodes use a parent extent, and that the parent node exists.
64+
65+
### EDGE_INVALID
66+
- **Description:** An edge is missing a source or target.
67+
- **Fix:** Ensure all edges have both `source` and `target` properties correctly set.
68+
69+
```ts
70+
// Here's an example of some valid edge configurations
71+
const edges = ref([
72+
{ id: 'e1-3', source: '1', target: '3' },
73+
{ id: 'e1-2', source: '1', target: '2' },
74+
{ id: 'e1-4', source: '1', target: '4' },
75+
])
76+
```
77+
78+
### EDGE_NOT_FOUND
79+
- **Description:** A corresponding edge could not be found when calling `useEdge`.
80+
- **Fix:** Verify the edge exists when you call `useEdge` outside of a custom edge component.
81+
82+
### EDGE_SOURCE_MISSING / EDGE_TARGET_MISSING
83+
- **Description:** An edge's source or target node is missing.
84+
- **Fix:** Ensure both the source and target nodes exist and are correctly set for each edge.
85+
86+
### EDGE_TYPE_MISSING
87+
- **Description:** An edge's type has no corresponding component defined.
88+
- **Fix:** Define a component for every edge-type you use to ensure correct rendering of your custom edges.
89+
90+
### EDGE_SOURCE_TARGET_SAME
91+
- **Description:** An edge's source and target are the same node.
92+
- **Fix:** If this is intentional, you can ignore this error. Otherwise, ensure the source and target nodes are different.
93+
94+
### EDGE_SOURCE_TARGET_MISSING
95+
- **Description:** Both, the source *and* target nodes are missing from an edge.
96+
- **Fix:** Ensure both the source and target nodes exist and are correctly set for each edge.
97+
98+
### EDGE_ORPHANED
99+
- **Description:** An edge has lost its source or target node, likely due to node deletion.
100+
- **Fix:** If you intentionally orphaned the edge, you can ignore this error. Otherwise, ensure the source and target nodes exist or that you clean up edges before they are orphaned.
101+
102+
## Evaluating Errors During Runtime
103+
104+
During development, Vue Flow emits warnings to the console for errors encountered. These warnings are intended to help developers identify and resolve issues without failing silently. In production, however, these warnings are suppressed to avoid exposing potentially sensitive information to end users.
105+
106+
### Hooking into onError or @error Events
107+
108+
You can handle errors programmatically by hooking into the `onError` or `@error` events. This allows you to perform custom operations based on the type of error encountered. Here's an example of how to use `isErrorOfType` to handle a specific error type:
109+
110+
```ts
111+
import { isErrorOfType, ErrorCode } from '@vue-flow/core'
112+
113+
onError((error) => {
114+
if (isErrorOfType(error, ErrorCode.NODE_INVALID)) {
115+
const [nodeId] = error.args
116+
// Handle the NODE_INVALID error, e.g., by notifying the user or logging details.
117+
}
118+
})
119+
```
120+
121+
```vue
122+
<template>
123+
<VueFlow v-model="elements" @error="handleError" />
124+
</template>
125+
```
126+
127+

0 commit comments

Comments
 (0)