Next.js App Router SDK Best Practices
Best practices#
Use TypeScript -- The SDK is TypeScript-first. Type all parameters with
ComponentParameter<T>and slots with string literal union types.Mark parameters as optional -- Always use
?for parameter types. Parameters can beundefinedeven when marked required in the Uniform dashboard.Push
"use client"as far down the tree as possible -- The"use client"directive (a React Server Components concept, not Uniform-specific) turns a component and all its children into client components. Only add it to the smallest leaf components that truly need browser APIs (e.g., a quirk button, a score display). Keep page layouts and content components as server components for faster rendering and less JavaScript.Use ISR for performance -- Configure
generateStaticParams()for your most-visited paths to serve pre-rendered pages. See details in the ISR section hereAvoid dynamic functions at the top of pages -- Keep
cookies(),headers(), or other dynamic Next.js functions in components deeper in the tree, wrapped inSuspense, to maximize static rendering.Use
flattenValuesfor assets and content blocks -- Always useflattenValuesfrom@uniformdev/canvasfor asset parameters. See more details in designated guide here.Use
resolveComponentfallback -- Always return a fallback component fromresolveComponentto gracefully handle unknown component types.