Skip to content

Stream-native code rendering

Render the stream.
Land the diff.

Syntax highlighting and review-ready diffs for AI output. No Monaco, no workers, editable when you need it.

src/billing/categorizeCharge.ts
streaming
Built on @pierre/diffs and ShikiVue, React, Svelte, vanilla0 Monaco workersMIT licensed

One stream, three usable states.

Start with append-only rendering. Upgrade to a review surface only when the content is complete.

Append

Plain text first

Deltas land in one pre. No text model, no worker, no layout thrash while the answer is still moving.

for await (const delta of stream)
  output.append(delta)

output.getStats()
// renderMode: 'plain-text'
Finalize

Highlighted file

One final snapshot becomes an interactive file with Shiki highlighting. The stream already sits on the final metrics, so the text does not move.

await output.finalize({
  view: 'file',
  enableLineSelection: true,
})
Review

Accurate diff

Generate the diff from the final text, not the partial tokens. Select, annotate, accept, or reject a hunk.

await output.finalize({
  view: 'diff',
  original: previous,
  diffStyle: 'split',
})

Review surfaces, not just colored text.

Every capability below ships in the controller. The playground uses the same API.

Edit in place

Read-only by default. startEditing() loads the editor lazily, waits for hydration, and hands you a real document with undo and redo.

Editing guide
const editor = await surface.startEditing({
  onChange: event => queueSave(event.file),
}, 'review-draft')

Annotations that align

Attach review comments to a line. They survive rerenders and move with the edit session.

Mina

Keep the empty-id check before the request so the network layer never sees a bad key.

additions line 4
surface.setAnnotations([
  { side: 'additions', lineNumber: 4, metadata },
])

Selection and decisions

Controlled line selection, token hover, accept and reject. The resolved file is yours to save.

review.acceptReject(0, 'accept')
review.getResolvedFile()?.contents

Merge conflicts

Resolve current, incoming, or both without leaving the page.

Drop-in for markstream-vue

If both renderers are installed, stream-diffs wins. Existing CodeBlockNode usage stays the same.

<MarkdownRender
  :content="markdown"
  :loading="streaming"
/>
Integration notes

Fast enough to leave in the chat path.

On the measured Chrome benchmark, stream-diffs put a visible code surface on screen 92% sooner than stream-monaco and used 92% fewer renderer DOM nodes.

Chrome 150, 1440x1000, three repetitions. Methodology and commands live in the performance notes.

Read the benchmark
72.4ms

median cold fallback visible

stream-monaco: 913.0 ms
17.3kB

first-party runtime gzip

Excludes the lazy renderer payload
0

Monaco models or workers

Append-only streaming path

The playground, at full size.

Edit two sources, switch unified and split, annotate a line, then start an inline editor on the rendered diff.

The stream-diffs playground showing two source editors above a rendered split diff with review controls

One controller for the whole code block.

Stream plain text, land a highlighted file or diff, then edit in place.