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!

fix broken page titles for standalone blog posts & 404 pages

Blue Mousedb4e377ef812
diff --git a/web/app/App.tsx b/web/app/App.tsx
index fc0e17458..fa606e098 100644
--- a/web/app/App.tsx
+++ b/web/app/App.tsx
@@ -4,7 +4,7 @@ import _some from 'lodash/some'
import _startsWith from 'lodash/startsWith'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
-import { useLocation, Outlet } from 'react-router'
+import { useLocation, useMatches, Outlet } from 'react-router'
import 'dayjs/locale/uk'
import { Toaster } from 'sonner'
@@ -19,17 +19,32 @@ const TITLE_BLACKLIST = ['/projects/', '/captchas/', '/blog']
const App = () => {
const { pathname } = useLocation()
+ const matches = useMatches()
const { t } = useTranslation('common')
const { theme } = useTheme()
+ // Check if current route is a standalone blog post or 404 page (handled by $.tsx)
+ // These have their own title handling in SEO.tsx
+ const isBlogPostOrCatchAll = matches.some((match) => {
+ const data = match.data as { slug?: string } | null
+ const id = match.id || ''
+ // Has blog post data (slug field) or is the catch-all route
+ return data?.slug || id === 'routes/$' || id.endsWith('/$')
+ })
+
useEffect(() => {
if (_some(TITLE_BLACKLIST, (page) => _startsWith(pathname, page))) {
return
}
+ // Skip if this is a standalone blog post or catch-all route (404)
+ if (isBlogPostOrCatchAll) {
+ return
+ }
+
const { title } = getPageMeta(t, undefined, pathname)
document.title = title
- }, [t, pathname])
+ }, [t, pathname, isBlogPostOrCatchAll])
const isReferralPage = _startsWith(pathname, '/ref/')
const isProjectViewPage =
diff --git a/web/app/components/SEO.tsx b/web/app/components/SEO.tsx
index 20f0fab53..a18bf8f7a 100644
--- a/web/app/components/SEO.tsx
+++ b/web/app/components/SEO.tsx
@@ -1,7 +1,7 @@
import _startsWith from 'lodash/startsWith'
import _toUpper from 'lodash/toUpper'
import { useTranslation } from 'react-i18next'
-import { useLocation } from 'react-router'
+import { useLocation, useMatches } from 'react-router'
import { getOgImageUrl, MAIN_URL, defaultLanguage } from '~/lib/constants'
import routes from '~/utils/routes'
@@ -13,9 +13,16 @@ export const SEO = () => {
i18n: { language },
} = useTranslation('common')
const { pathname, search, hash } = useLocation()
+ const matches = useMatches()
const { title, prefixLessTitle } = getPageMeta(t, undefined, pathname)
- const isBlogPage = _startsWith(pathname, '/blog')
+ // Check if any matched route has blog post data (standalone posts don't start with /blog)
+ const isBlogPostFromLoader = matches.some((match) => {
+ const data = match.data as { html?: string } | null
+ return typeof data?.html === 'string' && data.html.length > 0
+ })
+
+ const isBlogPage = _startsWith(pathname, '/blog') || isBlogPostFromLoader
const isMainPage = pathname === '/'
const isErrorsPage = pathname === routes.errorTracking
const isProjectViewPage = _startsWith(pathname, '/projects/')