Server rendering
What happens to Prismora in Next.js, Nuxt, SvelteKit, SolidStart, Astro and other frameworks that render on a server.
How it works
- 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 toucheswindowordocumentat import, and elements are registered only wherecustomElementsexists. - In the browser the stylesheet arrives with the page, so tokens, theme, layout classes and the text are right at first paint.
- 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(orprismora.css) and your theme CSS.prismora initputs 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.
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.
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:
| Call | Why | Where |
|---|---|---|
new ThemeController() | Reads localStorage and the system colour scheme | useEffect (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.
Notes per framework
| Framework | Note |
|---|---|
| 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, Vue | Tell the compiler that pm- tags are custom elements (isCustomElement); init sets it. |
| SvelteKit | Works as is. This site is a static SvelteKit build. |
| SolidStart | Import the elements in entry-client.tsx. |
| Astro | Import elements in a <script> of the layout; the no-flash script needs is:inline. |
| Angular | Add 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.