ident
All repositories: gitoria
30.9 KB
# hl:web — the web framework`hl:web` serves an app's pages from the server and keeps them live in the browser. It is writtenin Hybriel: `WebFramework.hl` is the server half, `client.hl` the browser half, and `compile.hl`turns each component's View into that component's own code. The model behind it (components,Views, realms, the boundary) is in [COMPONENTS.md](../../COMPONENTS.md). This page lists the rulesan app is held to. Each rule is a located refusal at boot unless it says otherwise.## Starting an app```hybrielimport WebFramework from 'hl:web'import Home from './components/home.hl'import Styles from './styles.hl'routes = [ { pattern = "/" component = Home } ]server = new WebFramework(routes = routes, styles = Styles, port = 8080)```Settings may be passed as named arguments. Most of them may instead be members of the file thatruns the `new`:| setting | default | meaning ||---|---|---|| `routes` | `[]` | the route table (below); pass it as an argument || `styles` | none | the app's styles file: the imported class, or a path string. It must be in the project graph || `port` | 8080 | the port to listen on || `host` | `HL_HOST`/`HOST`, else 0.0.0.0 | the interface to bind || `audience` | `{}` | per outward event, who receives it (see Events) || `minify` | false | one-line HTML and compact modules || `watchMode` | true | a saved `.hl` file re-analyses the app and reloads every open tab || `sessionDir` | `<app>/.sessions` | where sessions are stored; `false` keeps them in memory || `sessionMaxAge`, `sessionIdle`, `sweepInterval` | 14 days, 15 min, 5 min | the session clocks, in seconds || `sessionCookie` | `hlsid` | the cookie's name: letters, digits, `-` and `_` || `sessionSecure` | null | the cookie's `Secure` flag: null = set when the request came over https (this server speaks TLS, or `X-Forwarded-Proto: https`), true always, false never || `sessionAnonMax` | 10000 | the most sessions nobody logged in to; the oldest go first || `appTitle`, `appDescription`, `appImage`, `appFavicon`, `meta` | none | the head every page gets unless it declares its own || `links` | none | a list of hybrids, one `<link>` each in every page's head (`{ rel = 'preconnect' href = '…' }`) || `appIcons`, `appShortName`, `appThemeColor`, `appBackgroundColor`, `appTouchIcon`, `appManifest` | none | make the app installable: a web app manifest, linked from every head (see Offline and installable) || `offline` | none | the pages kept offline: a service worker, their state in IndexedDB, a queue for their emits || `pushKey` | none | the app's VAPID public key (base64url): serves the service worker with Web Push, and enables `subscribePush()` (see Web Push) || `pushPrivateKey`, `pushSubject` | none | the VAPID private key (base64url, the 32-byte scalar of `pushKey`) and a `mailto:`/`https://` contact: enable `sendPush()` (see Web Push). A key that is not `pushKey`'s other half is refused at boot || `pingEvery`, `pongWithin` | 25, 10 | the dead-socket clock, in seconds: the browser pings every `pingEvery`, and a pong missing after `pongWithin` closes the socket and reconnects || `renderCacheMax` | 64 | how many finished renders the render cache keeps (least recently used out first); 0 switches it off. A component opts in by declaring a `cacheKey` member (COMPONENTS §12, "A render kept per key") || `pageCacheMax` | 32 | how many keys the page cache keeps (a route that carries `pageKey`, COMPONENTS §12 "A page kept per key"); 0 switches it off || `pageCacheBytes` | 67108864 | the bytes of state and documents the page cache keeps together (least recently used key out first) || `uploadMax` | 64 MiB | the largest file an emit may carry, in bytes (see Files in an emit) || `uploadSessionMax`, `uploadHeldMax`, `emitMax` | 256 MiB, 1 GiB, 16 MiB | the bytes announced by one session's unfinished uploads, by all sessions', and the largest `POST /__hl/emit` body (413 past them). An accepted upload start makes a session when the visitor has none || `pageHeaders` | none | headers added to EVERY answer, over the safe defaults (see Security headers) || `trustedOrigins` | none | origins besides the request's own host allowed to emit, upload and open the socket || `pushKept`, `pushKeptBytes`, `tabKept` | 10000, 1 MiB, 600 | the push log per tab (see Events): the pushes kept for a socket that comes back, their bytes, and the seconds a tab without a socket is kept |An app runs on one web framework. If its files reach two packages that hold a `WebFramework.hl`(for example an old vendored copy beside this one), it is refused at boot, naming the import rowof each.## RoutesEach entry has a `pattern` (`/posts/:id`, `/assets/*`) and one kind:| kind | answers with ||---|---|| `component = Home` or `"./components/home.hl"` | the page, rendered on the server; the component must be imported by the app, and must declare a View || `function = (route, req) => { … }` | what the function returns (a Hybrid becomes JSON); `req.session` is the cookie's session, or null || `direct = "text"` | that text || `file = "./x"` | one file || `directory = "./assets"` | the files under a directory |A named group (`:id`) reaches the component as a construction argument of the same name: declare`id = null` at its root. A named wildcard does the same with the rest of the path:`/code/*path` gives `path = 'src/lib/util.hl'` for `/code/src/lib/util.hl`, on the first load andon a navigation. A bare `*` has no name a member could take; it is what a `directory` routeserves from.The request itself reaches a component the same way, and only one that declares the member(COMPONENTS.md): `session = null` gets the session, `host = null` the host without its port,`headers = null` the request's headers as a hash with lowercase names —`headers['accept-language']`. On a client navigation they are the headers of the request thenavigation crossed on, so they are still the browser's own: the socket's upgrade request, or the`POST /__hl/emit` under the fallback. `cookie`, `authorization` and `proxy-authorization` are leftout, because a member is state and state reaches page script.## ComponentsA component is a `.hl` file with a `View`. Its root members are its state, and are constructed onthe server for each request.**A View attribute is a literal, a member or a field path.** `href = "/"`, `href = url` and`href = p.url` are allowed. `href = '/posts/' + id` is refused at its line: declare`postUrl = '/posts/' + id` at the file's root and write `href = postUrl`. The same holds for avalue bound on a component reference (`Card { title = t }`) and for the condition of an `if` in aView, which may also be a `for` row variable.**An attribute name that is not an identifier is quoted.** `"aria-hidden" = "true"` and`"data-page" = it.target` render as written and bind like any attribute, in a `for` row too. AcamelCase name is not rewritten (`ariaHidden` renders as `ariaHidden`). `data-page = it.target`unquoted is refused at its line, naming the quoted form.**A bound attribute in a `for` row follows the row** on every update of the list: a new list, a`push`, an `upsert` and a write into a row's record (`items[0].title = …`) repaint it, as theyrepaint the row's text and class.**The tree carries the elements the HTML parser implies.** `table { tr { td { … } } }` is renderedas `table > tbody > tr > td`, because that is the tree the browser builds from the HTML, and thepage is continued from the tree the browser built. The pairs are listed in `view.hl`(`impliedElements`): `tr`, `td` and `th` under `table` get a `tbody`, `td` and `th` under `tbody`,`thead` or `tfoot` get a `tr`, and `col` gets a `colgroup`. Consecutive children that need the samecontainer share one.The other rules:- A View reads only names the file declares. A name it declares nowhere is refused.- `parent './main.hl'` wraps a page in a shell. The shell declares `slot = null` and places`slot` in its View exactly once. A component that is filled (`Card { p { … } }`) must declare aslot too.- **`$parent` is the page or component whose View placed this one** (hybriel#63). In a handler,`$parent.save(x)` calls a method of that host and `$parent.title` reads one of its members; writingthrough it is refused when the file is built. In the browser, hl:web hands the component the livehost instance (never a copy) when it builds it: when the page is hydrated, when a row or an `if`arm adds a component later, and after a client-side navigation. A page or shell has no host, so`$parent` there is an error when it runs. **Use it in handlers only for now:** the server buildsthe component for the first HTML without a host (the runtime's `hlLoad` takes no builder in therun form yet), so reading `$parent` in a member initializer or in the View fails the server'srender with "'$parent' has no owner".- `body { … }` is allowed only as the root of a View, and a page wrapped by a parent cannot haveone: the shell owns the body.- A View cannot render itself, directly or through other components.- A Style rule cannot be written on a component reference. Write it on an element inside thatcomponent.- A page's head comes from its members `__title`, `__description`, `__image`, `__favicon` and`__meta`, and falls back to the app's `appTitle`, `appDescription`, `appImage`, `appFavicon` and`meta`. A handler that writes one of them updates the document.## Events`on name(…)` handlers and `emit` statements cross between the browser and the server over aWebSocket on the app's own port. `POST /__hl/emit` is the fallback for a peer without a socket.A handler that takes `session` as its last parameter gets the connection's session from theserver, never from the peer. A handler may end its parameters with `request` (after `session`):`on server login(user, session, request)` gets `{ ip, headers, userAgent, https }` of the carrier, read-only —`ip` is `X-Client-IP`, else the first `X-Forwarded-For` hop, else the peer address (a WebSocket's upgrade carries none yet).Trust the proxy headers only behind a proxy that sets them.SESSIONS ARE LAZY: a visitor gets a session (id, file, cookie) only when something is stored in it — a login,`session.data`, an accepted upload start — so cookie-less requests cost nothing. Existing cookies (same name) andsession files keep working unchanged; logins never expire. Over a socket the ack carries a one-time token the pagetrades for the cookie at `POST /__hl/adopt`.THE COOKIE IS RE-ISSUED (W138). Every HTTP answer that resolves a signed-in session (a page, a function route, aPOST emit, an upload start) sends the session's `Set-Cookie` again when the cookie was never issued with the app'scurrent attributes (name, `Domain`, `Path`, `Secure`, `SameSite`: a short signature is kept in the session file) orwas last issued more than 24 hours ago. So an old host-only login moves onto the app's `sessionDomain` on its nextvisit, and a login with `sessionMaxAge` of 99 years stays inside Chrome's 400-day cap on a cookie's lifetime.Anonymous sessions are not refreshed, and a socket cannot set a cookie, so sockets are left alone.An outward event reaches the tab that caused it. To send it to other connections, give it an`audience` entry: a function of the event's arguments and the receiving connection's session thatanswers true or false.**No push is lost across a socket gap** (ticket #143). A push goes to the tab, not to itssocket: the server numbers every push to a tab and keeps the last `pushKept` of them (at most`pushKeptBytes`), also while the tab has no socket. The bytes bound is the one that governs: abusy server pushes hundreds of small frames in a few seconds, and a count bound below the bytes oneturns a short gap into a resync (#160). A tab whose socket comes back (a phonethat slept, a network switch, a socket the ping gave up on) names the last push it got inits `hello` and is sent the rest again, in order, each once. A gap longer than that log, atab gone longer than `tabKept` seconds, or a server that restarted resyncs the tab instead:the server mounts its shell and page again and sends the members it derives itself (thosethat call an imported class, and `session`), which the browser lays over the page. Thenevery mounted component that declares `on client reconnected(r)` gets`r = { how, missed, build, stale }`: `how` is `'replayed'` (nothing was lost; `missed` pushes came again)or `'resynced'` (a member only a push handler builds up may lack what was pushed meanwhile —ask the server for it here). `build` is the server's build and `stale` is true when it is notthe build this page was rendered by — the server restarted onto changed sources (ticket #152;in every mode, `watchMode` additionally reloads the tab itself). It fires once per reopenedsocket, never on the first.**A page shown again** (#174). Every mounted component that declares `on client shown(r)` gets`r = { persisted }` when the browser shows the page: on `pageshow` (`persisted` is true for a restorefrom the back/forward cache, false for the first show) and when `visibilitychange` makes the tabvisible (`persisted` false; turning hidden does not call it). An app re-plans here, without waitingfor the user's first touch.```hybrielon client reconnected(r) {if (r.stale) { location.reload() }if (r.how == 'resynced') { refresh() }}```A value-form emit (`answer = emit server ask()`) waits for one answer, so it has one answerer.If two files in the target realm answer the event, it is refused.**A write anywhere repaints what it wrote** (tickets #98, #99), from the compiler's writesets, never by watching the members:- A listener repaints what its handler writes when the handler is done. A handler stillwaiting after the task that started it (a network answer, `new Promise(…)`) has itswrite set painted then too, so what it wrote before the wait shows while it waits.- A function made inside a component — an `XMLHttpRequest`'s `onload` or `onprogress`, atimer, a Promise's executor, a `then` — is compiled so that every return of it isannounced with the site it was made at. What it writes (a member, a push into one, afield inside one, and what the methods it calls and the events it emits write) isrepainted after the task that ran it. A function that writes no member repaints nothing.- A repaint the listener already made in the same task is not made twice.**After a face that takes `session`** (tickets #121, #122), the server re-derives themembers that read `session` for the tabs that mounted the component, with the page's ownroute params, and ships them in the ack (`sync`); the browser takes them as writes.A server face's own writes (its declared members) travel as a separate numbered push `{ t: 'sync', n, sync: { <file>: { member: value } } }`to the emitting tab only, sent before the face's outward `emit client` frames and before the ack (COMPONENTS §10).- A member that reads `session` and calls an imported class, directly or through a localmethod or static, is computed on the server only and never re-derived in the browser.- Such a member is already up to date when the handler continues, so a client handler thatappends the face's returned row to a list derived from `session` shows it twice. Assignfrom what the sync brought, or leave the list to the sync.- A member derived from `session` that needs a server-only resource (a database) must reachit through an imported class or a static of one; a plain copy (`me = session.user.id`) isderived everywhere.### Files in an emitA browser `File` (an input's `ev.target.files[0]`, a dropped file) or a list of them(`ev.target.files`) may be an argument of an `emit server …`. It never rides the socket:before the emit goes out, the client half sends each file to `/__hl/upload` as its own HTTPrequests, with the page's session cookie, in parts of 1 MiB. The face gets the file in itsplace as `{ bytes, name, type, size }` (`bytes` a `Bytes`), or a list of those for a list:```hybrielinput { type = 'file' on change(ev) { emit send(ev) } }on send(ev) { saved = emit server saveFile(ev.target.files[0]) }on server saveFile(file) {writeFile('uploads/' + file.name, file.bytes)return file.size}```- **Progress.** While a file is sent, every mounted component that declares`on client uploadProgress(p)` gets `p = { event, index, name, sent, size }`: the emit'sevent, the file's position among the emit's files, its name, the bytes sent so far andits size.- **A dropped connection.** A part that did not come back is asked for again: the clientwaits (250 ms, doubling up to 4 s), asks the server how much of the file it has, and goeson from there. After 8 drops in a row it gives up.- **A failed upload ends the emit.** A file the server refuses (bigger than `uploadMax`, anupload of another session) or a connection that stays down ends the emit with that errorinstead of sending it — except a queueable emit in an offline app, which is queued with itsfiles when the connection is what failed (COMPONENTS §10): it gets the failed ack a failing face sends(`{ t: 'ack', i, ok: false, error }`), so a value-form emit answers null and the error islogged. The face does not run.- An upload belongs to the session that started it, and one emit takes it. An upload thatnothing takes within an hour is dropped. The parts are held in the server's memory untilthe emit takes them.## Offline and installableThe full model is [COMPONENTS.md §10](../../COMPONENTS.md). An app writes no JavaScript for anyof it.```hybrielappTitle = "Hybriel Notes"appIcons = [ { src = "/static/icon-192.png" sizes = "192x192" } { src = "/static/icon-512.png" sizes = "512x512" } ]offline = [ NoteList, NoteEditor ]```- `appIcons` (or `appManifest`, or `offline`) serves `/__hl/manifest.webmanifest` and links it,with an apple-touch-icon, from every page's head. `appManifest`'s entries are written over thegenerated manifest.- `offline` lists pages: route components, as classes or path strings. Anything else is refusedat its line. The framework generates the service worker and registers it. The shell and thelisted pages' documents are cached, and a navigation is network-first. What the server lastsaid about a listed page is kept in IndexedDB and shown over an older cached document. Astatement-form `emit server …` from a listed page that does not reach the server is queued andreplayed in order when the socket reopens. Each queued emit carries a stable id, and theserver runs it once: a replay whose ack was lost is answered again without running the handler(the last 200 ids per session are kept). A socket that goes silent without closing is noticedby the ping and reopened. A queued emit keeps its files: IndexedDB holds them with the entry,and they go up on the replay under the emit's id, once (COMPONENTS §10). A page thatdeclares `__hlQueued = 0` /`__hlQueue = []` shows the queue. A page that declares `__hlOnline = true` has it follow the browser'sconnection (`navigator.onLine`, and the online/offline events), so a View can say "you are offline".- `offlineFallback = Start` (a route component, class or path string, answered by a route with noparameter; needs `offline`) names a DATA-FREE page: the worker keeps its document once, fetched withoutcredentials, and shows it for any page it has nothing for while the network is down, instead of "Unavailableoffline". Not set: nothing changes. A page (kept or the fallback) that declares `__hlDataFree = true` is keptthe same way — its document is the anonymous one, and the browser keeps neither its state nor a queue for it.- `offlineFiles = ['/md-editor.js', '/vendor/lib.js']` (needs `offline`) lists the app's OWN file-route urls theworker precaches at install and serves cache-first offline (ticket #170). Exactly the urls listed: adirectory route is never kept as a tree, list each file you need. Not set: no extra file is kept.- Kept state is per component for a member no route parameter feeds (the same list at every url ofthe page), per url for the rest. A param page that was never loaded as a document is answered offlinewith a kept document of the same component, booted with the url's parameters.- What is kept belongs to the last user who was logged in. An expired or fresh anonymous sessionchanges nothing: that user's queue is held, and replays when the same user logs in again (the serverrefuses a replay made for another user). Another user logging in forgets the copy (state, queue and theworker's documents); an entry from before users were kept is dropped unsent. Aface that logs the session out forgets the copy by itself (the ack says whose session it is now);an app with its own logout calls `forgetOffline()` from `hl:web`.- In any app, an emit in flight when its socket closes is sent again with its id over the POSTfallback or the next socket, and answered there (ticket #107). A page being left(`beforeunload`, `pagehide`) reopens nothing and posts nothing.- **A failed answer after a give-up means "not run".** An emit that waits for a socket that stays closedends, at the give-up (`window.__hlGiveUp`, 120 s), with the failed answer (`null` for a value-form emit).The POST carrying it is aborted then, and the frame carries `by`, the give-up horizon in the *server's* clock(the time the server last told the page, in the clock frame after a hello or in a pong, plus the duration the page measured since, plusthe give-up; client and server clocks are never compared). A frame that reaches the server after `by` (a proxyheld it) is refused and run by no face, so the app that was told "failed" is never contradicted. The horizon isearly by at most one message latency, which can only refuse an emit the page was about to give up anyway.- `import { notify, notifyAt, notifyIn } from 'hl:web'` shows a notification now, or at a time while the pageis open. A closed app cannot be woken at a set time without a server push.## Web PushA reminder for a closed app is a server push the service worker shows. This is the browser half(ticket #173); the server's VAPID signature and payload encryption are `hl:crypto`'s.- `pushKey = '<base64url VAPID public key>'` (a `WebFramework` argument or a manifest member) servesthe service worker — also in an app with no `offline` (it then keeps nothing and answers every fetchfrom the network) — and tells the page the key.- The worker handles `push`: the payload is JSON text `{ "title", "body", "url", "tag", "icon" }`, shownwith `registration.showNotification` (a payload that is not JSON becomes the body, titled with thehost). On `notificationclick` it focuses an open window of the app, else opens `url` (default `/`).- `import { subscribePush } from 'hl:web'`: in a handler, asks for notification permission (on firstuse), registers the worker if the page has none, calls `pushManager.subscribe({ userVisibleOnly:true, applicationServerKey: pushKey })` and answers `{ endpoint, expirationTime, keys = { p256dh, auth } }`,or `null` (no push support, permission refused, no `pushKey`, subscribe failed — said in the console).The app hands it on with its own emit:```import { subscribePush } from 'hl:web'View { button { "Turn on notifications" on click(e) { let s = subscribePush() emit server savePush(s) } } }on server savePush(s) { /* store s.endpoint, s.keys.p256dh, s.keys.auth for this user and device */ }```### Sending a push (the server half)- `pushKey`, `pushPrivateKey` and `pushSubject` together enable `import { sendPush } from 'hl:web'`, called in an `on server`handler or a route function (in a component's browser build the name binds to a refusal, like any server-only name).- `sendPush(subscription, payload, opts)`: `subscription` is what `subscribePush()` gave (`endpoint`, `keys.p256dh`,`keys.auth`), as the app stored it; `payload` a String or Bytes up to 3993 bytes (the worker shows JSON text`{ title, body, url, tag, icon }`); `opts` = `{ ttl` (seconds, default 86400), `urgency` (`'very-low'`, `'low'`, `'normal'`,`'high'`), `topic` (up to 32 URL-safe characters) `}`. It signs a VAPID JWT (ES256, `aud` the endpoint's origin, 12 h), encryptsthe payload (RFC 8291 aes128gcm, one record) and POSTs it with hl:fetch.- It answers `{ ok, status, gone, error }`: `ok` is a 2xx (201 = accepted); `gone` is a 404/410, the subscription is dead andthe app drops it; `status` 0 with `error` is a malformed subscription, or a push service that cannot be reached (the latteronly where the caller has an `on Error(e)` handler — without one hl:fetch faults the call, as it does everywhere).- A call blocks its handler until the push service answers (15 s at most). A missing setting is a located error.## What it serves| url | what ||---|---|| `/<file key>` (e.g. `/components/home.hl`) | a component's browser module || `/__hl/hl-runtime.js` | the runtime every module imports || `/__hl/web/client.js` | this package's browser half (other packages' halves are at `/__hl/<name>/client.js`) || `/__hl/app.css` | the one stylesheet, built from the styles file and every component's `Style` || `/__hl/emit` | the POST fallback for emits || `/__hl/up` | an empty `204`: the probe a tab makes once a second while its socket waits to reconnect, so it is back within about a second of a restarted server (ticket #153; the backoff between socket attempts stops at 4 s) || `/__hl/manifest.webmanifest` | the web app manifest, for an installable app || `/__hl/sw.js`, `/__hl/web/worker.js` | the service worker's entry script and its compiled module, for an app with `offline` or `pushKey` || `/__hl/upload` | a file of an emit, in parts (`POST` `{ name, type, size, q, n }` → `{ id, have }`, or `{ handled }` when the session handled emit `q` already; `POST ?id=&at=` one part → `{ have }`; `GET ?id=` → `{ have }`) |The page loads the modules and the stylesheet as `<url>?v=<hash>`, where the hash covers everything the build serves. A url with the current hash is sent with `Cache-Control: public, max-age=31536000, immutable`, and any other url with `no-cache`. A deploy therefore changes every url, and a tab that navigates into a newer build loads that page as a full document.An app's own `file` and `directory` routes keep the same url across deploys, so they answer with an `ETag` of the content and `Cache-Control: no-cache` (a route's own `Cache-Control` header replaces that). A request whose `If-None-Match` names the current tag gets a `304` with no body.## Cloned row templates: measured, not adopted (ticket #68)Svelte clones one hoisted `<template>` per row or branch shape; hl:web builds a browser-created row element by element. Measured with `tests/browser/bench-web-rows.mjs` (headless Chrome, a clean page before every run, best of 5, ms, master c183052c):| case | ms ||---|---|| replace 1000 rows (li, 3 elements, an `if` inside) | 338 || append 10 x 100 rows (same row) | 780 || deep row, 20 elements x 300 rows | 7.5 || shallow row, 2 elements x 1000 rows | 14 || toggle an `if` branch 1000 times | 45 |DOM creation is not where the time goes: the CPU profile (`HL_BENCH_PROF=<case>`) puts `createElement`, `setAttribute` and `appendChild` together under 3% of the cheap cases and the dearer cases are bound by something else. A 20-element row costs 25 us per row in total, a 2-element row 14 us; cloning could not make either 1.2x faster, and the machinery that wires sites, events and marks onto a clone is the same code the walk runs today (a claim walk over the clone), so nothing is saved there either. No prototype was built: the bound from the profile is under 1.03x.What the profile does show: the 3-element row with an `if` costs 340 us, and 115 ms of its 340 is `rehome` -> `sitesOnto`, which scans the mount's WHOLE `m.sites` for every row built and copies each site it reads (value semantics), so a build of n rows is O(n x sites). The append case is worse (780 ms) for the same reason plus `updateRow` on the rows that stay. That is the cost to attack, not element creation.### The fix that followed (ticket #68, second step)`sitesOnto` now reads `m.sites` from the end, stops at the first site older than the walk's, and writes `el` in place instead of copying each site. `rebindRow` decides once per row body whether it composes a child (nothing to take again if not) instead of copying the seed's tree for every row that stays, and `rowPaint` reads its paint entry in place (`paintEntry`) instead of copying the compiled table. Same bench, old (c183052c) vs new, best of 5, ms:| case | old | new | ratio ||---|---|---|---|| replace 1000 rows | 342.0 | 20.0 | 17.1x || append 10 x 100 rows | 782.3 | 92.6 | 8.5x || deep row 20 el x 300 | 8.4 | 7.6 | 1.1x || shallow row 2 el x 1000 | 18.2 | 13.1 | 1.4x || toggle if-branch x 1000 | 48.8 | 40.2 | 1.2x (noise: 0.98x to 1.2x across runs) |Typing in a routger chat (a copy of the app, 30 keystrokes, main-thread time) is unchanged at about 1.5 ms per key: a keystroke builds no rows. Gates: `HL_WEB_STRICT=1` framework browser test 398 ok, `tests/core-ast/web-tickets.mjs` 205 ok.## Session rotation (W120)`session.rotate()` in a face that logs a session in (the handler takes `session`) mints a new session id when it returns,moves user/data/handled to it and deletes the old id (a planted cookie is anonymous). The REST carrier answers with`Set-Cookie`; over the socket the server pushes `{ t: 'rotate', token }` and the client POSTs `/__hl/rotate` (Origin-checked,one-shot token + the current cookie), whose answer sets the cookie. All live tabs of the session follow. See COMPONENTS.md.## Security headers and cross-site requestsEvery answer carries `X-Content-Type-Options: nosniff`, `Referrer-Policy: strict-origin-when-cross-origin`,`X-Frame-Options: SAMEORIGIN` and `Content-Security-Policy: frame-ancestors 'self'` — pages, the 404, `/__hl/*`and the app's own routes. A header a route sets itself is left alone. The app adds or replaces any of them(and a script CSP, which is not a default because it would break apps) with `pageHeaders`; `null` removes one:```hybrielpageHeaders = { 'Content-Security-Policy' = "default-src 'self'" 'X-Frame-Options' = null }````POST /__hl/emit`, `/__hl/upload` and the WebSocket upgrade refuse a cross-site caller: `Sec-Fetch-Site: cross-site`,or an `Origin` that is not the request's `Host` (or `X-Forwarded-Host`) nor listed in `trustedOrigins`. The first twoanswer 403; a socket is closed straight after its handshake. A request with no `Origin` (curl, another server) passes.**Behind a proxy on a non-443 port** (W123): nginx's `proxy_set_header Host $host;` drops the port while the browser's`Origin` keeps it (`https://h:8443` vs `Host: h`). A `Host` (or `X-Forwarded-Host`) WITHOUT a port is compared with theOrigin by hostname only (cookies are not port-scoped); with a port it must match exactly, and an `X-Forwarded-Port`completes a portless one. Prefer `proxy_set_header Host $http_host;` (keeps the port), or send `X-Forwarded-Host` /`X-Forwarded-Port`; otherwise list the origin in `trustedOrigins`. A refused socket or emit logs one console warningnaming Origin vs Host, and the client backs off (the reconnect delay resets only when the server answers a frame).
Branches
Latest commits
- ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
- dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
- d277633cident#27: README: identity access and the introspect endpointmre
- e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
- 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
- a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
- d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
- ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
- 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
- c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
- 80965c08ident#28: README says the deploy goes through the standbymre
- 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
- a544b261ident#28: README names the new vendored Hybrielmre
- 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
- 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
- f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre
- d8be66ebident: report and log line for the widget cache and frame height changemre
- 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre
- a22d2daaident#31: the sign-in frame is no taller than the tallest step needs (plain CSS height per width), gate check for itmre
- a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemre