Skip to content

Commit baa34bb

Browse files
t3dotggclaude
andcommitted
fix(web): restore grain on floating chrome surfaces
Moving the noise from a fixed overlay to the body background removed it from surfaces that paint their own background above the body — the inset main card and the sidebar. The light-on-dark grain brightened those surfaces by ~3.5%, so its loss made them visibly darker and exposed the m-2 seam between the main card and the body edge. Extract the noise into a --surface-grain variable, add a surface-grain utility layering it over an element's own background color, and apply it to SidebarInset and the sidebar containers. Grain baked into each surface's cached raster keeps the perf win — no per-frame blend. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 61dd044 commit baa34bb

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎apps/web/src/components/ui/sidebar.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function Sidebar({
216216
<SidebarInstanceContext value={instanceContextValue}>
217217
<div
218218
className={cn(
219-
"flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",
219+
"flex h-full w-(--sidebar-width) flex-col bg-sidebar surface-grain text-sidebar-foreground",
220220
className,
221221
)}
222222
data-slot="sidebar"
@@ -234,7 +234,7 @@ function Sidebar({
234234
<Sheet onOpenChange={setOpenMobile} open={openMobile} {...props}>
235235
<SheetPopup
236236
className={cn(
237-
"w-(--sidebar-width) max-w-none bg-sidebar p-0 text-sidebar-foreground",
237+
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
238238
className,
239239
)}
240240
data-mobile="true"
@@ -304,7 +304,7 @@ function Sidebar({
304304
{...props}
305305
>
306306
<div
307-
className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm/5"
307+
className="flex h-full w-full flex-col bg-sidebar surface-grain group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm/5"
308308
data-sidebar="sidebar"
309309
data-slot="sidebar-inner"
310310
>
@@ -622,7 +622,7 @@ function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
622622
return (
623623
<main
624624
className={cn(
625-
"relative flex min-w-0 w-full flex-1 flex-col bg-background",
625+
"relative flex min-w-0 w-full flex-1 flex-col bg-background surface-grain",
626626
"md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ms-2 md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ms-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm/5",
627627
className,
628628
)}

‎apps/web/src/index.css‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@
250250
padding-right: max(env(safe-area-inset-right), 0px);
251251
}
252252

253+
/* Grain texture for chrome surfaces that float above the body (see the
254+
--surface-grain note). Layered over the element's background-color, so it
255+
composes with bg-* utilities. */
256+
@utility surface-grain {
257+
background-image: var(--surface-grain);
258+
background-repeat: repeat;
259+
background-size: 256px 256px;
260+
}
261+
253262
/* Suppress all transitions during theme changes */
254263
.no-transitions,
255264
.no-transitions *,
@@ -355,12 +364,19 @@ body {
355364
padding-top: max(env(safe-area-inset-top), 0px);
356365
}
357366

358-
/* App-chrome grain. Baked into the body background (behind content) rather
359-
than a fixed overlay on top: a full-viewport overlay forces the compositor
360-
to re-blend every frame any animation produces, which multiplied idle GPU
361-
cost. The overlay's 0.035 opacity lives in the SVG rect instead. */
367+
/* App-chrome grain. Baked into each surface's own background (behind
368+
content) rather than a fixed overlay on top: a full-viewport overlay
369+
forces the compositor to re-blend every frame any animation produces,
370+
which multiplied idle GPU cost. The overlay's 0.035 opacity lives in the
371+
SVG rect instead. Surfaces that float over the body (e.g. the inset main
372+
card) must opt in via the surface-grain utility, or they lose the
373+
grain's subtle brightening and stand out against the body. */
374+
:root {
375+
--surface-grain: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
376+
}
377+
362378
body {
363-
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
379+
background-image: var(--surface-grain);
364380
background-repeat: repeat;
365381
background-size: 256px 256px;
366382
}

0 commit comments

Comments
 (0)