From 76a5cfdbfdab6ba752d2f8749d586eb326071433 Mon Sep 17 00:00:00 2001 From: Marius Maaland Date: Thu, 8 Oct 2026 19:15:21 +0200 Subject: [PATCH] Show a styled page for addresses that don't exist (#61) Unknown addresses showed Next's default 404 page. Now they get the site header and footer, "Page not found" with the address asked for, the scan form and a link home, still with a 404 status. Closes #61 Co-Authored-By: Claude Opus 5.5 --- apps/web/src/app/globals.css | 21 +++++++++++++++++++++ apps/web/src/app/not-found.test.tsx | 14 ++++++++++++++ apps/web/src/app/not-found.tsx | 27 +++++++++++++++++++++++++++ apps/web/src/app/requested-path.tsx | 9 +++++++++ 4 files changed, 71 insertions(+) create mode 100644 apps/web/src/app/not-found.test.tsx create mode 100644 apps/web/src/app/not-found.tsx create mode 100644 apps/web/src/app/requested-path.tsx diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index 51cba85..22fea4a 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -313,6 +313,27 @@ a:hover { color: var(--ink-2); } +/* Not found */ + +.not-found { + display: flex; + flex-direction: column; + gap: var(--space-8); + padding-block: var(--space-16) var(--space-24); +} + +.not-found-title { + font-size: var(--text-title); + font-weight: var(--weight-strong); + line-height: var(--leading-tight); + letter-spacing: var(--tracking-title); +} + +.requested-path { + color: var(--ink); + overflow-wrap: anywhere; +} + /* Report: head */ .report { diff --git a/apps/web/src/app/not-found.test.tsx b/apps/web/src/app/not-found.test.tsx new file mode 100644 index 0000000..5dad5ac --- /dev/null +++ b/apps/web/src/app/not-found.test.tsx @@ -0,0 +1,14 @@ +import { renderToStaticMarkup } from 'react-dom/server'; +import { expect, test, vi } from 'vitest'; +import NotFound from './not-found.tsx'; + +vi.mock('next/navigation', () => ({ usePathname: () => '/pricing' })); + +test('says the page is missing, names the address, and offers a scan and the home page', () => { + const html = renderToStaticMarkup(); + expect(html).toContain('

Page not found

'); + expect(html).toContain('/pricing'); + expect(html).toContain('class="scan-form compact"'); + expect(html).toContain('Back to the home page'); + expect(html).toContain('class="site-header"'); +}); diff --git a/apps/web/src/app/not-found.tsx b/apps/web/src/app/not-found.tsx new file mode 100644 index 0000000..35472dd --- /dev/null +++ b/apps/web/src/app/not-found.tsx @@ -0,0 +1,27 @@ +import type { Metadata } from 'next'; +import { RequestedPath } from './requested-path.tsx'; +import { ScanForm } from './scan-form.tsx'; +import { SiteHeader } from './site-chrome.tsx'; + +export const metadata: Metadata = { title: 'Page not found ยท stackprobe' }; + +// Any address that doesn't exist. Next sends it with a 404 status. +export default function NotFound() { + return ( + <> + +
+
+

Page not found

+

+ There's no page at . Scan a domain, or go back to the home page. +

+
+ +

+ Back to the home page +

+
+ + ); +} diff --git a/apps/web/src/app/requested-path.tsx b/apps/web/src/app/requested-path.tsx new file mode 100644 index 0000000..768115e --- /dev/null +++ b/apps/web/src/app/requested-path.tsx @@ -0,0 +1,9 @@ +'use client'; + +import { usePathname } from 'next/navigation'; + +// The address that was asked for, which the not-found page isn't given on the server. +export function RequestedPath() { + const path = usePathname(); + return {path || 'this address'}; +}