Skip to content
Torso

How it works

From a click on the page to a line in your code

Torso has no database and no content API. It works because it knows, for every word on the page, which line of which file it came from. Here is how it finds out, and what it does with that.

01

At build time, your components are read

Wrapping your Next.js config adds one step to the compiler. It reads each component, finds the text and link addresses that are written out literally, and stamps a short id on the element that holds them.

The file on disk is never modified. Anything dynamic, such as a variable, a loop or a function call, is left exactly as it is.

components/hero.tsx, as you wrote it
export function Hero() {  return (    <section>      <h1>Ship faster</h1>      <a href="/signup">Start for free</a>    </section>  );}
What the browser receives
<section>  <h1 data-cms="k3f9a1.0">Ship faster</h1>  <a data-cms="k3f9a1.2" data-cms-href="k3f9a1.1" href="/signup">    Start for free  </a></section>
02

A manifest remembers where everything lives

The same analysis produces a manifest: for every id, the file, the position and the text. It also lists the text that has no id because it reaches the page indirectly, from props, constants, translation files and Markdown.

In development it is computed on demand. For production it is written during the build and travels with your deployment, so the server never needs your source files.

.torso/manifest.json
{  "file": "components/hero.tsx",  "entries": [    { "id": "k3f9a1.0", "kind": "text", "line": 4, "text": "Ship faster" },    { "id": "k3f9a1.1", "kind": "href", "line": 5, "text": "/signup" },    { "id": "k3f9a1.2", "kind": "text", "line": 5, "text": "Start for free" }  ]}
03

The editor wraps your site from the outside

The edit URL serves a small page of its own: your real site in a frame, with the toolbar around it. The editor reaches into the frame, so your pages load no editor script and visitors never download one.

When you click, it looks up what is under the pointer in the manifest. There are three ways a piece of text can be recognised, and when none of them is certain the text simply stays read-only.

/edit

Your site, in a frame, unmodified

Ship faster

Start for free

1 unsaved changeSave
By id
Text written directly inside an HTML tag carries its id. The match is exact, even when the same words appear ten times on the page.
By value
Text that arrives through a prop, a constant, a translation file or Markdown has no id. It is matched by its words, preferring the file that rendered the element, and only when that leaves exactly one candidate.
By company
A number is only trusted when text from the same object sits beside it: a price inside the card that shows its plan’s name. A stray 3 elsewhere in your code can never claim a 3 on the page.
04

Saving is three checks, then a write

The browser sends only an id, the text you started from and the new text. It never sends a file path or file contents, so an editor cannot write anywhere the manifest does not point.

On your machine the component file is rewritten and the page refreshes in place. In production the same change becomes one commit on your branch, added on top of whatever is there. The branch is never force-moved.

  1. 1

    Is it still the same text?

    The edit names the text you started from. If the source says something else now, because a developer changed it, that edit is refused and nothing is written.

  2. 2

    Escape for where it lands

    JSX, a string, a template literal, JSON, YAML and Markdown each have their own rules. A brace typed into a heading becomes an entity, not an expression.

  3. 3

    Read it back

    The changed file is parsed again. Unless every edited string reads back exactly as typed, and nothing else moved, the file is not written.

Typing “Ship {much} faster” writes
      <h1>Ship &#123;much&#125; faster</h1>
05

Then your host does what it always does

A commit lands, your host rebuilds, and the new text is live. Until then the editor keeps showing what you saved, so a change never looks lost while the build runs.

That is the whole system. To see the checks run on real input, try the demos. To set it up, read the docs.

What never happens

  • Your pages never fetch content at request time. The words are in the build.
  • Visitors never download the editor, the manifest or a file path.
  • An edit never adds or removes an element. It replaces the inside of one string.
  • A save never overwrites a change it has not seen.