Server
The server.ts file is the server-side rendering (SSR) entry point for your section. It renders your Vue component to HTML on the server, producing the initial markup that is sent to the browser before JavaScript loads.
How It Works
During a build or server request, the SSR entry point:
Initializes a Vue app instance with your section component
Receives the context (store info, global design) and data (content, design values)
Renders the component to an HTML string using Vue's server renderer
Returns the HTML along with the serialized state for client-side hydration
This ensures the section is visible immediately on page load, before any JavaScript executes.
Usage
// server.ts
import { createVueServerApp } from '@lightspeed/crane-api';
import Section from './Section.vue';
import type { Content, Design } from './type';
export default createVueServerApp<Content, Design>(Section);The generic parameters <Content, Design> provide type safety for the data passed during rendering.
Extensions
createVueServerApp accepts an optional second argument for hooking into the app lifecycle:
All extension callbacks are optional.
SSR Considerations
Since server-side rendering runs in Node.js, browser APIs are not available:
No
window,document, ornavigator— guard any browser-specific code withtypeof window !== 'undefined'or move it toonMountedin your Vue componentNo event listeners — attach them in
onMountedon the client sideNo DOM measurements — use safe defaults during SSR and update in
onMounted
See Best Practices for patterns.
Last updated
Was this helpful?
