chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.0 Latest 5 packages
0
0
Shell test: a back supersedes the shell's move still settling
web/shell/test/history.svelte.ts+11−4
| @@ -3,9 +3,12 @@ | ||
// screen (`here`) reactive, as SvelteKit's `page.state` is, so the shell | ||
// sees an entry gone back or forward to. As SvelteKit's router does, an | ||
// entry is made a moment after it is asked for, and `here` is set only once | ||
// its move settles, later still. `entered` runs as the shell | ||
// starts, as a page hydrated; a page loaded again is a new `History` | ||
// holding the entries, at the one it was on. | ||
// its move settles, later still. A back or forward meanwhile comes after | ||
// that move, as a browser's does (SvelteKit sets `page.state` before the | ||
// task that made the entry ends; a back is a task of its own), so the move | ||
// sets no `here`: it is the entry's the browser went to, never one it left. | ||
// `entered` runs as the shell starts, as a page hydrated; a page loaded | ||
// again is a new `History` holding the entries, at the one it was on. | ||
| ||
type Entry = { url: string; state: unknown; replace: boolean }; | ||
| ||
| @@ -13,6 +16,8 @@ export class History { | ||
readonly entries: Entry[]; | ||
at: number; | ||
here: unknown = $state(undefined); | ||
/** How many times the browser has gone back or forward: a move settling meanwhile sets no `here`. */ | ||
private went = 0; | ||
/** The router's history as the shell takes it (`Navigation`). */ | ||
readonly navigation; | ||
| ||
| @@ -30,10 +35,11 @@ export class History { | ||
await Promise.resolve(); | ||
if (replace && self.at >= 0) self.entries[self.at] = entry; | ||
else self.entries.splice(++self.at, Infinity, entry); | ||
const went = self.went; | ||
const { promise, resolve } = Promise.withResolvers<void>(); | ||
setTimeout(resolve); | ||
await promise; | ||
self.here = entry.state; | ||
if (self.went === went) self.here = entry.state; | ||
}, | ||
entered: (run: () => void) => queueMicrotask(run) | ||
}; | ||
| @@ -41,6 +47,7 @@ export class History { | ||
| ||
/** The browser's back (`by` -1), or forward (1). */ | ||
go(by: number) { | ||
this.went++; | ||
this.at += by; | ||
this.here = this.entries[this.at].state; | ||
} | ||