Skip to content

Commit

Permalink
fix: rename sidebar cookie to be valid name (#6558)
Browse files Browse the repository at this point in the history
* fix: rename sidebar cookie to be valid name

* fix: rename sidebar cookie to underscore

---------

Co-authored-by: shadcn <[email protected]>
  • Loading branch information
longzheng and shadcn authored Feb 7, 2025
1 parent 16d4d38 commit 1eb2d74
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions apps/www/content/docs/components/sidebar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ const SIDEBAR_KEYBOARD_SHORTCUT = "b"

### Persisted State

The `SidebarProvider` supports persisting the sidebar state across page reloads and server-side rendering. It uses cookies to store the current state of the sidebar. When the sidebar state changes, a default cookie named `sidebar:state` is set with the current open/closed state. This cookie is then read on subsequent page loads to restore the sidebar state.
The `SidebarProvider` supports persisting the sidebar state across page reloads and server-side rendering. It uses cookies to store the current state of the sidebar. When the sidebar state changes, a default cookie named `sidebar_state` is set with the current open/closed state. This cookie is then read on subsequent page loads to restore the sidebar state.

To persist sidebar state in Next.js, set up your `SidebarProvider` in `app/layout.tsx` like this:

Expand All @@ -420,7 +420,7 @@ import { AppSidebar } from "@/components/app-sidebar"

export async function Layout({ children }: { children: React.ReactNode }) {
const cookieStore = await cookies()
const defaultOpen = cookieStore.get("sidebar:state")?.value === "true"
const defaultOpen = cookieStore.get("sidebar_state")?.value === "true"

return (
<SidebarProvider defaultOpen={defaultOpen}>
Expand All @@ -437,7 +437,7 @@ export async function Layout({ children }: { children: React.ReactNode }) {
You can change the name of the cookie by updating the `SIDEBAR_COOKIE_NAME` variable in `sidebar.tsx`.

```tsx showLineNumbers title="components/ui/sidebar.tsx"
const SIDEBAR_COOKIE_NAME = "sidebar:state"
const SIDEBAR_COOKIE_NAME = "sidebar_state"
```

## Sidebar
Expand Down
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/sidebar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/new-york/sidebar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/registry/default/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TooltipTrigger,
} from "@/registry/default/ui/tooltip"

const SIDEBAR_COOKIE_NAME = "sidebar:state"
const SIDEBAR_COOKIE_NAME = "sidebar_state"
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
const SIDEBAR_WIDTH = "16rem"
const SIDEBAR_WIDTH_MOBILE = "18rem"
Expand Down
2 changes: 1 addition & 1 deletion apps/www/registry/new-york/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TooltipTrigger,
} from "@/registry/new-york/ui/tooltip"

const SIDEBAR_COOKIE_NAME = "sidebar:state"
const SIDEBAR_COOKIE_NAME = "sidebar_state"
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
const SIDEBAR_WIDTH = "16rem"
const SIDEBAR_WIDTH_MOBILE = "18rem"
Expand Down

0 comments on commit 1eb2d74

Please sign in to comment.