UI frameworks
Next.js
Render a Vela Pro workspace in Next.js App Router using a Client Component without dynamic import wrappers.
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
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:
'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
Import and render <Chart /> directly inside a Server Component page or layout, and give its outer wrapper an explicit height:
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
- 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 callingenableVelaPro()only populates in-memory SDK registries. - Keep
new VelaWorkspace()insideuseEffect: ConstructingVelaWorkspacereadsdocumentand initializes Canvas and WebGL2 surfaces, so callingnew VelaWorkspace()during render throwsdocument is not definedon the server. Running the constructor insideuseEffectlets the server emit the sized container<div>and mounts the chart in the browser during hydration without anext/dynamicwrapper. - Update from route parameters in place: When navigating between dynamic routes that keep
<Chart />mounted in a shared layout, the seconduseEffectswitches the active market withworkspace.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
| Stack | Verified versions | Checks run |
|---|---|---|
| Next.js (App Router) | Next.js 16.4 | Static prerendering (next build) and production server (next start) |