-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathlayout.tsx
More file actions
55 lines (50 loc) · 1.5 KB
/
layout.tsx
File metadata and controls
55 lines (50 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { CartProvider } from "components/cart/cart-context";
import { Navbar } from "components/layout/navbar";
import { WelcomeToast } from "components/welcome-toast";
import { GeistSans } from "geist/font/sans";
import { getCart } from "lib/shopify";
import { ReactNode } from "react";
import { Toaster } from "sonner";
import "./globals.css";
import { baseUrl } from "lib/utils";
const { SITE_NAME } = process.env;
export const metadata = {
metadataBase: new URL(baseUrl),
title: {
default: SITE_NAME!,
template: `%s | ${SITE_NAME}`,
},
robots: {
follow: true,
index: true,
},
};
export default async function RootLayout({
children,
}: {
children: ReactNode;
}) {
// Don't await the fetch, pass the Promise to the context provider
let cart: ReturnType<typeof getCart> | null;
//by doing this we are ensuring to pass Promise<Cart | undefined> in provider
//this is preventing an error on first load if the getcart throw some errors
try {
cart = getCart();
} catch (err) {
cart = Promise.resolve(undefined);
}
return (
<html lang="en" className={GeistSans.variable}>
<body className="bg-neutral-50 text-black selection:bg-teal-300 dark:bg-neutral-900 dark:text-white dark:selection:bg-pink-500 dark:selection:text-white">
<CartProvider cartPromise={cart}>
<Navbar />
<main>
{children}
<Toaster closeButton />
<WelcomeToast />
</main>
</CartProvider>
</body>
</html>
);
}