Files
nanobot/webui/src/components/thread/session-transition.ts
T
chengyongru ce3f36983d feat(webui): stabilize session transitions and goal presentation
Keep the composer stable during interruptible session changes. Move active and blocked goals into the header with localized gallery previews, and preserve focus when overlays close. Include the reviewed navigation, layout and accessibility fixes.
2026-11-13 23:37:07 +08:00

47 lines
1.3 KiB
TypeScript

import { flushSync } from "react-dom";
import "./session-transition.css";
let active: ViewTransition | null = null;
let pending: (() => void) | null = null;
export function finishSessionTransition(): void {
const update = pending;
pending = null;
active?.skipTransition();
active = null;
delete document.documentElement.dataset.sessionTransition;
if (update) flushSync(update);
}
export function transitionSession(update: () => void, animate = true): void {
pending = update;
active?.skipTransition();
const root = document.documentElement;
if (!animate || !document.startViewTransition
|| window.matchMedia("(prefers-reduced-motion: reduce)").matches
|| root.hasAttribute("data-theme-snapshot")) {
active = null;
pending = null;
delete root.dataset.sessionTransition;
update();
return;
}
root.dataset.sessionTransition = "";
const transition = document.startViewTransition(() => {
if (pending !== update) return;
pending = null;
flushSync(update);
});
active = transition;
// Skipped captures still run their update; only the latest navigation may commit.
void transition.ready.catch(() => {});
const release = () => {
if (active !== transition) return;
active = null;
delete root.dataset.sessionTransition;
};
void transition.finished.then(release, release);
}