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)