# Troubleshooting

> Fix the common problems with the React, Vue, Svelte, Angular, Solid and Web Component adapters, from double mounts to reactive proxies and zone change detection.

The adapters in `@birchui/react`, `@birchui/vue`, `@birchui/svelte`, `@birchui/angular`, `@birchui/solid` and `@birchui/element` share one model: the widget is created once when the component mounts, later prop changes are compared by identity and sent to `update()`, and the widget is destroyed when the component unmounts. Most problems on this page come from code that works against that model.

| Symptom | Jump to |
| --- | --- |
| The widget is empty or zero pixels tall | [The widget has no height](#the-widget-has-no-height) |
| `createGrid` runs twice in development | [The widget is created twice in development](#the-widget-is-created-twice-in-development) |
| New rows or edited rows do not appear | [Changes to rows do not reach the widget](#changes-to-rows-do-not-reach-the-widget) |
| Scrolling or typing gets slower after each render | [The widget updates on every render](#the-widget-updates-on-every-render) |
| Large data sets are slow in Vue | [Vue makes large data slow](#vue-makes-large-data-slow) |
| Large data sets are slow in Svelte 5 | [Svelte state makes large data slow](#svelte-state-makes-large-data-slow) |
| An Angular template does not refresh after a grid event | [Angular views do not update after a widget event](#angular-views-do-not-update-after-a-widget-event) |
| Angular runs change detection constantly | [Angular change detection runs too often](#angular-change-detection-runs-too-often) |
| The ref or `api` is `null` | [The API is null](#the-api-is-null) |
| `document is not defined` or a blank server-rendered page | [Server rendering errors](#server-rendering-errors) |
| The watermark shows in production but not locally | [The license key is not applied with server rendering](#the-license-key-is-not-applied-with-server-rendering) |

## The widget has no height

**Cause.** Each adapter renders one container element and creates the widget inside it. The grid fills its container (`height: 100%`, with a 120 pixel minimum), so a container without a height gives a short or empty grid. In Angular the host element is `display: block` but has no height of its own.

**Fix.** Size the container through the adapter:

**React**

```tsx
<BirchGrid style={{ height: 480 }} columns={columns} rows={orders} />
```

**Vue**

```vue
<BirchGrid style="height: 480px" :columns="columns" :rows="orders" />
```

**Svelte**

```svelte
<BirchGrid style="height: 480px" {columns} rows={orders} />
```

**Angular**

```css
birchui-grid {
  height: 480px;
}
```

In a flex layout, give the container `flex: 1` and `min-height: 0`. See [Sizing the grid](https://docs.birchui.com/grid/theming.md#sizing-the-grid).

## The widget is created twice in development

**Cause.** React Strict Mode mounts, unmounts and mounts every component again in development. `BirchGrid` and components made with `createReactComponent` create the widget in a layout effect and call `destroy()` in its cleanup, so you see two creations and one destruction. The final instance is the one your ref points to. Production builds mount once.

**Fix.** Nothing is needed for the adapter components. Problems appear only in code that creates a widget itself:

- Do not call `createGrid`, `createScheduler` or any other `create…` function in the component body or in `useMemo`. Render runs more than once and the cleanup never runs there.
- When you create a widget in your own effect, destroy it in the cleanup:

```tsx title="SalesChart.tsx"
import { useEffect, useRef } from 'react';
import { createChart, type ChartDatum } from '@birchui/charts';

export function SalesChart({ data }: { data: ChartDatum[] }) {
  const host = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const chart = createChart(host.current!, {
      data,
      series: [{ type: 'column', xKey: 'month', yKey: 'revenue' }],
    });
    return () => chart.destroy();
  }, []);

  return <div ref={host} style={{ height: 320 }} />;
}
```

Better still, wrap the widget with `createReactComponent(chartDefinition)` as shown in [Wrapping your own widgets](https://docs.birchui.com/frameworks/react.md#wrapping-your-own-widgets), which handles Strict Mode and prop updates for you.

## Changes to rows do not reach the widget

**Cause.** Adapters compare each option with the value they last sent using `Object.is`. `orders.push(order)` or `orders[3].status = 'Shipped'` keeps the same array, so nothing is sent.

**Fix.** Pass a new array, or call the API for incremental changes:

```ts
setOrders((current) => [...current, order]);

gridRef.current?.applyTransaction({ update: [{ ...order, status: 'Shipped' }] });
```

Set `getRowId` so updated objects match existing rows. See [Updating data](https://docs.birchui.com/grid/updating-data.md#incremental-changes-applytransaction).

## The widget updates on every render

**Cause.** An inline array, object or function, such as `columns={[...]}` or `getRowId={(row) => row.id}`, is a new value on each render. The adapter sends it to `update()` every time, and a new `columns` array re-resolves every column.

**Fix.** Define `columns`, `getRowId`, `modules`, `pagination` and similar values outside the component, or memoize them with `useMemo` and `useCallback` (React), `const` in `<script setup>` (Vue) or `<script>` (Svelte). Event handler props (`onCellClick` and so on) are always read from the latest render and never cause an update, so inline handlers are fine. See [Props and updates](https://docs.birchui.com/frameworks/react.md#props-and-updates).

## Vue makes large data slow

**Cause.** A deep `ref` or `reactive` turns every row object into a proxy. With tens of thousands of rows this costs memory and time, the grid receives proxies instead of your objects, and in-place mutations still do not reach it, because the adapter watches `options` only one level deep. Wrapping the widget API in `ref()` proxies the API object as well.

**Fix.** Hold rows in `shallowRef` and assign a new array to change them. Use the exposed `api`, which the adapter already stores in a `shallowRef` and marks raw; do not copy it into `ref()`.

```ts
import { markRaw, shallowRef } from 'vue';

const orders = shallowRef<Order[]>([]);

async function loadOrders() {
  const response = await fetch('/api/orders?status=open');
  orders.value = markRaw(await response.json());
}
```

See [Reactivity and updates](https://docs.birchui.com/frameworks/vue.md#reactivity-and-updates).

## Svelte state makes large data slow

**Cause.** `$state` makes every row a deep proxy. It is slow for large data sets, and `orders.push(order)` keeps the same array, so the adapter does not send it.

**Fix.** Declare rows and the bound API with `$state.raw`, and assign new arrays:

```svelte
<script lang="ts">
  import { BirchGrid } from '@birchui/svelte';
  import type { GridApi } from '@birchui/core';

  let orders = $state.raw<Order[]>([]);
  let api = $state.raw<GridApi<Order> | null>(null);

  function addOrder(order: Order) {
    orders = [...orders, order];
  }
</script>

<BirchGrid bind:api style="height: 480px" {columns} rows={orders} getRowId={(order) => order.id} />
```

See [Updates and reactivity](https://docs.birchui.com/frameworks/svelte.md#updates-and-reactivity).

## Angular views do not update after a widget event

**Cause.** `injectBirchWidget` creates the widget and its DOM listeners outside the Angular zone. Outputs such as `(cellClick)` re-enter the zone when they emit. A handler you register directly on the widget, for example `grid.instance?.on('selectionChanged', ...)`, runs outside the zone, so a zone-based app does not run change detection for it.

**Fix.** Prefer the component outputs. When you subscribe directly, re-enter the zone:

```ts
import { Component, NgZone, afterNextRender, inject, signal, viewChild } from '@angular/core';
import { BirchGridComponent } from '@birchui/angular';

@Component({
  selector: 'app-orders',
  standalone: true,
  imports: [BirchGridComponent],
  template: `<p>{{ selected() }} selected</p><birchui-grid [columns]="columns" [rows]="orders" />`,
})
export class OrdersComponent {
  private readonly zone = inject(NgZone);
  private readonly grid = viewChild.required<BirchGridComponent<Order>>(BirchGridComponent);
  readonly selected = signal(0);

  constructor() {
    afterNextRender(() => {
      this.grid().instance?.on('selectionChanged', ({ selected }) =>
        this.zone.run(() => this.selected.set(selected.length)),
      );
    });
  }
}
```

Zoneless apps that use `provideZonelessChangeDetection()` need no `zone.run()`. See [Change detection](https://docs.birchui.com/frameworks/angular.md#change-detection).

## Angular change detection runs too often

**Cause.** Work you start yourself, such as a `setInterval` or a websocket that calls `applyTransaction`, runs inside the zone and triggers change detection on every tick.

**Fix.** Start it with `zone.runOutsideAngular(() => ...)`. The widget does not need the zone to render, and only state your templates read needs `zone.run()`.

## The API is null

**Cause.** The widget is created after the first render: in a layout effect (React), `onMounted` (Vue), an effect (Svelte, Solid) or `afterNextRender` (Angular). Before that, and after unmount, the ref, `api` or `instance` is `null` or `undefined`.

**Fix.** Use optional chaining (`gridRef.current?.setQuickFilter('emea')`), call the API from event handlers, or listen for the `ready` event (`onReady` in React and Svelte, `@ready` in Vue, `(ready)` in Angular).

## Server rendering errors

**Cause.** Every package is safe to import on the server, and the adapters create widgets only in the browser. Errors such as `document is not defined` come from calling a `create…` function yourself during server rendering, or, in the Next.js App Router, from rendering `BirchGrid` in a Server Component.

**Fix.** Create widgets only in browser lifecycle hooks, and mark the Next.js file that renders an adapter component with `'use client'`. Pass serializable data from the server and define columns, which usually hold functions, in the client file. See [Next.js and server rendering](https://docs.birchui.com/frameworks/react.md#nextjs-and-server-rendering) and [SvelteKit](https://docs.birchui.com/frameworks/svelte.md#sveltekit).

## The license key is not applied with server rendering

**Cause.** `setLicenseKey` stores the key in the copy of `@birchui/license` that runs it. A call that runs only on the server never reaches the browser bundle. A key read from a private environment variable is also `undefined` in the browser, because frameworks inline only public variables into client code.

**Fix.** Call `setLicenseKey` in code that runs in the browser, and expose the key through a public variable:

| Framework | Variable | Where to call `setLicenseKey` |
| --- | --- | --- |
| Next.js | `NEXT_PUBLIC_BIRCHUI_LICENSE_KEY` | A `'use client'` module in the root layout |
| Vite, Vue, React, Solid | `VITE_BIRCHUI_LICENSE_KEY` | `main.ts` before mounting the app |
| SvelteKit | `PUBLIC_BIRCHUI_LICENSE_KEY` from `$env/static/public` | `src/routes/+layout.svelte` |
| Nuxt | `runtimeConfig.public` | A client plugin |
| Angular | `environment.birchLicenseKey` | `main.ts` before `bootstrapApplication` |

The variable must be defined when the production bundle is built. Widgets re-check the key when it changes, so order does not matter. The console warning names the reason a key was rejected; see [What happens without a valid key](https://docs.birchui.com/getting-started/licensing.md#what-happens-without-a-valid-key).

## Related

- [React](https://docs.birchui.com/frameworks/react.md), [Vue](https://docs.birchui.com/frameworks/vue.md), [Svelte](https://docs.birchui.com/frameworks/svelte.md), [Angular](https://docs.birchui.com/frameworks/angular.md), [Solid](https://docs.birchui.com/frameworks/solid.md) and [Web Component](https://docs.birchui.com/frameworks/web-component.md)
- [Licensing and activation](https://docs.birchui.com/getting-started/licensing.md)
- [API reference: @birchui/react](https://docs.birchui.com/api/react.md), [@birchui/vue](https://docs.birchui.com/api/vue.md), [@birchui/svelte](https://docs.birchui.com/api/svelte.md)
