Skip to content

Commit 4726b3f

Browse files
committed
fix(web): home content off-center when sidebar collapsed
The home page centered its content by offsetting with --cheatcode-sidebar-offset, but that var was never set on the home route: AppSidebar (which sets it) is Suspense-wrapped for usePathname, so its effect lagged and the root pl fell back to the 16rem (256px = *expanded* width) default even while the sidebar was collapsed to a 48px rail — shoving all content ~200px right of center. - Add HomeSidebarOffset (non-suspended client) that sets the var from the store's sidebarCollapsed (56px collapsed / 240px expanded), so the offset is always right. - The fixed composer form used a hardcoded md:pl-64 instead of the var, so it never re-centered on collapse — switch it to md:pl-[var(--cheatcode-sidebar-offset,16rem)]. Verified: collapsed -> greeting + composer both center at 988 (aligned); expanded -> 1080.
1 parent 3eeee20 commit 4726b3f

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

apps/web/src/app/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { HomeComposerFromSearchParams } from "@/components/home/home-composer-fr
33
import { HomeGreeting } from "@/components/home/home-greeting";
44
import { HomeHeadline } from "@/components/home/home-headline";
55
import { HomeSessionChrome } from "@/components/home/home-session-chrome";
6+
import { HomeSidebarOffset } from "@/components/home/home-sidebar-offset";
67
import { AppSidebar } from "@/components/shell/app-sidebar";
78
import { CheatcodeMark } from "@/components/ui/cheatcode-mark";
89

910
export default function HomePage() {
1011
return (
1112
<div className="relative min-h-screen bg-white text-[#1b1b1b] transition-[padding] duration-200 md:pl-[var(--cheatcode-sidebar-offset,16rem)]">
13+
<HomeSidebarOffset />
1214
<Suspense fallback={null}>
1315
<AppSidebar variant="full" />
1416
</Suspense>

apps/web/src/components/home/home-composer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export function HomeComposer({
387387
<HomeQuickActions activeIntentId={intentId} onIntentClick={selectQuickIntent} />
388388
{skillCreatorMode ? <SkillCreatorSuggestions onPick={(text) => setValue(text)} /> : null}
389389
<form
390-
className="cheatcode-home-composer-form mt-8 w-full md:pointer-events-none md:fixed md:right-0 md:bottom-8 md:left-0 md:z-20 md:flex md:justify-center md:pl-64"
390+
className="cheatcode-home-composer-form mt-8 w-full md:pointer-events-none md:fixed md:right-0 md:bottom-8 md:left-0 md:z-20 md:flex md:justify-center md:pl-[var(--cheatcode-sidebar-offset,16rem)]"
391391
onSubmit={submit}
392392
>
393393
<div className="relative z-10 mx-auto flex w-full max-w-[708px] flex-col gap-0 md:pointer-events-auto">
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use client";
2+
3+
import { useEffect } from "react";
4+
import { useAppStore } from "@/lib/store/app-store";
5+
6+
/**
7+
* Sets `--cheatcode-sidebar-offset` from the sidebar collapse state so the home
8+
* page's content (root padding-left + the fixed composer form) tracks the actual
9+
* sidebar width — 56px when collapsed (icon rail), 240px when expanded. The main
10+
* `AppSidebar` also sets this, but it is Suspense-wrapped (usePathname), so its
11+
* effect can lag on the home route and the var falls back to the 16rem expanded
12+
* default even while the rail is collapsed, shoving the content right. This runs
13+
* outside that Suspense boundary so the offset is always correct.
14+
*/
15+
export function HomeSidebarOffset() {
16+
const sidebarCollapsed = useAppStore((state) => state.sidebarCollapsed);
17+
18+
useEffect(() => {
19+
document.documentElement.style.setProperty(
20+
"--cheatcode-sidebar-offset",
21+
sidebarCollapsed ? "56px" : "240px",
22+
);
23+
}, [sidebarCollapsed]);
24+
25+
return null;
26+
}

0 commit comments

Comments
 (0)