Automatic server components and resumability
Server components, server views and resumability describe parts of one Fuzor
rendering system. Write the component's HTML, put server work in a leading
<script server>, and add a normal <script> when it needs browser behavior.
The compiler prepares the structure and connects data, actions and updates.
These capabilities apply automatically to supported native declarations.
| Term | Meaning in Fuzor |
|---|---|
| Server component | An HTML component with server code that supplies public data or actions. |
| Server view | The component's compiled structure filled with its current public server answer. |
| Resumability | The browser continues from the emitted HTML and declared state, loading managed handlers when needed. |
You author one component. Fuzor generates its identities, metadata, lazy handler references and server transport. No companion fragment, handler or server files, ambient declarations, per-component Vite registration, renderer setup or refresh calls are required.
Write one HTML component
<!-- components/counter-panel.html -->
<script server>
export default ({ url }) => ({
title: url.searchParams.get("title") ?? "A compiled counter"
})
</script>
<script>
const count = fuzor.state("count", 0)
fuzor.action("increment", () => count.update(value => value + 1))
</script>
<section>
<h2><fz-state name="title"></fz-state></h2>
<button type="button" data-fz-click="increment">
Count: <fz-state name="count"></fz-state>
</button>
</section>
Use <counter-panel></counter-panel> in a page. Fuzor discovers the HTML component
and generates the integration using the ordinary fuzorPlugin() setup. This
example's title comes from the request; its counter is local to each instance.
The first response contains the resolved title and 0 before browser JavaScript
runs. The first click loads the managed action and updates only the count binding.
The client script is optional. A server-only component can bind public props
directly through <fz-state>, supported fields and attributes, data-fz-each
lists and data-fz-if conditions. For local state, use fuzor.state; derived
values use fuzor.computed. See the native authoring
reference for their supported expressions and
bindings.
One lifecycle
- Compile. Fuzor resolves component markup ahead of time, prepares binding and structural update programs, and separates server implementation from browser handlers.
- Produce HTML. Build-only public props are evaluated during compilation. Request loaders run for the actual request and fill the compiled structure. Both paths emit HTML and the public state needed to continue it.
- Resume. The browser adopts that HTML, restores the declared cells using Effect Atom, and attaches the generated event dispatch. Managed declaration scripts and actions are not replayed as initialization.
- Update. Local writes patch affected bindings. Fresh server answers update compatible owners in place. The surrounding component is retained.
- Dispose. Leaving the owner cancels its pending work and releases its resources. Late answers cannot take over a newer page.
An ordinary imperative script, such as editor initialization, still runs when its instance activates. Fuzor resumes its declared state and managed handlers; it does not serialize arbitrary JavaScript closures or an entire execution heap. Third-party Framework Islands retain their own runtime contracts.
Build time and request time
A server script exporting const props supplies build-time public data. Export
a default loader function for request-dependent data. A loader receives
request, url, route params and an abort signal; it may return JSON, a
Promise or an Effect. Its function is not executed during the build, although
server module initialization and imports are. defineServerData(loader, options)
is optional when you need dependency keys, caching or a different timeout.
Only explicit public props, loader results and declared state are sent to the browser. Server imports and implementation stay on the server. Keep credentials and private records out of the public result.
| Application work | Hosting requirement |
|---|---|
| Compiled HTML, build-time server props and local state/actions | Static hosting works, including SPA, MPA and inline output. |
| Request-dependent data or server actions | A reachable backend executes the private code. Fuzor generates backend output automatically. |
| MPA navigation | Each navigation receives a complete document and resumes its own component instances. |
| SPA navigation | The generated router adopts compiled route structure and connects its server reads where needed. |
Request-time work selects request rendering automatically. An explicitly static deployment or inline-only build fails when it cannot serve that work. Static hosting cannot execute private server code after deployment. You still choose your application's navigation and hosting policies.
Fine-grained compatible updates
Each state cell has compiled dependent bindings. A changed cell visits those bindings; equal values do no DOM work. Synchronous writes are batched. State objects and arrays are whole cells, so use separate cells for values that need independent writes.
Server-only outputs follow fresh public props. Local state and edited prop-backed cells retain their client values. Compatible refreshes preserve DOM identity, field drafts, focus and selection. Keyed lists retain rows with the same key; conditional templates create or remove their admitted content. Changing the route's parameters creates a new route instance; a query update can refresh the current instance while retaining local state.
Keyed row templates can contain conditional content. data-fz-item-if="path"
reads a boolean from that row; nested data-fz-if="state" reads the owner's
state. Compatible visible branches retain their DOM and field drafts when a row
moves. Hiding a branch removes its content, and reopening creates fresh content.
Branch actions keep the containing row's untrusted key. See the
native structural bindings
for the template contract and examples.
This updates already compiled structure. A server answer supplies public data; it cannot supply executable templates, handler import URLs or arbitrary DOM instructions. HTML, metadata and generated code must come from the same build.
Actions refresh their views automatically
Declare fuzor.action("save", handler) in the server script and use
data-fz-click="save" or a supported form event in the markup. The action name
is local to the component. Fuzor generates the request dispatch, executes the
server handler, reevaluates the selected loaders and applies the returned public
seeds. The action does not need to return markup, and the application does not
call fetch or refresh the view itself.
By default an action refreshes the route's loaders conservatively. Optional
dependency keys and context.invalidate(...) narrow the reads to the affected
data. Unknown dependencies still refresh. Fuzor does not infer dependencies
inside arbitrary SQL or HTTP calls. These keys describe data dependencies;
authorization and validation belong in your loaders and mutations.
Server actions in keyed rows receive an untrusted context.event.rowKey;
validate it and authorize access before using it. Failed refreshes are reported
separately from mutations, and Fuzor never automatically retries a write. See
the server action contract.
Asynchronous reads
Initial request-rendered HTML streams in document order, including for readers without JavaScript. Page data and the first owner finish before headers, then later owners load on downstream demand. Ready content appears before a later slow owner finishes; a slow first owner still delays the shell. Modules and the complete route seed are sent only after every owner succeeds, so adoption needs no duplicate read. HEAD remains buffered.
Preflight failures return safe 404/500/504 documents. After headers, a failure cannot change the 200 status: the server reports it privately and terminates the response body without successful startup or a completed continuation. The default document deadline is 30 seconds; the shortest declared loader timeout overrides it and must be between 1 ms and 120 seconds. Public seeds retain their 2 MiB aggregate cap; complete documents are capped at 16 MiB.
SPA entry and query reads stream independent component answers as they finish. The compiler wires the transport automatically. Previous values remain until their replacement arrives; a valid component failure leaves healthy sibling answers usable. Put values that must agree in one loader answer and use the backend's transaction or revision guarantees for a coherent read.
Updates are checked against the current build, page, owner and sequence before
they are accepted. Navigation cancels obsolete reads. An action refresh
supersedes older pending answers for the affected owners while unrelated reads
can finish. The stream decoder loads only when this read path needs it; SSR
adoption and action refreshes do not load it. Failed reads emit
fuzor:data-error; private exception details are redacted.
External changes and optimism
Automatic action refresh covers changes made through Fuzor's server actions. Changes made by another process, a database console or an external service need a real notification source. Ordinary HTML server components do not yet subscribe to those changes automatically.
Automatic HTML-owner subscriptions to external changes, distributed source coordination and automatic optimistic mutation inference remain open.
Current limits
- Conditional branches inside rows support up to eight levels of nesting. Nested keyed lists, scripts and native, UI or framework owners inside row templates are rejected, including in hidden branches. Static nested components are supported outside dynamic row templates.
- Request-seeded text, input, textarea, checkbox, single-value select and safe attribute bindings are supported. Selects use static options/optgroups; supply a value present in that list. Multiple-value selects are rejected.
- Resumable state is bounded, finite JSON. It does not include imported modules' private mutable state, arbitrary closures or browser resources. Persistence across reloads is a separate, opt-in application policy.
- Keeping a component during a compatible refresh does not imply persistent layouts across route changes.
- Node and production browser checks cover this automatic path. Actual deployed Workers qualification remains open.
The native guide documents the state, action, computed, effect and binding syntax used by this system. The server data reference describes loader results, caching, dependency keys and errors.
Owned children in compiled rows
The lists guide walks through a tested example.
Compiled row templates admit native declarations, scoped module scripts, Fuzor UI roots and framework islands even when initially empty or hidden. The list owns placement and declared public inputs; each child owns its DOM and lifetime. Identity is the full typed root/row/owner address. Moves retain the live child; removal cancels its generation before late work can attach. Returning keys start fresh lifetimes and may consume compatible explicit native/UI checkpoint lineage. Native and UI checkpoint envelopes and UI public snapshots are version 2; private machine snapshots remain independently versioned. Address/definition/schema and whole-subtree limits are checked before publication. DOM scroll/animation resources restore by stable IDs, never sibling positions.
Server child props and action targets resolve through compiled slots and current server rows. Posted paths and event keys confer no authorization. Recursive reads share one per-request cache and eight-reader semaphore. Missing authoritative children are hidden/disposed, and reappearance creates a fresh lifetime. Read and stream failures retain existing status/abort semantics; mutations are never retried automatically. The application still authenticates and authorizes each action.
React, Solid and Vue retain roots/local state on moves and update props through
persistent adapters. Build-known row props receive previews; request-only props
keep the compiled authored fallback until activation. Dynamic row props cannot use
client:none. Framework heaps and arbitrary script closures are not checkpoints.
The shared bounds remain eight structural levels, sixteen address segments and
2,048 rows/child owners per admitted native subtree. Parent holes cannot write
machine-owned ARIA, tabindex or selected/value state.