Lazy load notification and keep-online providers
Introduced NotificationProviderWrapper to dynamically load the notification context only on dashboard pages, reducing initial bundle size. KeepOnline component is now also lazy-loaded. Updated app layout to use the new wrapper.
This commit is contained in:
@@ -3,9 +3,9 @@ import "./globals.css"
|
||||
import { ThemeProvider } from "@/components/layout/theme-provider"
|
||||
import { Toaster } from "sonner"
|
||||
import type React from "react"
|
||||
import { NotificationProvider } from "@/lib/notification-context"
|
||||
import { Metadata, Viewport } from "next"
|
||||
import KeepOnlineWrapper from "@/components/layout/KeepOnlineWrapper"
|
||||
import { NotificationProviderWrapper } from "@/components/layout/NotificationProviderWrapper"
|
||||
// Christmas theme disabled
|
||||
// import { ChristmasDecorations } from "@/components/christmas-decorations"
|
||||
// import { isDecember } from "@/lib/utils/christmas"
|
||||
@@ -78,7 +78,7 @@ export default function RootLayout({
|
||||
<html lang="en" suppressHydrationWarning className="dark">
|
||||
<body className={inter.className}>
|
||||
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem disableTransitionOnChange>
|
||||
<NotificationProvider>
|
||||
<NotificationProviderWrapper>
|
||||
{/* Christmas decorations disabled */}
|
||||
<Toaster
|
||||
theme="dark"
|
||||
@@ -87,7 +87,7 @@ export default function RootLayout({
|
||||
/>
|
||||
<KeepOnlineWrapper />
|
||||
{children}
|
||||
</NotificationProvider>
|
||||
</NotificationProviderWrapper>
|
||||
</ThemeProvider>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname } from "next/navigation";
|
||||
import KeepOnline from "@/components/KeepOnline";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
// Lazy load KeepOnline component - only needed on dashboard pages
|
||||
const KeepOnline = dynamic(() => import("@/components/KeepOnline"), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
const KeepOnlineWrapper = () => {
|
||||
const pathname = usePathname();
|
||||
|
||||
34
components/layout/NotificationProviderWrapper.tsx
Normal file
34
components/layout/NotificationProviderWrapper.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname } from "next/navigation";
|
||||
import dynamic from "next/dynamic";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
// Lazy load NotificationProvider - only needed on dashboard pages
|
||||
// This saves ~5-10KB from initial bundle since it includes polling logic and API calls
|
||||
const NotificationProvider = dynamic(
|
||||
() => import("@/lib/notification-context").then(mod => ({ default: mod.NotificationProvider })),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => null
|
||||
}
|
||||
);
|
||||
|
||||
interface NotificationProviderWrapperProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export function NotificationProviderWrapper({ children }: NotificationProviderWrapperProps) {
|
||||
const pathname = usePathname();
|
||||
|
||||
// Only load NotificationProvider on dashboard pages (but not admin pages)
|
||||
const isDashboardPage = pathname?.includes("/dashboard") && !pathname?.includes("/dashboard/admin");
|
||||
|
||||
if (isDashboardPage) {
|
||||
return <NotificationProvider>{children}</NotificationProvider>;
|
||||
}
|
||||
|
||||
// On non-dashboard pages, render children without provider
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -60,7 +60,7 @@
|
||||
"tailwind-merge": "^2.5.5",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"vaul": "^0.9.6",
|
||||
"zod": "^3.24.1"
|
||||
"zod": "^3.25.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@distube/ytdl-core": "^4.16.12",
|
||||
@@ -10551,9 +10551,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "3.24.1",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz",
|
||||
"integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==",
|
||||
"version": "3.25.76",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
||||
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
|
||||
Reference in New Issue
Block a user