The Client Runtime
How Coralite bridges the Serialization Boundary to bring your components to life in the browser.
The Serialization Boundary
In Coralite, your component code is split into two distinct execution contexts. The server() block runs in Node.js at build time. The client() block is serialized and runs in the browser.
Critically, the server() block is physically stripped from the client bundle via AST analysis. This is the Serialization Boundary. Server secrets can never leak to the browser.
<template id="counter">
<button ref="incrementBtn">+1</button>
<span>{{ count }}</span>
</template>
<script type="module">
export function server () {
return { count: 0 }
}
export async function client ({ state, refs, signal }) {
refs('incrementBtn').addEventListener('click', () => {
state.count++
}, { signal })
}
</script>
The client() Context
The client() function receives a single unified context object. The most important keys are refs, state, and signal.
export async function client ({ state, refs, signal, emit }) {
// state: The reactive state object
// refs: A function to query elements by their ref attribute
// signal: An AbortSignal that fires when the component disconnects
// emit: A function to dispatch custom events
}
Targeting DOM Nodes with refs()
Never use document.querySelector or global DOM queries inside your components. They break encapsulation and are slow. Use the refs() function to target elements within your component's scope.
Forbidden:
// ❌ Breaks encapsulation
document.querySelector('.my-button').addEventListener('click', fn)
Required:
// ✅ Scoped, fast, and safe
refs('my-button').addEventListener('click', fn, { signal })