Guide

Resuming

The browser does not run view code to start the page. The server sends the HTML, the model and a small listener. A click loads the handler it names and the binding chunks of the model paths that changed. The sizes on this page come from the site's build of examples/todo: pnpm --filter website build measures them into website/dist/demo-server/demo.json. Raw is the size as served, and gzip is zlib level 9 of the same bytes. The build fills the numbers, so a change to the loader or the compiler changes them with no edit here.

#What the server sends

The server render of idlip/server writes plain markup with data attributes. The second todo of the app from Getting started renders as follows, with line breaks added:

html
<li i-a="4">
  <input type="checkbox" on:click="$e3" i-a="5" />
  <!--t6-->Write a component<!--/t-->
</li>

The <head> holds two scripts:

#Before the first event

The page loads the document and the loader, and nothing else. The state is not decoded yet.

Request Raw gzip
GET / (document) 5099 B 2136 B
GET /assets/loader.<hash>.js 10086 B 4030 B
Total 15185 B 6166 B

The e2e test records every request from the navigation on, and fails if any other request appears. Moving the pointer and focusing an element are not handled events and load nothing.

#The first click

A click on the second checkbox runs these steps:

  1. The listener reads $e3 from the checkbox and queues the event with the element. It sends no message yet.
  2. The loader decodes the state script, once for the page.
  3. The loader imports the toggle handler chunk, and with it the helpers module the chunks share. The chunk exports the function $e3 of the click, which reads the row the user clicked and returns the message toggle("a2"). The loader runs the handler on the model. The result is the next model.
  4. The manifest says toggle writes todos.*.done. The loader imports the binding chunk of that path only. It asks for all three files before any arrives, so the click costs one round trip.
  5. The binding chunk patches the checkbox, the done class of the row and the 0 left count, since countLeft(todos) reads todos.*.done.

The checkbox names an event function whose message runs the handler, which writes todos.*.done, and the binding of that path changes the row and the count.

The click makes three requests:

Request Raw gzip
GET /assets/todo.handler.toggle.<hash>.js 264 B 213 B
GET /assets/_idlip-helpers.<hash>.js 2877 B 1361 B
GET /assets/todo.binding.todos._.done.<hash>.js 469 B 289 B
Total 3610 B 1863 B

A built chunk file is named <module>.<kind>.<name>.<hash>.js, and a _ segment stands for * in the path. _idlip-helpers.<hash>.js holds the DOM and render helpers every chunk of the build imports. It loads once, with the first chunks. The bindings of todos.*.text, todos.*.id and draft, the list chunk and the other three handlers stay on the server.

A second click on any checkbox loads nothing. The chunks are already in the page, and the state was decoded once.

#Write sets

The compiler reads each handler and lists the model paths it writes. The loader loads the binding chunks of those paths. For the todo app:

Handler Writes Binding chunks loaded
setDraft draft draft
clear draft draft
toggle todos.*.done todos.*.done
add todos, next, draft todos.*.done, todos.*.id, todos.*.text, draft

toggle maps over todos and changes only done, so its write set is todos.*.done and not all of todos.

#A click before the scripts load

The listener is inline in <head>, so it runs before the loader arrives. A click while the loader is still on the network goes into the queue. When the loader starts, it runs the queued messages in order. The e2e test holds every script request, clicks, and then checks that the page updates once the scripts load.

#Preload the first click

The first click waits for one round trip to fetch its chunks. renderToResponse writes <link rel="modulepreload"> tags for the chunks of the first click. The same tags come from renderPreload(page.chunks, page.manifests) from idlip/server, with the result of render, which returns <link rel="modulepreload"> tags for the chunks of the first click, so the browser fetches them with the page. For the todo page it names the shared helpers module, the toggle handler and the todos.*.done binding.