CI / verify (pull_request) Successful in 1m7s
CI / infrastructure-smoke (pull_request) Successful in 34s
CI / package-release (pull_request) Successful in 49s
CI / migration-smoke (pull_request) Successful in 2m17s
CI / image-build (pull_request) Successful in 1m10s
CI / deploy-smoke (same-origin) (pull_request) Successful in 45s
CI / package-publication (pull_request) Successful in 57s
CI / deploy-smoke (split) (pull_request) Successful in 2m37s
The Dashboard had one address. The API served the page only at `/`, both reference proxies forwarded only `/`, and the open module lived in React state, so a refresh went back to the first module, nothing could be bookmarked, and Back left the Dashboard (DESIGN.md §2.7). ADR 0057 makes the address bar the source of truth: - `/` is a host-owned Overview, now the landing page; `/modules/<id>` mounts that module. An id the server's navigation does not list shows "This page isn't available" and loads nothing; any other Dashboard address is a host-owned "Page not found". - `/modules`, `/settings`, and `/account` are reserved whole, from one list (`@ekklesia/shell/dashboard-routes`) that the shell's router and the API's page routes both read. The API serves the same frozen page, ETag, and security headers anywhere inside them; look-alikes and other methods stay the sanitized 404. - A small host-owned history replaces the selected-module state, built in the entry point so it stays the only file touching `window`. Navigation items are real links; modified clicks are left to the browser. Focus moves to the page after an in-place change, and the tab is named after the page. - Sign-in still happens in place with no return value (ADR 0034), so a deep link opens its own page after sign-in. - Both reference Caddyfiles forward the new paths; the deploy smoke now reloads a module's address through the real proxy and requires it to mount again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
129 lines
4.3 KiB
TypeScript
129 lines
4.3 KiB
TypeScript
/**
|
|
* The shell's one view of the address bar (ADR 0057).
|
|
*
|
|
* The Dashboard's URL is the source of truth for which page is open: a refresh, a bookmark, and the
|
|
* browser's Back and Forward buttons all have to land on the same page that was showing. Everything
|
|
* in the shell reads the current path and moves between pages through this small interface rather
|
|
* than through `window.history`, for two reasons. It keeps the entry point the only file in this
|
|
* package that touches a browser global — the browser implementation is handed the window's pieces,
|
|
* it does not reach for them. And it lets every routing behaviour be tested against an in-memory
|
|
* history whose entries a test can inspect.
|
|
*
|
|
* Deliberately not a routing library. The shell's pages are a handful of host-owned screens plus one
|
|
* mounted module, and `react-router-dom` is refused to modules precisely because routing belongs to
|
|
* the host (ADR 0026); adopting it here would prejudge how a module's own pages are addressed, which
|
|
* a later decision owns.
|
|
*/
|
|
export interface HostHistory {
|
|
/** The current path, without query or fragment. */
|
|
pathname(): string;
|
|
/** Opens a new page, adding a history entry. Opening the page already showing adds none. */
|
|
push(path: string): void;
|
|
/** Corrects the current entry in place, adding none — for a non-canonical spelling of the same
|
|
* page. */
|
|
replace(path: string): void;
|
|
/** Notifies after every change, whether made here or by the browser's Back and Forward. */
|
|
subscribe(listener: () => void): () => void;
|
|
}
|
|
|
|
/** The parts of a `Window` the browser history needs, passed in by the entry point. */
|
|
export interface HostHistoryWindow {
|
|
readonly location: Pick<Location, "pathname">;
|
|
readonly history: Pick<History, "pushState" | "replaceState">;
|
|
addEventListener(type: "popstate", listener: () => void): void;
|
|
removeEventListener(type: "popstate", listener: () => void): void;
|
|
}
|
|
|
|
/**
|
|
* The address bar itself. `pushState` and `replaceState` fire no event of their own, so this
|
|
* notifies its subscribers after each one; `popstate` covers Back and Forward.
|
|
*/
|
|
export function createBrowserHostHistory(view: HostHistoryWindow): HostHistory {
|
|
const listeners = new Set<() => void>();
|
|
const notify = (): void => {
|
|
for (const listener of [...listeners]) {
|
|
listener();
|
|
}
|
|
};
|
|
return {
|
|
pathname: () => view.location.pathname,
|
|
push(path) {
|
|
if (path === view.location.pathname) {
|
|
return;
|
|
}
|
|
view.history.pushState(null, "", path);
|
|
notify();
|
|
},
|
|
replace(path) {
|
|
view.history.replaceState(null, "", path);
|
|
notify();
|
|
},
|
|
subscribe(listener) {
|
|
if (listeners.size === 0) {
|
|
view.addEventListener("popstate", notify);
|
|
}
|
|
listeners.add(listener);
|
|
return () => {
|
|
listeners.delete(listener);
|
|
if (listeners.size === 0) {
|
|
view.removeEventListener("popstate", notify);
|
|
}
|
|
};
|
|
},
|
|
};
|
|
}
|
|
|
|
/** An in-memory history with the same semantics, whose entries a caller can inspect and step
|
|
* through. Used by tests; production always uses {@link createBrowserHostHistory}. */
|
|
export interface MemoryHostHistory extends HostHistory {
|
|
readonly entries: readonly string[];
|
|
readonly index: number;
|
|
/** Steps like the browser's Back (`-1`) and Forward (`1`) buttons. */
|
|
go(delta: number): void;
|
|
}
|
|
|
|
export function createMemoryHostHistory(initialPath = "/"): MemoryHostHistory {
|
|
const entries: string[] = [initialPath];
|
|
let index = 0;
|
|
const listeners = new Set<() => void>();
|
|
const notify = (): void => {
|
|
for (const listener of [...listeners]) {
|
|
listener();
|
|
}
|
|
};
|
|
return {
|
|
get entries() {
|
|
return [...entries];
|
|
},
|
|
get index() {
|
|
return index;
|
|
},
|
|
pathname: () => entries[index] ?? "/",
|
|
push(path) {
|
|
if (path === entries[index]) {
|
|
return;
|
|
}
|
|
entries.splice(index + 1, entries.length, path);
|
|
index = entries.length - 1;
|
|
notify();
|
|
},
|
|
replace(path) {
|
|
entries[index] = path;
|
|
notify();
|
|
},
|
|
go(delta) {
|
|
const next = Math.min(Math.max(index + delta, 0), entries.length - 1);
|
|
if (next !== index) {
|
|
index = next;
|
|
notify();
|
|
}
|
|
},
|
|
subscribe(listener) {
|
|
listeners.add(listener);
|
|
return () => {
|
|
listeners.delete(listener);
|
|
};
|
|
},
|
|
};
|
|
}
|