From 6760fcc2eb53e28aff35b92c5c8fa4b926cd3b02 Mon Sep 17 00:00:00 2001 From: karitham Date: Tue, 24 Nov 2026 20:22:40 +0100 Subject: [PATCH] web: park a board's windows before it goes Switching boards put every chat at the top of its conversation. Svelte takes the outgoing board view, and the slots inside it, out of the page in the same flush that swaps boards, so `release` found each window host already disconnected and moved it into the parking with a plain append. Chrome clamps a scroller that leaves the page to its top, so the offset was gone before `release` could save it. `boards.active` now parks the board being left while its windows are still in the page: `hosts.shelter(id, false)` hides them with their last size and leaves them parked instead of putting them back into slots that are about to go. Turning `active` into an accessor catches every switch, including the tabs' own assignments. --- robot-docs/web.md | 15 ++++++++++----- web/src/lib/boards.svelte.ts | 17 ++++++++++++++++- web/src/lib/tiles/hosts.ts | 8 +++++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/robot-docs/web.md b/robot-docs/web.md index 2b57dc42e..180674767 100644 --- a/robot-docs/web.md +++ b/robot-docs/web.md @@ -450,11 +450,16 @@ Settings → Layout) recently visited open boards parked in its off-screen switches instead of unmounting them. Chats, scroll offsets, iframes, and WebGL terminals survive board switches and reattach with `moveBefore`; closing a window, closing a board tab, or deleting a board drops them so `#collect` -unmounts them on the next frame. A parked host also carries its own -`visibility: hidden`, cleared after it moves back into a slot. Without that, -Chrome can keep the parking's inherited `visibility: hidden` on a host that -`moveBefore` returns to its slot, and the window stays invisible. Hosted windows -read their owning board via `windowBoard()` in +unmounts them on the next frame. The board being left is parked before it goes: +the setter of `boards.active` calls `hosts.shelter(id, false)`, because Svelte +takes the board view, and every slot in it, out of the page in the same flush, +and Chrome clamps a scroller carried out of the page that way to its top before +`release` can park it. `shelter`'s `back` false keeps those windows parked +instead of putting them back into slots that are about to go. A parked host also +carries its own `visibility: hidden`, cleared after it moves back into a slot. +Without that, Chrome can keep the parking's inherited `visibility: hidden` on a +host that `moveBefore` returns to its slot, and the window stays invisible. +Hosted windows read their owning board via `windowBoard()` in [`boards.svelte.ts`](../web/src/lib/boards.svelte.ts) (`BOARD_CONTEXT` set in [`WindowSlot.svelte`](../web/src/lib/tiles/WindowSlot.svelte)) rather than `boards.board`, so parked windows stay isolated from the active board. diff --git a/web/src/lib/boards.svelte.ts b/web/src/lib/boards.svelte.ts index 1d1bfd14d..da3d659aa 100644 --- a/web/src/lib/boards.svelte.ts +++ b/web/src/lib/boards.svelte.ts @@ -37,10 +37,25 @@ function forgetEarlierLayouts() { class Boards { #boards = new Map(); entries = $state.raw([]); - active = $state(null); + #active = $state(null); /** The tab whose name is being edited. */ renaming = $state(null); tabs = $derived(this.entries.filter((entry) => entry.open)); + /** + * The board on screen. Leaving one parks its windows out of sight first, + * while they are still in the page: the board view showing them is destroyed + * a moment later, and a window carried out of the page inside its slot loses + * what it held (a chat its scroll, a frame its page) before `release` could + * park it. Every way a board changes is this one. + */ + get active() { + return this.#active; + } + set active(id: string | null) { + const leaving = this.#active; + if (leaving && id !== leaving) hosts.shelter(leaving, false); + this.#active = id; + } closed = $derived(this.entries.filter((entry) => !entry.open)); board = $derived( this.active ? (this.#boards.get(this.active) ?? null) : null, diff --git a/web/src/lib/tiles/hosts.ts b/web/src/lib/tiles/hosts.ts index a9889e24e..ab6451d6e 100644 --- a/web/src/lib/tiles/hosts.ts +++ b/web/src/lib/tiles/hosts.ts @@ -126,8 +126,13 @@ class Hosts { * Parks the windows of `board` before a layout change rebuilds their slots, * and puts each one whose slot stayed back once it is done. Only where moves * keep a window's state; elsewhere a park would cost what it saves. + * + * `back` false leaves them all parked: the board itself is leaving the page, + * and a window taken out of it with its slot loses its scroll — Chrome + * clamps a scroller that is no longer rendered — before `release` could park + * it. Only a park while the window is still in the page saves where it was. */ - shelter(board: string) { + shelter(board: string, back = true) { if (!movable) return; const parked = [...this.#entries] .filter( @@ -146,6 +151,7 @@ class Hosts { this.#hide(entry.host); }); this.#settle(); + if (!back) return; queueMicrotask(() => { for (const entry of parked) { if (!entry.slot?.isConnected || entry.host.parentElement === entry.slot) -- knotmirror 0.0.1