Member itx: an owed reload is the person's, where the page can say it #14
merged no-auto-reload-2 was squashed into main as d1184ed by jonas, 2026-11-28 11:19 UTC. jonas opened it 2026-11-28 11:19 UTC.
After a cut socket, a page where nothing subscribes to the session was reloaded when the next session opened. Now the window gets the cancelable event `iterate:reload-owed` with the words; a page that shows them (a mind's live-reload.js badge) cancels it, and then nothing reloads and `root` is not written over. A page where nothing cancels it is reloaded as before. The end of the sign-in still reloads. Card: tasks/show-an-updated-badge-instead-of-reloading-app-pages-on-publish.md. Checks: `pnpm check` on 1024aa1 (115 files, 1266 tests) passed. Via: /agents/claude/no-auto-reload-2-mx0bd0ks-5977e9 Session: claude d8055970-f827-4410-a60f-a1cfb249061e on beelink 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01F4yAt8eDQZEzgkoSHhuVNJ
Conversation
Nobody has said anything yet.
Sign in to comment or to merge.
Files
2 files changed
M src/browser/member-itx.test.tsx
@@ -10,7 +10,7 @@ import { IDBFactory } from "fake-indexeddb"; import { BotIcon } from "lucide-react"; import { useContextStub, useIterateContext } from "iterate/react"; -import { connectMemberItx, mayReload } from "./member-itx.ts"; +import { connectMemberItx, mayReload, RELOAD_OWED } from "./member-itx.ts"; import { DashAgents } from "#/agent-kind-view/dash-agents.tsx"; import { DashContexts } from "#/components/dash/dash.tsx"; import { AppShell } from "#/components/app-shell.tsx"; @@ -206,7 +206,7 @@ expect(reload).not.toHaveBeenCalled(); }); -test("a page that does not read its session says that the mind cannot be reached, and is reloaded when the next session opens", async () => { +test("a page that does not read its session, and where nothing says an owed reload, says that the mind cannot be reached, and is reloaded when the next session opens", async () => { using _clock = clock(); const net = network(); net.up = false; @@ -242,6 +242,42 @@ net.drop(1006); await itx.whoami(); expect(reload).toHaveBeenCalledTimes(1); +}); + +test("a page that says an owed reload itself is never reloaded and keeps what it drew: after a cut it goes on with the new session", async () => { + using _clock = clock(); + const net = network(); + const root = { textContent: "the app, with a draft" }; + const reload = vi.fn(); + // as a mind's live-reload.js: it shows the words in a badge, and cancels the event + const said: string[] = []; + const badge = (event: Event) => { + said.push((event as CustomEvent<{ words: string }>).detail.words); + event.preventDefault(); + }; + window.addEventListener(RELOAD_OWED, badge); + onTestFinished(() => window.removeEventListener(RELOAD_OWED, badge)); + const itx = connectMemberItx({ root, url: new URL("ws://dash.example.com/itx"), reload, ...net }); + const session = itxSessionOf(itx); + session.watch(() => {}); + await itx.whoami(); + expect(said).toEqual([]); + // a deploy's cut: the next session opens, and the page is told once that a reload is owed + net.drop(1006); + expect(await itx.whoami()).toMatchObject({ principal: { actor: "/members/a" } }); + expect(said).toEqual(["Disconnected. Tap to reload"]); + expect(session.get()).toEqual({ epoch: 2, state: "open" }); + // an outage: the page is told, and `root` is not written over + net.up = false; + net.drop(1006); + await vi.advanceTimersByTimeAsync(15_750); + expect(said.at(-1)).toBe("Cannot reach the mind. Trying again…"); + net.up = true; + await vi.advanceTimersByTimeAsync(15_000); + expect(said.at(-1)).toBe("Disconnected. Tap to reload"); + expect(session.get()).toMatchObject({ state: "open" }); + expect(root).toEqual({ textContent: "the app, with a draft" }); + expect(reload).not.toHaveBeenCalled(); }); test("a sign-in that ended while no session was open: an outage alone reloads nothing, and when the host answers 401 over HTTP the page reloads and dials no more", async () => {
M src/browser/member-itx.ts
@@ -36,8 +36,16 @@ // once. // - A page where nothing subscribes to the session cannot open its stubs again: an app that // has not drawn yet, whose first call was refused, or one that holds its stubs with the SDK's -// hooks alone. That page is reloaded when the next session opens, and says so in `root` +// hooks alone. That page needs a reload when the next session opens, and says so in `root` // meanwhile. The mark only watches: it does not make a page one that lives on. +// - THAT RELOAD IS THE PERSON'S, WHERE THE PAGE CAN SAY THAT IT IS OWED (Jonas, 28 Nov 2026: +// "we cannot have apps reload. […] just pop up something in the corner that says this app has +// been updated. Tap here to reload"). The window gets the event `RELOAD_OWED`, with the words +// in its `detail`. A page that shows them (a mind's live-reload.js: a badge in a corner, and a +// tap reloads) cancels the event. Then nothing reloads and `root` keeps what the page drew: +// what a person wrote there stays, a new call goes through the new session, and only what +// the page held of the old one is still. A page where nothing cancels the event is reloaded, +// or gets the words in `root`, as before. // - THE FIRST SOCKET CAN BE DIALLED BEFORE THIS MODULE HAS LOADED. A page's HTML dials it in one // inline line of its head, under the name `EARLY_ITX_SOCKET`, and `memberItx` takes it for // its first session while it is connecting or open: @@ -73,6 +81,11 @@ * `memberItx` to take. */ export const EARLY_ITX_SOCKET = "__itxSocket"; +/** The window's event that says a reload is owed: `detail.words` is what to tell the person. It + * can be cancelled, and the listener that shows the words cancels it (`preventDefault()`): the + * page is then left as it is, and the person reloads it. */ +export const RELOAD_OWED = "iterate:reload-owed"; + /** The member's itx. `root` is where the page says what a reload would mend: that the mind * cannot be reached, for a page that does not read its session, and that the sign-in ended, * when the reloads did not reach the sign-in. */ @@ -92,6 +105,8 @@ early, fetch: ask = (input, init) => fetch(input, init), reload = () => location.reload(), + owe = (words) => + !dispatchEvent(new CustomEvent(RELOAD_OWED, { cancelable: true, detail: { words } })), }: { root: Pick<HTMLElement, "textContent"> | null; url?: URL; @@ -100,6 +115,9 @@ early?: WebSocket; fetch?: typeof fetch; reload?: () => void; + /** Tell the page that a reload is owed, with the words for the person. True when the page + * shows them: it is then neither reloaded nor written over. */ + owe?: (words: string) => boolean; }): Itx { let connection: ItxConnection = { epoch: 0, state: "opening" }; const readers = new Set<() => void>(); @@ -175,7 +193,10 @@ good = true; clearTimeout(proving); clearTimeout(quiet); - if (ended && unread()) return reloadOrSay("Disconnected. Reload the page to connect."); + // what the page held of the session before is still: a reload mends it, the person's own + // where the page can say so, and then the page goes on with the new session + if (ended && unread() && !owe("Disconnected. Tap to reload")) + return reloadOrSay("Disconnected. Reload the page to connect."); publish({ epoch: connection.epoch, state: "open" }); }; // the proof is the session's first call, so it is answered before any call of the page @@ -206,7 +227,8 @@ // the host says over HTTP that the sign-in ended void askWhetherSignedIn(); clearTimeout(quiet); - if (unread() && root) root.textContent = "Cannot reach the mind. Trying again…"; + if (unread() && !owe("Cannot reach the mind. Trying again…") && root) + root.textContent = "Cannot reach the mind. Trying again…"; if (connection.state !== "unreachable") publish({ epoch: connection.epoch, state: "unreachable" }); start([SLOW_WAIT_MS]);