A guide to integrate Para SDK with TanStack Start while preserving server-side rendering capabilities.
This guide will walk you through integrating Para SDK with TanStack Start while preserving server-side rendering (SSR) capabilities.
TanStack Start is a full-stack React framework powered by TanStack Router. Para SDK uses styled-components internally which requires client-side only loading to work correctly with SSR.
Before starting, you’ll need a Para API key which you can obtain from the Para Developer Portal. You can learn to create your account and get your API key from the Developer Portal.
Since TanStack Start uses Vite under the hood, we need to set up polyfills for modules like crypto, buffer, etc. that Para SDK relies on. We only want to run these polyfills on the client, not on the server.
Install the Vite Node Polyfills plugin:
Copy
Ask AI
npm install vite-plugin-node-polyfills --save-dev
Configure the polyfills in your app.config.ts:
app.config.ts
Copy
Ask AI
import { defineConfig } from "@tanstack/react-start/config";import tsConfigPaths from "vite-tsconfig-paths";import { nodePolyfills } from "vite-plugin-node-polyfills";export default defineConfig({ tsr: { appDirectory: "src" }, // Base configuration (applied to both client and server) vite: { plugins: [tsConfigPaths({ projects: ["./tsconfig.json"] })], define: { // This helps modules determine the execution environment "process.browser": true, }, }, // Client-specific configuration routers: { client: { vite: { // Apply node polyfills only on the client side plugins: [nodePolyfills()], }, }, },});
Create a providers component using React.lazy and ClientOnly to ensure Para SDK only loads on the client:
src/components/Providers.tsx
Copy
Ask AI
import React from "react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { ClientOnly } from "@tanstack/react-router";const queryClient = new QueryClient();// Lazy load ParaProvider to avoid SSR issuesconst LazyParaProvider = React.lazy(() => import("@getpara/react-sdk").then((mod) => ({ default: mod.ParaProvider })));export default function Providers({ children }: React.PropsWithChildren) { return ( <ClientOnly fallback={null}> <QueryClientProvider client={queryClient}> <LazyParaProvider paraClientConfig={{ apiKey: import.meta.env.VITE_PARA_API_KEY || "", env: "BETA" as const }} config={{ appName: "Your App Name" }} > {children} </LazyParaProvider> </QueryClientProvider> </ClientOnly> );}
Para offers two hosted environments: Environment.BETA (alias Environment.DEVELOPMENT) for testing, and
Environment.PROD (alias Environment.PRODUCTION) for live use. Select the environment that matches your current
development phase.
The Para SDK uses styled-components internally which can cause issues during server-side rendering. By using React.lazy and ClientOnly, we ensure Para components are only evaluated in the browser environment where styled-components works correctly.