From 3740171a5ce7625545cb596e38cb70ce81c976d3 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Wed, 15 Jul 2026 18:12:30 +0530 Subject: [PATCH] feat(layout): add cookie persistence for playground sidebar state management --- .../components/layout/ui/shell/LayoutShell.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/surfsense_web/components/layout/ui/shell/LayoutShell.tsx b/surfsense_web/components/layout/ui/shell/LayoutShell.tsx index 7a42d5a2e..8578b7dec 100644 --- a/surfsense_web/components/layout/ui/shell/LayoutShell.tsx +++ b/surfsense_web/components/layout/ui/shell/LayoutShell.tsx @@ -44,6 +44,20 @@ const DocumentTabContent = dynamic( const PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE = "surfsense_playground_sidebar_collapsed"; const PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 365; +function persistPlaygroundSidebarCollapsedCookie(isCollapsed: boolean) { + void window.cookieStore + ?.set({ + name: PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE, + value: String(isCollapsed), + path: "/", + expires: Date.now() + PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE * 1000, + sameSite: "lax", + }) + .catch(() => { + // Ignore preference persistence failures. + }); +} + function MacDesktopTitleBar({ isSidebarCollapsed, onToggleSidebar, @@ -242,8 +256,7 @@ export function LayoutShell({ const handlePlaygroundSidebarToggle = () => { setIsPlaygroundSidebarCollapsed((collapsed) => { const nextCollapsed = !collapsed; - const secureAttribute = window.location.protocol === "https:" ? "; Secure" : ""; - document.cookie = `${PLAYGROUND_SIDEBAR_COLLAPSED_COOKIE}=${nextCollapsed}; Path=/; Max-Age=${PLAYGROUND_SIDEBAR_COOKIE_MAX_AGE}; SameSite=Lax${secureAttribute}`; + persistPlaygroundSidebarCollapsedCookie(nextCollapsed); return nextCollapsed; }); };