# Troubleshooting

> Fix a small or unstyled diagram canvas, nodes piled at the origin, missing edges and ports, lost undo history in frameworks, export differences, watermarks and slow large graphs.

The diagram never throws on bad data. It skips or repairs what it cannot use and logs a warning with the prefix `[Birch UI Diagram]`, so check the console first.

| Symptom | Jump to |
| --- | --- |
| The canvas is a 240 pixel strip | [The canvas is too small](#the-canvas-is-too-small) |
| Nodes and edges are unstyled | [The diagram has no styles](#the-diagram-has-no-styles) |
| Every node sits on top of the others | [All nodes are at the same position](#all-nodes-are-at-the-same-position) |
| `ignoring edge … because it refers to a missing node` | [An edge or node is missing](#an-edge-or-node-is-missing) |
| `unknown node type "…"` | [A node renders with the wrong shape](#a-node-renders-with-the-wrong-shape) |
| `… has an invalid or duplicate port…` | [A port is missing](#a-port-is-missing) |
| A connection is refused | [A connection is refused](#a-connection-is-refused) |
| Undo history clears in React, Vue or Svelte | [Undo history clears after every edit](#undo-history-clears-after-every-edit) |
| PNG export looks different from the screen | [Exports do not match the screen](#exports-do-not-match-the-screen) |
| "Birch UI Diagram · unlicensed copy" in the corner | [A watermark appears](#a-watermark-appears) |
| `Refused to apply inline style` in the console | [A Content Security Policy blocks the styles](#a-content-security-policy-blocks-the-styles) |
| Two copies of a package, or a large bundle | [Duplicate packages and bundle size](#duplicate-packages-and-bundle-size) |
| Large graphs are slow | [Large graphs are slow](#large-graphs-are-slow) |

## The canvas is too small

**Cause.** Without `width` and `height`, the diagram root fills its container (`height: 100%`) with a minimum height of 240 pixels. A container without a height gives that minimum.

**Fix.** Give the container a height, or pass fixed `width` and `height` in pixels:

```ts
createDiagram(document.querySelector<HTMLElement>('#purchase-approval')!, {
  ariaLabel: 'Purchase approval workflow',
  height: 560,
  nodes,
  edges,
});
```

`width` and `height` accept numbers only; use CSS on the container for lengths such as `calc(100vh - 120px)`. A diagram in a hidden tab re-measures through `ResizeObserver` when it becomes visible; call `zoomToFit()` then if the initial fit happened at zero size.

## The diagram has no styles

**Cause.** With `injectStyles: false`, the diagram does not add its stylesheet.

**Fix.** Import `@birchui/diagram/styles.css`, or insert the exported `diagramStyles` string into a shadow root yourself. See [Importing the CSS file](https://docs.birchui.com/getting-started/installation.md#importing-the-css-file).

## A Content Security Policy blocks the styles

**Cause.** Injected styles are a `<style>` element, which a `style-src` policy without `'unsafe-inline'` blocks. The injected element has no nonce option.

**Fix.** Set `injectStyles: false` and import `@birchui/diagram/styles.css` through your bundler.

## All nodes are at the same position

**Cause.** Nodes are placed at their `x` and `y`. Data without coordinates, or with `x: 0, y: 0` for every node, stacks them at the origin. A node without finite coordinates logs `node "…" needs finite x and y; placing it at 0`.

**Fix.** Run auto-layout once and store the positions:

```ts
await diagram.layout({ type: 'layered' });
```

See [Layout types](https://docs.birchui.com/diagram/layout.md#layout-types).

## An edge or node is missing

**Cause.** The model is validated when it loads:

```text
[Birch UI Diagram] ignoring duplicate node id "manager"
[Birch UI Diagram] ignoring edge "manager-finance" because it refers to a missing node
[Birch UI Diagram] ignoring edge without id: edges need an id, a source and a target
[Birch UI Diagram] node "erp" has an invalid parent "systems"; making it top-level
```

**Fix.** Give every node and edge a unique string `id`, and point `source.node` and `target.node` at existing nodes. See [Edges](https://docs.birchui.com/diagram/nodes-and-edges.md#edges).

## A node renders with the wrong shape

**Cause.** A `type` that is neither built in nor registered in `nodeTypes` logs `unknown node type "…"; rendering it as "…"` once and falls back to the default type.

**Fix.** Register the type in `nodeTypes`, or use a [built-in type](https://docs.birchui.com/diagram/nodes-and-edges.md#built-in-types). Type names are case-sensitive.

## A port is missing

**Cause.** Each port needs a unique `id` and a `side`. Otherwise the diagram logs `node "…" has an invalid or duplicate port; ports need a unique id and a side of top, right, bottom, left` and skips it. `ports` that is not an array logs `node "…" has ports that are not an array; ignoring them`.

**Fix.** Correct the port definitions. See [Ports](https://docs.birchui.com/diagram/nodes-and-edges.md#ports).

## A connection is refused

**Cause.** Self-loops, exact duplicates and targets with `connectable: false` are always refused. Everything else goes through `validateConnection`, and a `readOnly` diagram allows no edits.

**Fix.** Check the `validateConnection` callback with the source and target in the refused drag. See [Connecting](https://docs.birchui.com/diagram/interaction.md#connecting).

## Undo history clears after every edit

**Cause.** Passing a new `nodes` or `edges` array to a framework component reloads the document and clears the undo history. Feeding each change event back into those props does that on every edit.

**Fix.** Load once, let the diagram own the model, and keep your copy up to date from the change events or `toJSON()`. Pass new arrays only when you open a different diagram. See [Loading and framework state](https://docs.birchui.com/diagram/serialization.md#loading-and-framework-state) and [Changes to rows do not reach the widget](https://docs.birchui.com/frameworks/troubleshooting.md#changes-to-rows-do-not-reach-the-widget).

## Exports do not match the screen

**Cause.** `toPNG()` never includes HTML node content, because drawing `foreignObject` onto a canvas taints it; HTML nodes fall back to their shape and label. `toSVG()` includes HTML as `foreignObject` unless you pass `includeHtml: false`.

**Fix.** Return SVG from the template when `ctx.isExport` is true. See [Templates and export](https://docs.birchui.com/diagram/node-templates.md#templates-and-export).

## A watermark appears

**Cause.** The diagram checks its key for `diagram` offline. On a non-local host with no valid key, a watermark appears and one warning is logged, for example:

```text
[Birch UI] No license key is set for Birch UI Diagram. All features keep working; a watermark is shown on non-local hosts until a valid license key is set. Purchase a license at https://birchui.com/pricing
```

**Fix.** Call `setLicenseKey` from `@birchui/license` in the browser bundle, or pass `licenseKey` to `createDiagram`. With server rendering, expose the key through a public variable such as `NEXT_PUBLIC_BIRCHUI_LICENSE_KEY`; see [The license key is not applied with server rendering](https://docs.birchui.com/frameworks/troubleshooting.md#the-license-key-is-not-applied-with-server-rendering) and [What happens without a valid key](https://docs.birchui.com/getting-started/licensing.md#what-happens-without-a-valid-key).

## Duplicate packages and bundle size

**Cause.** Two installed versions of `@birchui/core` or `@birchui/license` split their state, so a key set in one copy is not seen by the other.

**Fix.** Run `npm ls @birchui/core @birchui/license`, align all `@birchui/*` packages on one version and run `npm dedupe`, or add `overrides` in `package.json`. The package is side-effect free apart from its CSS.

## Large graphs are slow

**Cause.** Calling `addNodes` once per node, running layout on every load, `force` layout on large graphs and heavy node templates all add work.

**Fix.** Load the model once, batch API edits in arrays, store coordinates after one layout, prefer `layered` or `tree`, and keep templates light. See [Guidelines for large graphs](https://docs.birchui.com/diagram/performance.md#guidelines-for-large-graphs).

## Framework adapters

Wrap the diagram with `createReactComponent(diagramDefinition)` or the equivalent factory. See [Framework troubleshooting](https://docs.birchui.com/frameworks/troubleshooting.md) for [Strict Mode](https://docs.birchui.com/frameworks/troubleshooting.md#the-widget-is-created-twice-in-development), [Vue proxies](https://docs.birchui.com/frameworks/troubleshooting.md#vue-makes-large-data-slow), [Svelte state](https://docs.birchui.com/frameworks/troubleshooting.md#svelte-state-makes-large-data-slow) and the [Angular zone](https://docs.birchui.com/frameworks/troubleshooting.md#angular-views-do-not-update-after-a-widget-event).

## Related

- [API reference: @birchui/diagram](https://docs.birchui.com/api/diagram.md)
- [Performance](https://docs.birchui.com/diagram/performance.md)
