Every frontend team has lived the same morning: the Lighthouse report blames a bundle you barely shipped, “Total Blocking Time” is red, and the profiler shows the browser spending its first two seconds re-executing framework code for a page that was already fully rendered on the server. Hydration is the tax. React, Vue, Svelte all ship your component tree twice — once as HTML, once as JavaScript — and then walk the DOM a second time to re-attach event listeners and rebuild state the server already had.
Qwik makes a radical bet: never re-execute. Instead of hydrating, it resumes. The server serializes the application’s live state — component state, signals, event handlers, promise results — into attributes and script tags inside the HTML itself, and the browser picks up exactly where the server left off. No listeners are attached until an event actually fires, and no component code is downloaded until a listener needs it.
That bet only works if serialization is bulletproof, so the interesting engineering in this codebase is not the JSX rendering — it is the state engine underneath. We sparse-cloned the monorepo at HEAD of main and read the four directories that carry the weight: packages/qwik/src/core (the runtime), packages/qwik/src/serializer (the serialization engine), packages/qwik/src/server (streaming SSR), and packages/optimizer (a Rust rewrite tool built on SWC). Everything below is verified against that tree, with line numbers you can click.
The full resume loop: the Rust optimizer cuts your code into lazy chunks, SSR streams HTML plus a serialized state graph, and the qwikloader imports symbols only when their events fire.
Reading the overview from left to right:
- transform_modules, L77 — the Rust entry point folds every per-file result into one
TransformOutputand sorts the emitted modules byorder, so chunk output is deterministic. - has_qrl_pattern, L1435 — a recursive AST walk that flags any call whose callee name ends with
$(component$,useTask$, the inline$()). - EntryStrategy, L14 — the four chunking policies,
Inline,Hoist,SingleandSegment, decide how aggressively handlers are split into lazy-loadable files. - qrlToString, L28 — encodes a QRL as
chunk#symbol#captureDeltas, delta-coding each captured root id against the previous one. - Serializer, L89 — the engine that walks the object graph depth-first and writes the roots array as alternating type/value slots.
- TypeIds, L96 — the 45-member tag enum that gives every serialized value a wire type, from
PlaintoEffectSubscriptionNoData. - import(), L222 — the qwikloader’s dynamic import: the first matching event resolves the handler attribute and fetches the chunk.
- inflate, L77 — the client-side restore switch that rebuilds Sets, Maps, Promises, Errors, Signals and Stores from tags.
The detail view adds the machinery behind each stage: identifier collection for captures, out-of-order streaming, subscription data, lazy restore proxies and the 1,876-line reconciler.
Why hydration became the tax every SPA pays
Qwik’s own glossary compresses the render model into one line: “JSX -> vDOM -> vnode_diff -> VNode -> DOM”. Rendering is ordinary. The revolution is in what happens around rendering. In a hydrating framework, the client re-runs every component to reconstruct state that already existed, and re-registers listeners on every interactive element. Qwik never attaches a listener at boot. Instead, the server emits one global listener set — the qwikloader — and each interactive element carries its handler as a serialized attribute string.
The qwikloader source documents the contract precisely: handler attributes hold chunk#symbol#captures#otherChunks QRLs separated by |, and events are routed through scoped kebab-case prefixes e:, ep:, d:, dp:, w: and wp: for element, document and window targets, with passive variants (qwikloader.ts, L19). The loader is a single file of 621 lines that listens globally, scans upward from the event target for a matching attribute, and only then pays the network cost. Until your first click, the app has executed essentially no application code.
QRLs: functions as serialized data
A QRL is Qwik’s answer to a question that normally has no answer: how do you put a closure into HTML? The optimizer lifts each handler body out of its component into a standalone symbol — code_move.rs does the physical extraction, and IdentCollector, L403 walks the closure to find which free identifiers it references, so the capture list is computed by the compiler rather than guessed at runtime.
What lands in the HTML is the wire form. qrlToString, L28 resolves the chunk and symbol, then encodes captures as delta-coded root indexes: each capture becomes a serialization root, and the string stores only the difference between consecutive ids. The inverse, parseQRL, L173, splits the hash-separated string and rebuilds a lazy handle whose resolve() fetches the chunk and deserializes the captured scope on demand. User events are even routed through shared core handlers like _run and _task, deduplicated by hash, so the page’s own handlers stay tiny.
Not every QRL needs a network round trip. Synchronous inline closures are handled by $addSyncFn$, which dedupes function source strings and ships them as entries in a document["qFuncs_<hash>"] array (Q_FUNCS_PREFIX, L142). At write time the serializer reduces a sync QRL to a single integer — its index into that function table (serialize.ts, L533) — so a hot little helper costs one number on the wire instead of a URL plus a symbol name.
Streaming state into the HTML: the qwik/state script
On the server, renderToStream, L44 wires a writer, resolves the symbol manifest, and drives a 2,276-line SSRContainer. That container does three unusual things. It streams HTML out of order — segments behind an unresolved boundary are parked and flushed later, with SsrNode shapes compressed into numeric vnodeData flag arrays. It backpatches: signal bindings whose values arrive after the HTML has flushed are collected into a patch list and emitted as a JSON script that the client applies late (emitPatchDataIfNeeded, L1573).
And it serializes state inline. stateScriptAttrs, L1534 emits a <script type="qwik/state"> element carrying the container instance hash, plus a q-d:qidle attribute whenever some state should resume eagerly at idle time. Synchronous helper functions get their own script keyed by q:func="qwik/json" (emitSyncFnsData, L1543). The serialized format is documented in the repo itself: even slots are TypeIds, odd slots are values, and a RootRef pointing at root n finds its data at slots (n*2, n*2+1) (serialization.md, L15). Cycles and shared references are handled by promoting the referenced object to a root and leaving a backref in place (promoteToRoot, L219).
Out-of-order streaming adds one more protocol detail: a container whose HTML has not finished flushing must not let a premature event resume half-serialized state. The loader keeps commands in its array-like window._qwikEv store, and a special QwikEvContainerReady = 0 entry marks a streamed container’s serialized state as complete (qwikloader.ts, L53). Handlers wait for that readiness signal, which is what makes incremental flushing safe rather than merely fast.
From 1,969-line parser to 45 type tags: build facts you can grep
The optimizer is not JavaScript — it is a Rust crate compiled for napi and wasm, sharing one workspace with the toolchain in the repo root (Cargo.toml, rust-toolchain). parse.rs alone is 1,969 lines of SWC-driven transformation. The monorepo holds 17 packages, publishes the core as @qwik.dev/core 2.0.0-rc.5, and builds with pnpm workspaces (read our pnpm source tour for why that matters in a repo this size).
The serialization engine’s vocabulary is the 45-member TypeIds enum: Plain, RootRef, ForwardRef, Constant, then containers like Set, Map, Promise, Error, then framework values — Signal, Store, ComputedSignal, Task, PropsProxy, SubscriptionData. Promises serialize as ForwardRef and are back-filled when they resolve. One subtle budget lives in auto.ts, L7: plain state qualifies for automatic serialization only under 1,024 estimated bytes, 64 values and depth 8, otherwise it must opt in explicitly — the function returns retain, reuse or omit. And the reconciler the resumed state feeds into is vnode_diff.ts, 1,876 lines of keyed diffing. These are the numbers that tell you this is a systems project wearing a framework costume.
Resuming on the client without re-executing the app
Resume starts the moment the qwikloader sees a matching event, dynamic-imports the chunk, and looks up the symbol (import(), L222; sibling chunks listed after the fourth # are warmed in parallel). Meanwhile the DOM container scans for state scripts with selectors like script[type="qwik/state"][q\:instance="..."] (dom-container.ts, L212) and feeds them through a queue that marks the container ready only when every root has been processed (processContainerStateData, L27).
Restore is deliberately two-phase: allocate creates empty skeletons that can be referenced before they exist, then inflate fills them in — so reference cycles resolve naturally (serialization.md, L26). Roots are restored lazily behind a proxy that deserializes properties on demand and caches them. Reactivity survives the trip too: a store is a Proxy whose handler records per-property effects (createStore, L86), and a signal’s .value getter reads first and subscribes second, so a compute pass never poisons itself with its own invalidation (signal-impl.ts, L60). The runtime runs wherever the render runs — our Node source tour covers the server platform side of that story.
Honest Limits
Resumability is not free magic, and the code is candid about the trade-offs. The optimizer must understand every capture statically; dynamic patterns can force handlers into conservative chunking, and the Enjoyed this post? Never miss out on future posts by following us EntryStrategy choice materially changes how many network requests a page can trigger. Serialized state is HTML weight: an app with large stores pays that weight on every document load, which is exactly why the 1,024-byte auto-serialization budget exists. The edge of the model is visible in the test suite — there is a dedicated spec for resuming across multiple containers on one page (packages/qwik/src/core/tests/multi-container-resume.spec.tsx), because isolated single-container demos always look cleaner than the apps people actually build. Dev-mode ergonomics rely on a __qrl_back_channel__ global that production builds do not have, and the wire format — while versioned inside the repo — is internal, not a public contract. Finally, the ecosystem split between builderio/qwik and the @qwik.dev package scope means blog posts age quickly; verify line numbers against the branch you deploy, not against this article. The Rust source tour is a good companion for readers who want to go deeper into the SWC-based half of this architecture.