diff --git a/apps/ssr/client/components/common/404.tsx b/apps/ssr/client/components/common/404.tsx
new file mode 100644
index 000000000..057d21090
--- /dev/null
+++ b/apps/ssr/client/components/common/404.tsx
@@ -0,0 +1,245 @@
+import { Header } from "@client/components/layout/header"
+import { openInFollowApp } from "@client/lib/helper"
+import { MemoedDangerousHTMLStyle } from "@follow/components/common/MemoedDangerousHTMLStyle.jsx"
+import { PoweredByFooter } from "@follow/components/common/PoweredByFooter.jsx"
+import { Button } from "@follow/components/ui/button/index.jsx"
+import { useTitle } from "@follow/hooks"
+import { m as motion } from "motion/react"
+import { Fragment, useEffect, useState } from "react"
+
+export const NotFound = () => {
+ const [isVisible, setIsVisible] = useState(false)
+ const [glitchText, setGlitchText] = useState("404")
+ const [isGlitching, setIsGlitching] = useState(false)
+
+ useTitle("404 - Page Not Found")
+
+ useEffect(() => {
+ setIsVisible(true)
+ }, [])
+
+ useEffect(() => {
+ if (!isGlitching) return
+
+ const glitchTexts = ["404", "40₄", "4Ø4", "404", "4◯4", "4○4", "4𝟘4"]
+
+ const glitchInterval = setInterval(() => {
+ const randomText = glitchTexts[Math.floor(Math.random() * glitchTexts.length)]
+ setGlitchText(randomText || "404")
+ }, 200)
+ return () => {
+ setGlitchText("404")
+ clearInterval(glitchInterval)
+ }
+ }, [isGlitching])
+ const handleGoHome = () => {
+ window.location.href = "/"
+ }
+
+ const handleOpenInApp = () => {
+ openInFollowApp({
+ deeplink: "",
+ fallbackUrl: "/",
+ })
+ }
+
+ return (
+
+
+ {`:root {
+ --container-max-width: 1024px;
+ }
+
+ @keyframes float {
+ 0%, 100% { transform: translateY(0px); }
+ 50% { transform: translateY(-10px); }
+ }
+
+ @keyframes pulse-glow {
+ 0%, 100% { box-shadow: 0 0 20px rgba(168, 162, 158, 0.3); }
+ 50% { box-shadow: 0 0 40px rgba(168, 162, 158, 0.6); }
+ }
+
+ @keyframes shake {
+ 0%, 100% { transform: translateX(0); }
+ 25% { transform: translateX(-2px); }
+ 75% { transform: translateX(2px); }
+ }
+
+ @keyframes glitch {
+ 0% { transform: translate(0); }
+ 20% { transform: translate(-2px, 2px); }
+ 40% { transform: translate(-2px, -2px); }
+ 60% { transform: translate(2px, 2px); }
+ 80% { transform: translate(2px, -2px); }
+ 100% { transform: translate(0); }
+ }
+
+ .float-animation {
+ animation: float 3s ease-in-out infinite;
+ }
+
+ .pulse-glow-animation {
+ animation: pulse-glow 2s ease-in-out infinite;
+ }
+
+ .shake-animation {
+ animation: shake 0.5s ease-in-out;
+ }
+
+ .glitch-animation {
+ animation: glitch 0.1s linear infinite;
+ }`}
+
+
+
+
+ {/* 404 Icon with animations */}
+
+ {
+ const element = document.querySelector(".shake-animation")
+ if (element) {
+ element.classList.remove("shake-animation")
+ setTimeout(() => element.classList.add("shake-animation"), 10)
+ }
+ }}
+ onMouseEnter={() => {
+ setIsGlitching(true)
+ }}
+ onMouseLeave={() => {
+ setIsGlitching(false)
+ }}
+ >
+
+ {glitchText}
+
+
+
+
+ {/* Error Message with stagger animation */}
+
+
+ Page Not Found
+
+
+ Sorry, the page you are looking for doesn't exist or has been moved. Please check the
+ URL or return to the homepage to continue browsing.
+
+
+
+ {/* Action Buttons with hover effects */}
+
+
+
+
+
+
+
+
+
+
+ {/* Additional Help with fade in */}
+
+
+ If you believe this is an error, please submit a issue on{" "}
+
+ GitHub
+
+
+
+
+ {/* Floating particles effect */}
+
+ {Array.from({ length: 6 }).map((_, i) => (
+
+ ))}
+
+
+
+
+
+ )
+}
diff --git a/apps/ssr/client/components/common/NotFound.tsx b/apps/ssr/client/components/common/NotFound.tsx
deleted file mode 100644
index 06cd84626..000000000
--- a/apps/ssr/client/components/common/NotFound.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-import { PoweredByFooter } from "@follow/components/common/PoweredByFooter.jsx"
-import { Logo } from "@follow/components/icons/logo.jsx"
-import { Button } from "@follow/components/ui/button/index.js"
-import { useLocation } from "react-router"
-
-export const NotFound = () => {
- const location = useLocation()
-
- return (
-
-
-
-
-
-
- You have come to a desert of knowledge where there is nothing.
-
-
- Current path: {location.pathname}
-
-
-
-
-
-
-
-
-
- )
-}
diff --git a/apps/ssr/client/pages/(main)/layout.tsx b/apps/ssr/client/pages/(main)/layout.tsx
index 3b762d634..831170d12 100644
--- a/apps/ssr/client/pages/(main)/layout.tsx
+++ b/apps/ssr/client/pages/(main)/layout.tsx
@@ -1,7 +1,11 @@
+import { NotFound } from "@client/components/common/404"
import { useSyncThemeWebApp } from "@follow/hooks"
import { Outlet } from "react-router"
export const Component = () => {
useSyncThemeWebApp()
+ if (document.documentElement.dataset.notFound === "true") {
+ return
+ }
return
}
diff --git a/apps/ssr/client/pages/(main)/share/feeds/[id]/metadata.ts b/apps/ssr/client/pages/(main)/share/feeds/[id]/metadata.ts
index 20d37d706..b39421f3e 100644
--- a/apps/ssr/client/pages/(main)/share/feeds/[id]/metadata.ts
+++ b/apps/ssr/client/pages/(main)/share/feeds/[id]/metadata.ts
@@ -1,15 +1,13 @@
import type { GetHydrateData } from "@client/lib/helper"
import { APPLE_APP_STORE_ID } from "@follow/constants"
+import { callNotFound } from "~/lib/not-found"
import { defineMetadata } from "~/meta-handler"
-const meta = defineMetadata(async ({ params, apiClient, origin, throwError }) => {
+const meta = defineMetadata(async ({ params, apiClient, origin }) => {
const feedId = params.id
- const feed = await apiClient.feeds.$get({ query: { id: feedId } }).catch((e) => {
- throwError(e.response?.status || 500, "Feed not found")
- throw e
- })
+ const feed = await apiClient.feeds.$get({ query: { id: feedId } }).catch(callNotFound)
const { title, description } = feed.data.feed
diff --git a/apps/ssr/client/pages/(main)/share/lists/[id]/metadata.ts b/apps/ssr/client/pages/(main)/share/lists/[id]/metadata.ts
index 25e8680bf..ba7995193 100644
--- a/apps/ssr/client/pages/(main)/share/lists/[id]/metadata.ts
+++ b/apps/ssr/client/pages/(main)/share/lists/[id]/metadata.ts
@@ -1,12 +1,11 @@
import { APPLE_APP_STORE_ID } from "@follow/constants"
+import { callNotFound } from "~/lib/not-found"
import { defineMetadata } from "~/meta-handler"
-export default defineMetadata(async ({ params, apiClient, origin, throwError }) => {
+export default defineMetadata(async ({ params, apiClient, origin }) => {
const listId = params.id!
- const list = await apiClient.lists
- .$get({ query: { listId } })
- .catch((e) => throwError(e.response?.status || 500, "List not found"))
+ const list = await apiClient.lists.$get({ query: { listId } }).catch(callNotFound)
const { title, description } = list.data.list
return [
diff --git a/apps/ssr/client/pages/(main)/share/users/[id]/metadata.ts b/apps/ssr/client/pages/(main)/share/users/[id]/metadata.ts
index 0d66fa950..79ab620b4 100644
--- a/apps/ssr/client/pages/(main)/share/users/[id]/metadata.ts
+++ b/apps/ssr/client/pages/(main)/share/users/[id]/metadata.ts
@@ -1,74 +1,71 @@
import { isBizId } from "@follow/utils/utils"
+import { callNotFound } from "~/lib/not-found"
import type { MetaTag } from "~/meta-handler"
import { defineMetadata } from "~/meta-handler"
-export default defineMetadata(
- async ({ params, apiClient, origin, throwError }): Promise => {
- const mayBeUserId = params.id
+export default defineMetadata(async ({ params, apiClient, origin }): Promise => {
+ const mayBeUserId = params.id
- const handle = isBizId(mayBeUserId || "")
- ? mayBeUserId
- : `${mayBeUserId}`.startsWith("@")
- ? `${mayBeUserId}`.slice(1)
- : mayBeUserId
+ const handle = isBizId(mayBeUserId || "")
+ ? mayBeUserId
+ : `${mayBeUserId}`.startsWith("@")
+ ? `${mayBeUserId}`.slice(1)
+ : mayBeUserId
- const [profileRes] = await Promise.allSettled([
- apiClient.profiles
- .$get({
- query: {
- handle,
- id: isBizId(handle || "") ? handle : undefined,
- },
+ const profileRes = await apiClient.profiles
+ .$get({
+ query: {
+ handle,
+ id: isBizId(handle || "") ? handle : undefined,
+ },
+ })
+ .catch((e) => callNotFound(e.message))
+
+ const realUserId = profileRes.data.id
+ const [subscriptionsRes] = await Promise.allSettled([
+ profileRes.data.id
+ ? apiClient.subscriptions.$get({
+ query: { userId: realUserId },
})
- .catch((e) => throwError(e.response?.status || 404, "User not found")),
- ])
- const isProfileResolved = profileRes.status === "fulfilled"
- const realUserId = isProfileResolved ? profileRes.value.data.id : ""
- const [subscriptionsRes] = await Promise.allSettled([
- isProfileResolved
- ? apiClient.subscriptions.$get({
- query: { userId: realUserId },
- })
- : Promise.reject(),
- ])
+ : Promise.reject(),
+ ])
- const isSubscriptionsResolved = subscriptionsRes.status === "fulfilled"
+ const isSubscriptionsResolved = subscriptionsRes.status === "fulfilled"
- const { name } = isProfileResolved ? profileRes.value.data : {}
- const subscriptions = isSubscriptionsResolved ? subscriptionsRes.value.data : []
+ const { name } = profileRes.data
+ const subscriptions = isSubscriptionsResolved ? subscriptionsRes.value.data : []
- return [
- {
- type: "title",
- title: name || "",
- },
- {
- type: "description",
- description:
- subscriptions.length > 0
- ? `${name} followed ${subscriptions.length} public subscription${
- subscriptions.length > 1 ? "s" : ""
- }. Follow them to get their latest updates on ${APP_NAME}`
- : "",
- },
- {
- type: "openGraph",
- title: `${name} on ${APP_NAME}`,
- image: `${origin}/og/user/${mayBeUserId}`,
- },
- isProfileResolved && {
- type: "hydrate",
- data: profileRes.value.data,
- path: apiClient.profiles.$url({ query: { id: mayBeUserId } }).pathname,
- key: `profiles.$get,query:id=${mayBeUserId}`,
- },
- isSubscriptionsResolved && {
- type: "hydrate",
- data: subscriptionsRes.value.data,
- path: apiClient.subscriptions.$url({ query: { userId: realUserId } }).pathname,
- key: `subscriptions.$get,query:userId=${realUserId}`,
- },
- ].filter((v) => !!v) as MetaTag[]
- },
-)
+ return [
+ {
+ type: "title",
+ title: name || "",
+ },
+ {
+ type: "description",
+ description:
+ subscriptions.length > 0
+ ? `${name} followed ${subscriptions.length} public subscription${
+ subscriptions.length > 1 ? "s" : ""
+ }. Follow them to get their latest updates on ${APP_NAME}`
+ : "",
+ },
+ {
+ type: "openGraph",
+ title: `${name} on ${APP_NAME}`,
+ image: `${origin}/og/user/${mayBeUserId}`,
+ },
+ {
+ type: "hydrate",
+ data: profileRes.data,
+ path: apiClient.profiles.$url({ query: { id: mayBeUserId } }).pathname,
+ key: `profiles.$get,query:id=${mayBeUserId}`,
+ },
+ isSubscriptionsResolved && {
+ type: "hydrate",
+ data: subscriptionsRes.value.data,
+ path: apiClient.subscriptions.$url({ query: { userId: realUserId } }).pathname,
+ key: `subscriptions.$get,query:userId=${realUserId}`,
+ },
+ ].filter((v) => !!v) as MetaTag[]
+})
diff --git a/apps/ssr/client/router.tsx b/apps/ssr/client/router.tsx
index dfe7d1660..344912828 100644
--- a/apps/ssr/client/router.tsx
+++ b/apps/ssr/client/router.tsx
@@ -2,7 +2,7 @@ import { buildGlobRoutes } from "@follow/utils/route-builder"
import { wrapCreateBrowserRouterV7 } from "@sentry/react"
import { createBrowserRouter, createHashRouter } from "react-router"
-import { NotFound } from "./components/common/NotFound"
+import { NotFound } from "./components/common/404"
const globTree = import.meta.glob("./pages/**/*.tsx")
const tree = buildGlobRoutes(globTree)
diff --git a/apps/ssr/src/lib/not-found.ts b/apps/ssr/src/lib/not-found.ts
new file mode 100644
index 000000000..d8ea4aca0
--- /dev/null
+++ b/apps/ssr/src/lib/not-found.ts
@@ -0,0 +1,8 @@
+export class NotFoundError extends Error {
+ constructor(reason: string) {
+ super(`Page not found: ${reason}`)
+ }
+}
+export const callNotFound = (reason: string) => {
+ throw new NotFoundError(reason)
+}
diff --git a/apps/ssr/src/router/global.ts b/apps/ssr/src/router/global.ts
index eec3db0e4..dfd0f86de 100644
--- a/apps/ssr/src/router/global.ts
+++ b/apps/ssr/src/router/global.ts
@@ -9,6 +9,7 @@ import { FetchError } from "ofetch"
import xss from "xss"
import { isDev } from "~/lib/env"
+import { NotFoundError } from "~/lib/not-found"
import { buildSeoMetaTags } from "~/lib/seo"
import { injectMetaHandler, MetaError } from "../meta-handler"
@@ -102,6 +103,12 @@ async function safeInjectMetaToTemplate(
} catch (e) {
console.error("inject meta error", e)
+ if (e instanceof NotFoundError) {
+ res.code(404)
+ document.documentElement.dataset.notFound = "true"
+ return document
+ }
+
if (e instanceof FetchError && e.response?.status) {
res.code(e.response.status)
}
@@ -114,12 +121,7 @@ async function safeInjectMetaToTemplate(
}
async function injectMetaToTemplate(document: Document, req: FastifyRequest, res: FastifyReply) {
- const injectMetadata = await injectMetaHandler(req, res).catch((err) => {
- if (isDev) {
- throw err
- }
- return []
- })
+ const injectMetadata = await injectMetaHandler(req, res)
if (!injectMetadata) {
return document