Overview

These APIs ship in core mates so the same components run on the server and in the browser. Use them to gate DOM APIs, read the request context during SSR, and coordinate async completion.

Hydration flags and the boot script live on Hydration. Store snapshot transfer is documented under globalStore and pageStore.

Flags

API
When true
Notes
isServer() Node start process Symbol.for('mates.server')
isBrowser() Client JS realm Symbol.for('mates.browser')
isDev() Non-production env Independent of SSR

Flag readout (browser)

In the SPA playground every SSR flag is false; isDev follows the build.

import { html, renderApp, isServer, isBrowser, isDev, isHydrating } from 'mates';

const App = () => () => html`
<div class="m-col m-gap">
<div class="card card-body">
<span class="overline">Client flags (SPA playground)</span>
<div class="mono">isServer() = ${String(isServer())}</div>
<div class="mono">isBrowser() = ${String(isBrowser())}</div>
<div class="mono">isDev() = ${String(isDev())}</div>
<div class="mono">isHydrating() = ${String(isHydrating())}</div>
</div>
<p class="muted m-t-5">Document-pass isSSR() lives on mates-fullstack, not mates.</p>
</div>
`;
renderApp(App, document.getElementById('app'));

getContext() on the client

Returns undefined outside a server request.

import { html, renderApp, getContext } from 'mates';

const App = () => {
const ctx = getContext(); // undefined in the browser playground
return () => html`
<div class="m-col m-gap">
<p class="muted">
getContext() → ${ctx ? ctx.req.path : 'undefined (client)'}
</p>
<p class="muted m-t-5">During SSR/RPC, ctx.req / cookie / auth are populated.</p>
</div>
`;
};
renderApp(App, document.getElementById('app'));