Skip to content

Commit 8d30dd1

Browse files
committed
fix(shop): mount cart drawer at root so it works on non-shop pages
The drawer was inside ShopLayout, which only mounts on /shop/* routes. Clicking the navbar cart button on /docs or /blog called the zustand store's openDrawer() but nothing was listening. Moved the drawer mount to __root.tsx so it's globally available — same as the search modal.
1 parent 2da61e5 commit 8d30dd1

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/components/shop/ShopLayout.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
import { twMerge } from 'tailwind-merge'
1515
import { useLocalStorage } from '~/utils/useLocalStorage'
1616
import type { CollectionListItem } from '~/utils/shopify-queries'
17-
import { CartDrawer } from './CartDrawer'
18-
import { useCartDrawerStore } from './cartDrawerStore'
1917

2018
type ShopLayoutProps = {
2119
collections: Array<CollectionListItem>
@@ -150,18 +148,10 @@ export function ShopLayout({ collections, children }: ShopLayoutProps) {
150148
>
151149
{children}
152150
</main>
153-
154-
<GlobalCartDrawer />
155151
</div>
156152
)
157153
}
158154

159-
function GlobalCartDrawer() {
160-
const open = useCartDrawerStore((s) => s.open)
161-
const setOpen = useCartDrawerStore((s) => s.setOpen)
162-
return <CartDrawer open={open} onOpenChange={setOpen} />
163-
}
164-
165155
function ShopSidebarNav({
166156
collections,
167157
showLabels,

src/routes/__root.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ import { THEME_COLORS } from '~/utils/utils'
3939
import { useHubSpotChat } from '~/hooks/useHubSpotChat'
4040
import { trackPageView } from '~/utils/analytics'
4141
import { twMerge } from 'tailwind-merge'
42+
import { CartDrawer } from '~/components/shop/CartDrawer'
43+
import { useCartDrawerStore } from '~/components/shop/cartDrawerStore'
44+
45+
function GlobalCartDrawer() {
46+
const open = useCartDrawerStore((s) => s.open)
47+
const setOpen = useCartDrawerStore((s) => s.setOpen)
48+
return <CartDrawer open={open} onOpenChange={setOpen} />
49+
}
4250

4351
const GOOGLE_ANALYTICS_ID = 'G-JMT1Z50SPS'
4452
const GOOGLE_ANALYTICS_SCRIPT_SRC = `https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID}`
@@ -218,6 +226,7 @@ function ShellComponent({ children }: { children: React.ReactNode }) {
218226
<ToastProvider>
219227
<PageViewTracker />
220228
{hideNavbar ? children : <Navbar>{children}</Navbar>}
229+
<GlobalCartDrawer />
221230
{showDevtools && LazyAppDevtools ? (
222231
<React.Suspense fallback={null}>
223232
<LazyAppDevtools />

0 commit comments

Comments
 (0)