Fine-tune light, shadows, borders, neumorphic
Light and shadows
Borders
Neumorphic

Server rendering

What happens to Prismora in Next.js, Nuxt, SvelteKit, SolidStart, Astro and other frameworks that render on a server.

How it works

  1. On the server your framework writes the element as a tag with its attributes and children: <pm-button variant="soft">Save</pm-button>. Importing a Prismora package on the server is safe: nothing touches window or document at import, and elements are registered only where customElements exists.
  2. In the browser the stylesheet arrives with the page, so tokens, theme, layout classes and the text are right at first paint.
  3. When the script runs each element is upgraded: it builds its inner structure and becomes interactive. Your framework hydrates around it without touching that structure.

Every release is checked for this: each entry of each published package is imported in plain Node, without a DOM, before it can be published, and the reference apps for Next.js, Nuxt, SvelteKit and Astro are built and driven in a browser.

First paint without jumps

Between first paint and upgrade an element is a plain box with its children. Three things keep the page still:

  • Load the CSS in the document head, not from a client-only component: @prismora/css/foundation.css (or prismora.css) and your theme CSS. prismora init puts them in the right file for each framework.
  • Layout comes from classes (pm-stack, pm-grid, pm-app), which need no script. The app shell is laid out by CSS before any element is defined.
  • Overlays stay out of the page. The content of a dialog, drawer, menu, popover, tooltip or command palette is hidden by the stylesheet until its element is defined, so it never flashes in the page.
  • Hide what is not ready, when it matters, with one rule: :not(:defined) matches an element until its script has run.
/* Keep the space of a large element, show nothing half-built. */ pm-data-table:not(:defined), pm-chart:not(:defined) { visibility: hidden; min-block-size: 20rem; }

The theme without a flash

The server cannot know whether the visitor chose dark mode. The no-flash script reads the saved choice and sets the attributes on <html> before the first paint. It must be an inline script in <head>, not a module and not deferred.

import { noFlashScript } from '@prismora/theme'; // Next.js (app/layout.tsx): suppressHydrationWarning because the script changes <html> before hydration. <html lang="en" suppressHydrationWarning> <head><script dangerouslySetInnerHTML={{ __html: noFlashScript }} /></head> <body>{children}</body> </html>

The framework guide shows the same for Nuxt, SvelteKit, SolidStart and Astro; prismora init writes it for you.

Code that must run in the browser

Element imports and wrappers are safe everywhere. These three are for the browser, so call them where your framework runs client code:

CallWhyWhere
new ThemeController()Reads localStorage and the system colour schemeuseEffect (React), onMounted or a .client plugin (Vue, Nuxt), onMount (Svelte, Solid), afterNextRender (Angular), a client <script> (Astro)
toast(), confirm()Create elements in the document
Element methods (dialog.show())Exist once the element is defined

registerIcons() may run on the server too (it only fills a list), but the icons are needed in the browser, so register them in a module the client loads.

// Wait for an element before calling its methods, wherever the code runs first. await customElements.whenDefined('pm-dialog'); document.querySelector('pm-dialog').show();

Notes per framework

FrameworkNote
Next.js, React Router, TanStack Start@prismora/react components are client components ('use client' is in the package). In a server component, write the tag (<pm-card>) or import the wrapper in a client component.
Nuxt, VueTell the compiler that pm- tags are custom elements (isCustomElement); init sets it.
SvelteKitWorks as is. This site is a static SvelteKit build.
SolidStartImport the elements in entry-client.tsx.
AstroImport elements in a <script> of the layout; the no-flash script needs is:inline.
AngularAdd CUSTOM_ELEMENTS_SCHEMA to components that use pm- tags.

What is not rendered on the server

The inside of an element (its shadow DOM) is built in the browser. Text you pass as children or attributes is in the HTML and readable by search engines; what an element draws from data (the rows of pm-data-table, a chart) appears after its script runs. For content that must be in the HTML, render it as children or as plain HTML with the CSS classes (<table class="pm-table">). Rendering shadow DOM on the server (declarative shadow DOM) is planned: see the roadmap.

Problems with hydration warnings or window is not defined? See troubleshooting.