restructure project, add claudemd
This commit is contained in:
17
web/ssr/serverData.ts
Normal file
17
web/ssr/serverData.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
// serverData returns the per-page data the backend injected for this render, or
|
||||
// null when there's none.
|
||||
//
|
||||
// Three render contexts, one accessor:
|
||||
// - ISR server render (goja): the handler sets globalThis.__SERVER_DATA__
|
||||
// before rendering, so the page renders with real data.
|
||||
// - Browser takeover: the handler inlines the same data as
|
||||
// <script>window.__SERVER_DATA__ = {...}</script> before the bundle, so the
|
||||
// client re-renders identical markup (no refetch, no flash).
|
||||
// - Static skeleton bake (cmd/bundle): nothing is set, so this returns null
|
||||
// and the component renders its placeholder/skeleton.
|
||||
//
|
||||
// Read it inside the reactive body (not captured at module load) so the value is
|
||||
// observed at render time in every context.
|
||||
export function serverData<T>(): T | null {
|
||||
return ((globalThis as unknown as { __SERVER_DATA__?: T }).__SERVER_DATA__) ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user