Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Move tabs detection to useSearchParams hook

Blue Mousec059cd54e7eb
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index 032ccfdd3..9ca272dc1 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -50,7 +50,7 @@ import React, {
} from 'react'
import { useHotkeys } from 'react-hotkeys-hook'
import { useTranslation } from 'react-i18next'
-import { useNavigate, Link, useSearchParams, useLoaderData } from 'react-router'
+import { useNavigate, Link, useSearchParams } from 'react-router'
import { ClientOnly } from 'remix-utils/client-only'
import { toast } from 'sonner'
@@ -249,10 +249,6 @@ const ViewProject = () => {
const { id, project, preferences, updatePreferences, extensions, mergeProject, allowedToManage } = useCurrentProject()
const projectPassword = useProjectPassword(id)
- const { tabs: projectQueryTabs } = useLoaderData<{
- tabs: string[]
- }>()
-
const { theme } = useTheme()
const { isAuthenticated, user, isLoading: authLoading } = useAuth()
@@ -279,6 +275,7 @@ const ViewProject = () => {
const [searchParams, setSearchParams] = useSearchParams()
const isEmbedded = searchParams.get('embedded') === 'true'
+ const projectQueryTabs = searchParams.get('tabs') ? searchParams.get('tabs')?.split(',') : []
const [liveVisitors, setLiveVisitors] = useState(0)
diff --git a/web/app/routes/projects.$id.tsx b/web/app/routes/projects.$id.tsx
index 1923d0ef7..433562ed5 100644
--- a/web/app/routes/projects.$id.tsx
+++ b/web/app/routes/projects.$id.tsx
@@ -1,12 +1,11 @@
import _split from 'lodash/split'
-import { type LinksFunction, type LoaderFunctionArgs, type MetaFunction } from 'react-router'
+import { type LinksFunction, type MetaFunction } from 'react-router'
import { useRequiredParams } from '~/hooks/useRequiredParams'
import { API_URL } from '~/lib/constants'
import ViewProject from '~/pages/Project/View'
import { CurrentProjectProvider } from '~/providers/CurrentProjectProvider'
import ProjectViewStyle from '~/styles/ProjectViewStyle.css?url'
-import { getProjectTabs } from '~/utils/server'
export const links: LinksFunction = () => [{ rel: 'stylesheet', href: ProjectViewStyle }]
@@ -21,14 +20,6 @@ export const meta: MetaFunction = ({ location }) => {
]
}
-export async function loader({ request }: LoaderFunctionArgs) {
- const tabs = getProjectTabs(request)
-
- return {
- tabs,
- }
-}
-
export default function Index() {
const { id } = useRequiredParams<{ id: string }>()
diff --git a/web/app/utils/server.ts b/web/app/utils/server.ts
index 6506c57c3..ad0409e4a 100644
--- a/web/app/utils/server.ts
+++ b/web/app/utils/server.ts
@@ -1,6 +1,5 @@
import type i18next from 'i18next'
import _includes from 'lodash/includes'
-import _split from 'lodash/split'
import _startsWith from 'lodash/startsWith'
import { TITLE_SUFFIX, SUPPORTED_THEMES, ThemeType } from '~/lib/constants'
@@ -37,16 +36,6 @@ export function detectTheme(request: Request): ThemeType {
return 'light'
}
-export function getProjectTabs(request: Request): string[] {
- const tabs = new URL(request.url).searchParams.get('tabs')
-
- if (!tabs) {
- return []
- }
-
- return _split(tabs, ',')
-}
-
function getAccessToken(request: Request): string | null {
const cookie = request.headers.get('Cookie')
const accessToken = cookie?.match(/(?<=access_token=)[^;]*/)?.[0]