From 8a8af948dba50c3ecbfcbe0ceae9a8adc0f9a5d9 Mon Sep 17 00:00:00 2001 From: JoeMakuta Date: Wed, 1 Apr 2026 13:07:27 +0200 Subject: [PATCH 1/3] feat: add experimental package import optimization configuration --- surfsense_web/next.config.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/surfsense_web/next.config.ts b/surfsense_web/next.config.ts index 263b3e6f6..5414d548d 100644 --- a/surfsense_web/next.config.ts +++ b/surfsense_web/next.config.ts @@ -24,6 +24,16 @@ const nextConfig: NextConfig = { }, ], }, + experimental: { + optimizePackageImports: [ + "lucide-react", + "@tabler/icons-react", + "date-fns", + "@assistant-ui/react", + "@assistant-ui/react-markdown", + "motion", + ], + }, // Turbopack config (used during `next dev --turbopack`) turbopack: { rules: { From fc4f9ba7c0563260e5a9e65a8e5df0ad33827c01 Mon Sep 17 00:00:00 2001 From: JoeMakuta Date: Wed, 1 Apr 2026 15:41:11 +0200 Subject: [PATCH 2/3] refac: import of UI components for dropdown menu, separator, toggle group, toggle, tooltip, and checkbox --- surfsense_web/components/ui/checkbox.tsx | 2 +- surfsense_web/components/ui/dropdown-menu.tsx | 2 +- surfsense_web/components/ui/separator.tsx | 2 +- surfsense_web/components/ui/toggle-group.tsx | 2 +- surfsense_web/components/ui/toggle.tsx | 2 +- surfsense_web/components/ui/tooltip.tsx | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/surfsense_web/components/ui/checkbox.tsx b/surfsense_web/components/ui/checkbox.tsx index 0936a383e..586e3e602 100644 --- a/surfsense_web/components/ui/checkbox.tsx +++ b/surfsense_web/components/ui/checkbox.tsx @@ -1,7 +1,7 @@ "use client"; import { CheckIcon } from "lucide-react"; -import { Checkbox as CheckboxPrimitive } from "radix-ui"; +import * as CheckboxPrimitive from "@radix-ui/react-checkbox"; import type * as React from "react"; import { cn } from "@/lib/utils"; diff --git a/surfsense_web/components/ui/dropdown-menu.tsx b/surfsense_web/components/ui/dropdown-menu.tsx index 24b99467e..2904b93dd 100644 --- a/surfsense_web/components/ui/dropdown-menu.tsx +++ b/surfsense_web/components/ui/dropdown-menu.tsx @@ -1,7 +1,7 @@ "use client"; import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"; -import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"; +import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"; import type * as React from "react"; import { cn } from "@/lib/utils"; diff --git a/surfsense_web/components/ui/separator.tsx b/surfsense_web/components/ui/separator.tsx index 63b8e6a69..d7cf2cd81 100644 --- a/surfsense_web/components/ui/separator.tsx +++ b/surfsense_web/components/ui/separator.tsx @@ -1,6 +1,6 @@ "use client"; -import { Separator as SeparatorPrimitive } from "radix-ui"; +import * as SeparatorPrimitive from "@radix-ui/react-separator"; import type * as React from "react"; import { cn } from "@/lib/utils"; diff --git a/surfsense_web/components/ui/toggle-group.tsx b/surfsense_web/components/ui/toggle-group.tsx index eb212182a..33aa433b2 100644 --- a/surfsense_web/components/ui/toggle-group.tsx +++ b/surfsense_web/components/ui/toggle-group.tsx @@ -1,7 +1,7 @@ "use client"; import type { VariantProps } from "class-variance-authority"; -import { ToggleGroup as ToggleGroupPrimitive } from "radix-ui"; +import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"; import * as React from "react"; import { toggleVariants } from "@/components/ui/toggle"; import { cn } from "@/lib/utils"; diff --git a/surfsense_web/components/ui/toggle.tsx b/surfsense_web/components/ui/toggle.tsx index 5841cdc35..f0e68cec9 100644 --- a/surfsense_web/components/ui/toggle.tsx +++ b/surfsense_web/components/ui/toggle.tsx @@ -1,7 +1,7 @@ "use client"; import { cva, type VariantProps } from "class-variance-authority"; -import { Toggle as TogglePrimitive } from "radix-ui"; +import * as TogglePrimitive from "@radix-ui/react-toggle"; import type * as React from "react"; import { cn } from "@/lib/utils"; diff --git a/surfsense_web/components/ui/tooltip.tsx b/surfsense_web/components/ui/tooltip.tsx index c19ce6f82..2fc85aae4 100644 --- a/surfsense_web/components/ui/tooltip.tsx +++ b/surfsense_web/components/ui/tooltip.tsx @@ -1,6 +1,6 @@ "use client"; -import { Tooltip as TooltipPrimitive } from "radix-ui"; +import * as TooltipPrimitive from "@radix-ui/react-tooltip"; import type * as React from "react"; import { cn } from "@/lib/utils"; From 0a65aa1a31cee5689f0f89ff00723deff5ac67f3 Mon Sep 17 00:00:00 2001 From: JoeMakuta Date: Wed, 1 Apr 2026 15:59:11 +0200 Subject: [PATCH 3/3] feat: dynamic import of PostHog --- surfsense_web/app/error.tsx | 8 +++++-- surfsense_web/lib/apis/base-api.service.ts | 26 ++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/surfsense_web/app/error.tsx b/surfsense_web/app/error.tsx index 7bbd74e0e..3935f84d5 100644 --- a/surfsense_web/app/error.tsx +++ b/surfsense_web/app/error.tsx @@ -1,6 +1,6 @@ "use client"; -import posthog from "posthog-js"; + import { useEffect } from "react"; export default function ErrorPage({ @@ -11,7 +11,11 @@ export default function ErrorPage({ reset: () => void; }) { useEffect(() => { - posthog.captureException(error); + import("posthog-js") + .then(({ default: posthog }) => { + posthog.captureException(error); + }) + .catch(() => {}); }, [error]); return ( diff --git a/surfsense_web/lib/apis/base-api.service.ts b/surfsense_web/lib/apis/base-api.service.ts index 4c3371233..bc9e6c1d8 100644 --- a/surfsense_web/lib/apis/base-api.service.ts +++ b/surfsense_web/lib/apis/base-api.service.ts @@ -1,4 +1,3 @@ -import posthog from "posthog-js"; import type { ZodType } from "zod"; import { getBearerToken, handleUnauthorized, refreshAccessToken } from "../auth-utils"; import { AppError, AuthenticationError, AuthorizationError, NotFoundError } from "../error"; @@ -234,18 +233,21 @@ class BaseApiService { } catch (error) { console.error("Request failed:", JSON.stringify(error)); if (!(error instanceof AuthenticationError)) { - try { - posthog.captureException(error, { - api_url: url, - api_method: options?.method ?? "GET", - ...(error instanceof AppError && { - status_code: error.status, - status_text: error.statusText, - }), + import("posthog-js") + .then(({ default: posthog }) => { + posthog.captureException(error, { + api_url: url, + api_method: options?.method ?? "GET", + ...(error instanceof AppError && { + status_code: error.status, + status_text: error.statusText, + }), + }); + }) + .catch(() => { + // PostHog is not available in the current environment + console.error("Failed to capture exception in PostHog"); }); - } catch { - // PostHog capture failed — don't block the error flow - } } throw error; }