Serializable State
- Marko serializes only state that browser code reads so pages resume without re-rendering
- Most JavaScript and Web API built-ins, promises, symbols, and cyclic references are supported
- Template-authored functions and closures serialize; external module functions, custom classes, and DOM nodes do not
To resume server-rendered HTML in the browser, Marko serializes only the server values referenced by client event handlers, <script> effects, and reactive updates.
Supported Types
Marko's serializer supports most standard JavaScript and Web API data types:
- Primitives:
undefined,null,boolean,number,string,bigint - Plain objects and arrays containing serializable values
Date,RegExp,Map,Set- Typed arrays,
ArrayBuffer, andDataView Promise, generators, async generators, andReadableStreamURL,URLSearchParams,Headers,Request,Response, andFormData(string entries)- Built-in
Errortypes, includingAggregateError Intlformatters andTemporalvalues- Symbols (well-known, registered, and unregistered
Symbol()) - Functions and closures authored inside
.markotemplates (and supported JS built-in functions)
For the exact list, see serializer.ts.
Reactive state reaches the client automatically when browser code depends on it. $global stays server-only unless properties are listed in $global.serializedGlobals so request-scoped values such as a locale can be read after resume.
Unserializable Data
Values that cannot be serialized across the server-to-client boundary include:
- Functions imported from external
.jsor.tsmodules, or created dynamically outside.markotemplates - Custom class instances (keep plain data in state and instantiate classes on the client inside
<lifecycle>or<script>) - DOM nodes and elements (use native element references instead)
Functions and closures defined directly inside .marko templates are compiler-registered and serializable:
<let/handler=null>
<const/onSecondClick() {
// Registered by the compiler and serializable
}>
<button onClick() {
handler?.();
handler = onSecondClick;
}>
Click
</button><let/handler=null as (() => void) | null>
<const/onSecondClick() {
// Registered by the compiler and serializable
}>
<button onClick() {
handler?.();
handler = onSecondClick;
}>Click</button>let/handler=null
const/onSecondClick() {
// Registered by the compiler and serializable
}
button onClick() {
handler?.();
handler = onSecondClick;
} -- Clicklet/handler=null as (() => void) | null
const/onSecondClick() {
// Registered by the compiler and serializable
}
button onClick() {
handler?.();
handler = onSecondClick;
} -- ClickKeep reactive state as plain serializable data rather than custom class instances or DOM references:
// ✅ serializable plain data
<let/cart={ items: [{ id: 1, qty: 2 }] }>
// ❌ unserializable values (custom class instance or DOM node)
<let/invalidCart=new Cart()>
<let/invalidDom={ el: document.body }>// ✅ serializable plain data
let/cart={ items: [{ id: 1, qty: 2 }] }
// ❌ unserializable values (custom class instance or DOM node)
let/invalidCart=new Cart()
let/invalidDom={ el: document.body }Further Reading
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.