Native DPU: Checking… setHTML(): Checking… CLS/LoAF: Checking…

Track 3 · Hypermedia & Islands · Cloudflare TransformStream + WICG DPU

DPU Out-of-Order Streaming Workbench

Pages that mix fast cached sections (80 ms) with slow database or model calls (520 ms+) normally force a choice: wait for the slowest block before painting anything, or ship client-side JS that re-renders the DOM and breaks typing focus. This workbench tests WICG Declarative Partial Updates over a live TransformStream, streaming sections in the order they finish while measuring CLS, LoAF, focus survival, and setHTML() sanitization.

Why this matters

Traditional server rendering stalls the whole response on the slowest top section, while naive client re-renders rebuild the whole subtree on every chunk—dropping active cursor focus in form inputs and adding framework overhead.

What this opens up

Streaming out-of-order HTML patches (<?start id="..."?>...<?end?> + <template for="...">) over one HTTP response so fast lower sections paint immediately, late upper sections slot cleanly into reserved placeholders without layout jumps (CLS ≈ 0), typing focus survives every update, and untrusted chunks are stripped by setHTML().

How the tests work

Click 1. Run Out-of-Order Stream to watch fast chunks paint first in canonical order, click 2. Trigger Unreserved CLS Trap to see real layout shifts (CLS > 0.1) when placeholders shrink, click 3. Run XSS Chunk Probe to verify stripped payloads, and run the Focus-Preservation Test against the full-DOM rebuild baseline.

3 Things To Try

1. Stream Out of Order Without Layout Jump

Fetches GET /stream/article?delays=520,380,260,160,80 over one chunked stream. The bottom conclusion paints at ~80 ms while the slow top summary lands last (~520 ms) inside reserved placeholders so CLS ≈ 0.

2. Break Layout Stability on Purpose (CLS > 0.1)

Switches to Auto-Height placeholders and delays upper sections (700ms / 540ms / 360ms) after the bottom settles at 40ms, triggering live layout-shift readings when late chunks push content down.

3. Stream an Adversarial XSS Payload

Turns on ?xss=1 to inject an image error handler, an inline <script> tag, and a javascript: link, proving setHTML() / allowlist sanitization strips every attack vector while keeping safe text.

Stream Controls & Feature-Detection Mode

Customize per-section Worker delays, toggle Native vs. Polyfill patching, switch height reservation, and race against Blocking SSR.

Stream: Idle
Detecting browser support for native Declarative Partial Updates, Element.prototype.setHTML() (Sanitizer), layout-shift, and long-animation-frame…
Per-Section Worker Latencies (ms, clamped 0–3000)
Open Raw HTTP Stream ↗
TTFB / First Section — Skeleton arrival vs. fastest patch
Out-of-Order Inversions — Canonical reading order check
Live CLS (Observer) 0.000 Target < 0.100 (0 shifts)
DPU vs. Eager JS Churn — Task time & LoAF entries
Mid-Stream Focus — DPU range vs. Eager re-render
XSS Sanitizer Proof Idle window.__pwned === undefined

Live DPU Streaming Receiver

Surgical <?start id="..."?>...<?end?> Comment-range patching via fetch().body.getReader()

Engine: Ready

Click Run Live Stream above to stream real out-of-order DPU chunks from GET /stream/article.

Eager JS Full-DOM Re-Render Baseline

Rebuilds the entire container subtree on every arriving chunk to measure DOM churn, task time, and focus loss

Baseline: Ready

Runs in parallel on the exact same arriving chunks for a direct side-by-side comparison.

Wire Stream, Sanitizer & Observer Inspector

0 chunks received
1. Chronological Chunk Arrival Timeline & Raw HTTP Stream
Seq Section ID Doc Slot Configured Delay Arrived At Bytes DPU Patch Eager Rebuild
No chunks received yet.

Raw HTTP Response Headers & Streamed Chunks

Waiting for GET /stream/article…
2. Adversarial XSS Sanitizer Telemetry & Vector Audit

Sanitizer Telemetry Summary

Enable "Inject adversarial XSS chunk" or click "Run XSS Chunk Probe" to inspect stripped elements, event attributes, and protocols.

Raw Untrusted Chunk Received on Wire (Inert Text Display)

No adversarial chunk received yet.
3. PerformanceObserver Log (CLS layout-shift & LoAF Entries)
0 layout-shift entries · 0 LoAF entries
Waiting for layout-shift or long-animation-frame entries…
4. Active Receiver & Sanitizer Module Source (public/lib/dpu-stream.js)
Loading /lib/dpu-stream.js…

1. The Problem

Generated pages combine fast cached blocks (80 ms) with slow model or database sections (500–4000 ms). Blocking SSR stalls TTFB until the slowest section completes, while client-side SPAs ship hydration JS that often rebuilds subtrees and drops active focus.

2. The Mechanism

A Cloudflare Worker TransformStream flushes the document skeleton immediately with <?start id="..."?>...<?end?> markers, then writes <template for="..." patch-mode="replace"> chunks as parallel generators complete out of order.

3. The Boundary & Risks

Untrusted streamed patches require setHTML() / strict allowlist sanitization to strip <script>, on*, and javascript: vectors, and upper-document patches require reserved skeleton heights to keep CLS < 0.1.

Architecture Cloudflare TransformStream DPU Emitter & Browser Surgical Range Patcher
Single HTTP/2 Chunked Response · Out-of-Order Completion -> Canonical DOM Order
Edge Stream Producer

Worker TransformStream src/worker.ts

GET /stream/article?delays=520,380,260,160,80
  • Flushes skeleton immediately with <?start id="..."?>...<?end?> markers and X-Accel-Buffering: no
  • Parallel timers write <template for="..." patch-mode="replace"> in completion order (80 ms -> 520 ms)
Browser Receiver

DPU Stream Parser & Sanitizer public/lib/dpu-stream.js

  1. fetch().body.getReader() decodes UTF-8 chunks incrementally
  2. Extracts complete <template for> payloads across chunk splits
  3. Sanitizes via native Element.prototype.setHTML() or DOMParser allowlist importer (zero dangerous sinks)
  4. Replaces ONLY nodes between <?start?> and <?end?> Comment nodes

Measured live with PerformanceObserver (layout-shift + long-animation-frame).

CONFIRM SIGNAL

Surgical Patch + Sanitized + Reserved

CLS ≈ 0.000 · Focus Preserved · __pwned === undefined
TTFB < 100ms 0 B Framework JS XSS Stripped
FALSIFY SIGNAL

Unreserved Upper Expansion / Full Rebuild

CLS > 0.1 · Eager Baseline Drops Focus

Late top sections expanding above settled content cause real layout shifts unless heights are reserved or appended below.

Zero-Sink Security Policy & Edge Headers

CSP + Sanitizer

Enforces strict script-src 'self', Cache-Control: no-cache, no-transform, X-Accel-Buffering: no, and frame-ancestors framing without X-Frame-Options. Client code contains zero unsafe HTML string-injection or dynamic-code sinks.

Out-of-order chunks stream directly from a Cloudflare Worker TransformStream into surgical Comment-bounded DOM ranges while live observers track CLS, LoAF, focus continuity, and sanitizer vector removal.
How This Is Set Up

Out-of-Order DPU Streaming vs. Blocking SSR

Replacing slowest-section blocking responses with immediate <?start id="..."?>...<?end?> skeletons and sanitized out-of-order <template for="..."> patches.

Blocking SSR (Stalls on Slowest Section)
// TTFB blocked until slowest generator (520ms) finishes
const [intro, intent, bench, notes, conclusion] =
  await Promise.all(generators.map((g) => g.run()));
return new Response(renderFullHtml(intro, conclusion));
WICG DPU TransformStream (Out-of-Order + Sanitized)
<!-- Flushed at TTFB ~10ms -->
<section data-slot-id="sec-intro"><?start id="sec-intro"?>Pending…<?end?></section>
<section data-slot-id="sec-conclusion"><?start id="sec-conclusion"?>Pending…<?end?></section>

<!-- Flushed at 80ms (arrives before sec-intro) -->
<template for="sec-conclusion" patch-mode="replace">
  <article>Conclusion ready while top intro is still generating.</article>
</template>
Key terms & further reading
WICG Declarative Partial Updates (DPU) ↗
A web proposal for updating named HTML regions in place using <?start id="..."?>...<?end?> markers and streamed <template for="..."> chunks without client frameworks.
HTML Sanitizer API (setHTML) ↗
A browser API that parses untrusted HTML safely, stripping <script> tags, inline event handlers, and javascript: URLs before inserting nodes.
Cumulative Layout Shift (CLS) ↗
A Core Web Vital measuring unexpected page movement; scores under 0.1 indicate stable layouts when late upper chunks fill reserved heights.
Long Animation Frames (LoAF) ↗
A browser performance entry that flags main-thread rendering stalls over 50 ms, helping compare surgical patching against full-DOM re-renders.
TransformStream ↗
A Web Streams API used by the Cloudflare Worker to flush the initial skeleton immediately and push HTML patches incrementally over one HTTP response.
Anti-Buffering Headers (no-transform / X-Accel-Buffering) ↗
HTTP response headers that tell intermediate proxies to forward each streamed chunk immediately instead of buffering the whole response until EOF.