Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Shell: a full-screen studio never writes the sidebar cookie

Claudea7ce16467b1e
diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx
index fe20dc92..1a417827 100644
--- a/src/components/app-sidebar.tsx
+++ b/src/components/app-sidebar.tsx
@@ -30,7 +30,7 @@ import { JobNotifications } from "@/components/job-notifications";
import { NAV, type NavGroupDef } from "@/components/nav-items";
import { useEngineMode, useStatus } from "@/lib/api";
import { useModKey } from "@/lib/keys";
-import { groupId, isFullScreenStudio, NAV_CLOSED_KEY, navActive, parseClosed, SIDEBAR_STATE_SCRIPT, sidebarOpenFromCookie } from "@/lib/nav";
+import { fullScreenStudio, groupId, NAV_CLOSED_KEY, navActive, parseClosed, sidebarCookie, SIDEBAR_STATE_SCRIPT, sidebarOpenFromCookie } from "@/lib/nav";
import { cn } from "@/lib/utils";
const NO_SEARCH = new URLSearchParams();
@@ -163,14 +163,14 @@ interface ShellState {
path: string;
/** The expanded/collapsed choice in the cookie. */
remembered: boolean;
- /** Opened or closed by hand on a full-screen studio: lasts while that page is open. */
- peek: { path: string; open: boolean } | null;
+ /** Opened or closed by hand in a full-screen studio (fullScreenStudio): lasts while you stay in it. */
+ peek: { studio: string; open: boolean } | null;
}
/**
- * SidebarProvider that starts from the remembered expanded/collapsed state (the shadcn cookie). On a
- * full-screen studio (isFullScreenStudio) the sidebar folds to its rail instead; opening it there
- * lasts until you leave that page, and neither writes the cookie.
+ * SidebarProvider that starts from the remembered expanded/collapsed state (the shadcn cookie). In a
+ * full-screen studio (fullScreenStudio) the sidebar folds to its rail instead; opening it there
+ * lasts until you leave that studio, and neither writes the cookie.
*/
export function SidebarShell({ children, style }: { children: React.ReactNode; style?: React.CSSProperties }) {
// The first client render reads the cookie and the URL itself, as the pre-paint script does, so hydration matches.
@@ -179,17 +179,34 @@ export function SidebarShell({ children, style }: { children: React.ReactNode; s
remembered: typeof document === "undefined" ? true : sidebarOpenFromCookie(document.cookie),
peek: null,
}));
- const full = isFullScreenStudio(state.path);
- const open = full ? state.peek?.path === state.path && state.peek.open : state.remembered;
+ const studio = fullScreenStudio(state.path);
+ const open = studio ? state.peek?.studio === studio && state.peek.open : state.remembered;
// Both callbacks are stable, so a new page alone leaves the provider's context as it was and the
- // sidebar doesn't render again on every navigation.
+ // sidebar doesn't render again on every navigation. A change is filed by the page it applies to
+ // (the state's own path), never by the page a stale callback was made on.
const onOpenChange = useCallback(
- (value: boolean) => setState((s) => (isFullScreenStudio(s.path) ? { ...s, peek: { path: s.path, open: value } } : { ...s, remembered: value })),
+ (value: boolean) =>
+ setState((s) => {
+ const at = fullScreenStudio(s.path);
+ return at ? { ...s, peek: { studio: at, open: value } } : { ...s, remembered: value };
+ }),
[],
);
- const onPath = useCallback((path: string) => setState((s) => (s.path === path ? s : { ...s, path })), []);
+ const onPath = useCallback(
+ (path: string) =>
+ setState((s) => {
+ if (s.path === path) return s;
+ const at = fullScreenStudio(path);
+ return { ...s, path, peek: at && s.peek?.studio === at ? s.peek : null };
+ }),
+ [],
+ );
+ // Only the remembered choice reaches the cookie: a studio's fold or peek never does.
+ useEffect(() => {
+ if (sidebarOpenFromCookie(document.cookie) !== state.remembered) document.cookie = sidebarCookie(state.remembered);
+ }, [state.remembered]);
return (
- <SidebarProvider open={open} onOpenChange={onOpenChange} persistOpen={!full} style={style}>
+ <SidebarProvider open={open} onOpenChange={onOpenChange} persistOpen={false} style={style}>
<Suspense fallback={null}>
<PathWatcher onPath={onPath} />
</Suspense>
diff --git a/src/components/layers/layers-editor.tsx b/src/components/layers/layers-editor.tsx
index 89da6da6..63e68819 100644
--- a/src/components/layers/layers-editor.tsx
+++ b/src/components/layers/layers-editor.tsx
@@ -6,7 +6,6 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, u
import { toast } from "sonner";
import { ErrorState, NotFoundState } from "@/components/empty-state";
import { Button } from "@/components/ui/button";
-import { useSidebar } from "@/components/ui/sidebar";
import { Skeleton } from "@/components/ui/skeleton";
import { CompareSlider } from "@/components/studio/compare-slider";
import { useIsMobile } from "@/hooks/use-mobile";
@@ -101,24 +100,6 @@ export function LayersEditor({ id, models }: { id: string; models: Record<string
return <EditorSkeleton />;
}
-/**
- * Below 1440 px the app's sidebar folds to icons while the editor is open, so the canvas keeps its
- * room next to a tool's form and the Layers panel (and the top bar its labels); it opens again when you leave.
- */
-function useRoomyCanvas() {
- const sidebar = useSidebar();
- const ref = useRef(sidebar);
- useLayoutEffect(() => {
- ref.current = sidebar;
- });
- useEffect(() => {
- const s = ref.current;
- if (s.isMobile || !s.open || window.innerWidth >= 1440) return;
- s.setOpen(false);
- return () => ref.current.setOpen(true);
- }, []);
-}
-
function Editor({ view, refetch, models }: { view: LayerProjectView; refetch: () => Promise<{ data?: LayerProjectView }>; models: Record<string, LayerModelInfo> }) {
// The document is the editor's once loaded; later fetches bring jobs and versions.
const [initial] = useState(view);
@@ -127,7 +108,6 @@ function Editor({ view, refetch, models }: { view: LayerProjectView; refetch: ()
const isMobile = useIsMobile();
const [engine, setEngine] = useEngine();
const status = useStatus().data;
- useRoomyCanvas();
const [hist, dispatch] = useReducer(historyReducer, initial.doc, (doc) => ({ past: [], present: doc, future: [] }));
const doc = hist.present;
diff --git a/src/lib/nav.ts b/src/lib/nav.ts
index ef894354..451bf313 100644
--- a/src/lib/nav.ts
+++ b/src/lib/nav.ts
@@ -53,6 +53,11 @@ export function sidebarOpenFromCookie(cookie: string): boolean {
return !new RegExp(`(?:^|;\\s*)${SIDEBAR_COOKIE}=false(?:;|$)`).test(cookie);
}
+/** The cookie that remembers the expanded/collapsed choice (as the shadcn SidebarProvider writes it). */
+export function sidebarCookie(open: boolean): string {
+ return `${SIDEBAR_COOKIE}=${open}; path=/; max-age=${60 * 60 * 24 * 7}`;
+}
+
/**
* Full-screen studios: a project open in Cinema, Canvas or Layers, and Assist (with its own rail of
* chats). They have a sidebar of their own, so the app sidebar folds to its icon rail while one is
@@ -60,8 +65,14 @@ export function sidebarOpenFromCookie(cookie: string): boolean {
*/
const FULL_SCREEN = /^\/(?:(?:cinema|canvas|layers)\/[^/]+\/?|assist(?:\/.*)?)$/;
-export function isFullScreenStudio(pathname: string): boolean {
- return FULL_SCREEN.test(pathname);
+/**
+ * Which full-screen studio a path belongs to (null on any other page): the project's own path, or
+ * "/assist" for every Assist page (its chats, projects, skills and memory are one workspace). The
+ * sidebar opened by hand stays open while you move inside one studio, and folds again in the next.
+ */
+export function fullScreenStudio(pathname: string): string | null {
+ if (!FULL_SCREEN.test(pathname)) return null;
+ return /^\/assist(?:\/|$)/.test(pathname) ? "/assist" : pathname.replace(/\/$/, "");
}
/**
diff --git a/tests/nav.test.ts b/tests/nav.test.ts
index a7e0e891..07b76716 100644
--- a/tests/nav.test.ts
+++ b/tests/nav.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { NAV } from "@/components/nav-items";
-import { DEFAULT_NAV_CLOSED, groupId, isFullScreenStudio, navActive, parseClosed, SIDEBAR_STATE_SCRIPT, sidebarOpenFromCookie } from "@/lib/nav";
+import { DEFAULT_NAV_CLOSED, fullScreenStudio, groupId, navActive, parseClosed, sidebarCookie, SIDEBAR_STATE_SCRIPT, sidebarOpenFromCookie } from "@/lib/nav";
const q = (s = "") => new URLSearchParams(s);
const LIBRARY = ["/library", "/library?tab=favorites"];
@@ -126,7 +126,24 @@ describe("remembered sidebar state", () => {
describe("full-screen studios", () => {
it("are an open Cinema, Canvas or Layers project, and Assist", () => {
- for (const p of ["/cinema/abc", "/canvas/x1", "/layers/l-2/", "/assist", "/assist/memory", "/assist/projects/p1"]) expect(isFullScreenStudio(p)).toBe(true);
- for (const p of ["/", "/cinema", "/canvas", "/layers", "/assistant", "/apps/app-packshot", "/cinema/a/b", "/library"]) expect(isFullScreenStudio(p)).toBe(false);
+ for (const p of ["/cinema/abc", "/canvas/x1", "/layers/l-2/", "/assist", "/assist/memory", "/assist/projects/p1"]) expect(fullScreenStudio(p)).not.toBeNull();
+ for (const p of ["/", "/cinema", "/canvas", "/layers", "/assistant", "/apps/app-packshot", "/cinema/a/b", "/library"]) expect(fullScreenStudio(p)).toBeNull();
+ });
+
+ it("count every Assist page as one studio, and each project as its own", () => {
+ // Opening the sidebar on a chat keeps it open on Skills; a different project folds it again.
+ expect(fullScreenStudio("/assist")).toBe("/assist");
+ expect(fullScreenStudio("/assist/skills")).toBe(fullScreenStudio("/assist/projects/p1"));
+ expect(fullScreenStudio("/layers/l-2/")).toBe(fullScreenStudio("/layers/l-2"));
+ expect(fullScreenStudio("/cinema/a")).not.toBe(fullScreenStudio("/cinema/b"));
+ expect(fullScreenStudio("/canvas/a")).not.toBe(fullScreenStudio("/cinema/a"));
+ });
+});
+
+describe("the remembered choice's cookie", () => {
+ it("is the one the shadcn provider reads, for a week, site-wide", () => {
+ expect(sidebarCookie(false)).toBe("sidebar_state=false; path=/; max-age=604800");
+ expect(sidebarOpenFromCookie(sidebarCookie(false).split(";")[0])).toBe(false);
+ expect(sidebarOpenFromCookie(sidebarCookie(true).split(";")[0])).toBe(true);
});
});