# Next.js (/vela-pro/get-started/frameworks/nextjs)



In Next.js App Router, render `VelaWorkspace` inside a Client Component (`'use client'`) and instantiate it inside `useEffect`. Module-level imports from Vela's open-source core (`@luxalgo/vela/workspace`), `@luxalgo/vela-pro`, and module packages do not access browser globals at import time, so `next/dynamic` with `ssr: false` is not required.

## Client Component [#client-component]

Create a Client Component that calls `enableVelaPro()` at module scope, constructs `VelaWorkspace` on mount, synchronizes prop changes in place, and destroys the workspace on unmount:

```tsx
'use client';

import { useEffect, useRef } from 'react';
import { VelaWorkspace } from '@luxalgo/vela/workspace';
import { BinanceProvider } from '@luxalgo/vela/providers/binance';
import { enableVelaPro } from '@luxalgo/vela-pro';

enableVelaPro();

export function Chart({ symbol = 'BTCUSDT' }: { symbol?: string }) {
    const containerRef = useRef<HTMLDivElement>(null);
    const workspaceRef = useRef<VelaWorkspace | null>(null);

    useEffect(() => {
        const workspace = new VelaWorkspace(containerRef.current!, {
            layout: false,
            symbol,
            timeframe: '60',
            live: true,
            providers: { binance: () => new BinanceProvider() },
        });
        workspaceRef.current = workspace;

        return () => {
            workspaceRef.current = null;
            workspace.destroy();
        };
    }, []);

    useEffect(() => {
        const workspace = workspaceRef.current;
        if (workspace && workspace.active.symbol !== symbol) {
            workspace.active.setSymbol(symbol);
        }
    }, [symbol]);

    return <div ref={containerRef} style={{ width: '100%', height: '100%' }} />;
}
```

## Server Component parent [#server-component-parent]

Import and render `<Chart />` directly inside a Server Component page or layout, and give its outer wrapper an explicit height:

```tsx
import { Chart } from './Chart';

export default async function MarketPage({
    params,
}: {
    params: Promise<{ symbol?: string }>;
}) {
    const { symbol = 'BTCUSDT' } = await params;

    return (
        <main style={{ height: '100vh' }}>
            <Chart symbol={symbol} />
        </main>
    );
}
```

## Server-side rendering notes [#server-side-rendering-notes]

* **Module imports and `enableVelaPro()` are SSR-safe**: Next.js evaluates `'use client'` modules on the server during prerendering and initial HTML generation. Importing `@luxalgo/vela/workspace`, `@luxalgo/vela-pro`, and `@luxalgo/vela-pro-*` requires no DOM, and calling `enableVelaPro()` only populates in-memory SDK registries.
* **Keep `new VelaWorkspace()` inside `useEffect`**: Constructing `VelaWorkspace` reads `document` and initializes Canvas and WebGL2 surfaces, so calling `new VelaWorkspace()` during render throws `document is not defined` on the server. Running the constructor inside `useEffect` lets the server emit the sized container `<div>` and mounts the chart in the browser during hydration without a `next/dynamic` wrapper.
* **Update from route parameters in place**: When navigating between dynamic routes that keep `<Chart />` mounted in a shared layout, the second `useEffect` switches the active market with `workspace.active.setSymbol(symbol)` without rebuilding the workspace.
* **Destroy on unmount**: Returning `workspace.destroy()` releases WebGL contexts, Web Workers, and live market subscriptions when navigating away from the route.

## Verified environment [#verified-environment]

| Stack                | Verified versions | Checks run                                                              |
| -------------------- | ----------------- | ----------------------------------------------------------------------- |
| Next.js (App Router) | Next.js 16.4      | Static prerendering (`next build`) and production server (`next start`) |

## Related [#related]

* [Installation](/vela-pro/get-started/setup)
* [Quickstart](/vela-pro/get-started/quickstart)
* [React](/vela-pro/get-started/frameworks/react)
* [Vue](/vela-pro/get-started/frameworks/vue)
* [Events and subscriptions](/vela-pro/charts/events)
