What a server sends

2 min·Assumes: state, events

When a server renders a page, it sends finished HTML plus a small
of data, so the browser can carry on without running your components.
import { state } from '@markless/core';

export default function Calendar() @{
	let day = state(13);

	<p>Booked: March {day}</p>
}

<p>Booked: March 13</p> arrives as plain HTML. day arrives as data, so the browser knows 13 is a value that can change.

The page is real HTML

The page and its View Source share colours. Hover one, then press a day:

March

Booked: March 13

Network

calendardocument

chunk-….jsclick code

no code yet

View Source

<section>  <h2>March</h2>  <p>Booked: March 13</p>  <button m:on="click:0">13</button> …</section><script type="markless/state">  {"cells":[{"graphNodeId":"state:day", … "root":13 …}]}</script><script type="markless/view">  {"events":[{"hostNodeId":"h3", … ["symbol:0"]}, …],   "domUpdates":[{"hostNodeId":"h2", … "state:day"} …]}</script>
A calendar page for March, with the line Booked: March 13 and three day buttons, beside its View Source. The source is the HTML the server sent: the heading, the Booked line and a button with an m:on attribute, then two data blocks. markless/state holds the values, state:day is 13. markless/view says who does what: element h3's click runs symbol:0, and element h2 shows state:day. The Booked line, its value and its view entry share one colour; the day buttons and their event share another; the heading is plain HTML. Press a day: only then does one small chunk of click code appear in the network panel.

A calendar beside its View Source: real HTML, plus two small data blocks, markless/state and markless/view.

  • Every element is plain HTML, so the page shows in full before any code runs.
  • An element with a handler carries m:on, naming its handler's record.
  • The first click fetches one small chunk of click code. The data itself never runs.

The two blocks are data

Everything the server adds to your HTML is the payload. It's two script tags that hold JSON, not code:

  • markless/state holds the values: state:day is 13.
  • markless/view says which element does what: the paragraph shows state:day, and each button's click runs its own symbol.

Here is the real response of renderToString() for the full calendar, laid out across lines, with the inline scripts, file names and some fields cut to …:

<link rel="modulepreload" href="/build/chunk-….js"
  crossorigin="anonymous" fetchpriority="high">
<script>…</script>
<div data-async-container data-markless-paths="…">
  <section>
    <h2>March</h2>
    <p>Booked: March 13</p>
    <button m:on="click:0">13</button>
    <button m:on="click:1">14</button>
    <button m:on="click:2">15</button>
  </section>
  <script type="markless/state">
    {
      "version": 1,
      "cells": [
        {
          "graphNodeId": "state:day",
          "name": "day",
          "value": { "version": 1, "root": 13, "records": [] },
          …
        }
      ],
      …
    }
  </script>
  <script type="markless/view">
    {
      "version": 1,
      "events": [
        {
          "hostNodeId": "h3",
          "eventName": "click",
          "symbolIds": ["symbol:0"]
        },
        …
      ],
      "domUpdates": [
        {
          "hostNodeId": "h2",
          "graphNodeId": "state:day",
          "symbolId": "symbol:3",
          …
        }
      ],
      …
    }
  </script>
  <script data-async-resumer
    data-markless-resume-module="/build/chunk-….js">…</script>
</div>

Only pages that can react get a payload

  • Values must be data, so a function can't be sent this way.
  • A page with nothing to react to gets no scripts at all, just <div data-async-container> and its HTML.
  • In the browser alone, render() keeps the same records in memory and writes none of these scripts.

Resuming shows what the browser does with them on the first press.