Compare commits

10 Commits

Author SHA1 Message Date
denshooter
ede591c89e Fix ActivityFeed hydration error: Move localStorage read to useEffect to prevent server/client mismatch
All checks were successful
Production Deployment (Zero Downtime) / deploy-production (push) Successful in 12m10s
2026-01-10 18:28:25 +01:00
denshooter
2defd7a4a9 Fix ActivityFeed: Remove dynamic import that was causing it to disappear in production
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Has been cancelled
2026-01-10 18:16:01 +01:00
denshooter
9cc03bc475 Prevent white screen: wrap ActivityFeed in error boundary and improve ClientProviders error handling
All checks were successful
Dev Deployment (Zero Downtime) / deploy-dev (push) Successful in 13m10s
Production Deployment (Zero Downtime) / deploy-production (push) Successful in 11m4s
2026-01-10 17:08:16 +01:00
denshooter
832b468ea7 Fix white screen: add error boundaries and improve error handling in AnalyticsProvider and useWebVitals 2026-01-10 17:07:00 +01:00
denshooter
2a260abe0a Fix ActivityFeed fetch TypeError: add proper error handling and type safety 2026-01-10 17:03:07 +01:00
denshooter
80f2ac61ac Fix type error in KernelPanic404: update currentMusic type to match return type 2026-01-10 16:55:01 +01:00
denshooter
a980ee8fcd Fix runtime errors: PerformanceObserver, localStorage, crypto.randomUUID, hydration issues, and linting errors 2026-01-10 16:54:28 +01:00
denshooter
ca2ed13446 refactor: enhance error handling and performance tracking across components
- Improve localStorage access in ActivityFeed, ChatWidget, and AdminPage with try-catch blocks to handle potential errors gracefully.
- Update performance tracking in AnalyticsProvider and analytics.ts to ensure robust error handling and prevent failures from affecting user experience.
- Refactor Web Vitals tracking to include error handling for observer initialization and data collection.
- Ensure consistent handling of hydration mismatches in components like BackgroundBlobs and ChatWidget to improve rendering reliability.
2026-01-10 16:53:06 +01:00
denshooter
20f0ccb85b refactor: improve 404 page loading experience and styling
- Replace Suspense with useEffect for better control over component mounting.
- Update loading indicators with fixed positioning and enhanced styling for a terminal-like appearance.
- Modify KernelPanic404 component to improve text color handling and ensure proper visibility.
- Introduce checks for 404 page detection based on pathname and data attributes for more accurate rendering.
2026-01-10 03:41:22 +01:00
denshooter
59cc8ee154 refactor: consolidate contact API logic and enhance error handling
- Migrate contact API from route.tsx to route.ts for improved organization.
- Implement filtering, pagination, and rate limiting for GET and POST requests.
- Enhance error handling for database operations, including graceful handling of missing tables.
- Validate input fields and email format in POST requests to ensure data integrity.
2026-01-10 03:13:03 +01:00
24 changed files with 2786 additions and 559 deletions

View File

@@ -38,7 +38,8 @@ export async function GET(request: NextRequest) {
cls: ((p.performance as Record<string, unknown>)?.coreWebVitals as Record<string, unknown>)?.cls as number || 0 cls: ((p.performance as Record<string, unknown>)?.coreWebVitals as Record<string, unknown>)?.cls as number || 0
})); }));
const avgLighthouse = projectsWithPerformance.length > 0 // Calculate average lighthouse score (currently unused but kept for future use)
const _avgLighthouse = projectsWithPerformance.length > 0
? Math.round(projectsWithPerformance.reduce((sum, p) => sum + p.lighthouse, 0) / projectsWithPerformance.length) ? Math.round(projectsWithPerformance.reduce((sum, p) => sum + p.lighthouse, 0) / projectsWithPerformance.length)
: 0; : 0;

View File

@@ -152,6 +152,7 @@ export async function POST(request: NextRequest) {
} }
} }
} }
}
// Track session data (for bounce rate calculation) // Track session data (for bounce rate calculation)
if (type === 'session' && session) { if (type === 'session' && session) {

View File

@@ -1,25 +1,137 @@
import { NextRequest, NextResponse } from 'next/server'; import { type NextRequest, NextResponse } from "next/server";
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
try { try {
// In a real app, you would check for admin session here const { searchParams } = new URL(request.url);
// For now, we trust the 'x-admin-request' header if it's set by the server-side component or middleware const filter = searchParams.get('filter') || 'all';
// but typically you'd verify the session cookie/token const limit = parseInt(searchParams.get('limit') || '50');
const offset = parseInt(searchParams.get('offset') || '0');
const contacts = await prisma.contact.findMany({ let whereClause = {};
orderBy: {
createdAt: 'desc', switch (filter) {
}, case 'unread':
take: 100, whereClause = { responded: false };
break;
case 'responded':
whereClause = { responded: true };
break;
default:
whereClause = {};
}
const [contacts, total] = await Promise.all([
prisma.contact.findMany({
where: whereClause,
orderBy: { createdAt: 'desc' },
take: limit,
skip: offset,
}),
prisma.contact.count({ where: whereClause })
]);
return NextResponse.json({
contacts,
total,
hasMore: offset + contacts.length < total
}); });
return NextResponse.json({ contacts });
} catch (error) { } catch (error) {
// Handle missing database table gracefully
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
if (process.env.NODE_ENV === 'development') {
console.warn('Contact table does not exist. Returning empty result.');
}
return NextResponse.json({
contacts: [],
total: 0,
hasMore: false
});
}
if (process.env.NODE_ENV === 'development') {
console.error('Error fetching contacts:', error); console.error('Error fetching contacts:', error);
}
return NextResponse.json( return NextResponse.json(
{ error: 'Failed to fetch contacts' }, { error: 'Failed to fetch contacts' },
{ status: 500 } { status: 500 }
); );
} }
} }
export async function POST(request: NextRequest) {
try {
// Rate limiting for POST requests
const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
if (!checkRateLimit(ip, 5, 60000)) { // 5 requests per minute
return new NextResponse(
JSON.stringify({ error: 'Rate limit exceeded' }),
{
status: 429,
headers: {
'Content-Type': 'application/json',
...getRateLimitHeaders(ip, 5, 60000)
}
}
);
}
const body = await request.json();
const { name, email, subject, message } = body;
// Validate required fields
if (!name || !email || !subject || !message) {
return NextResponse.json(
{ error: 'All fields are required' },
{ status: 400 }
);
}
// Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
return NextResponse.json(
{ error: 'Invalid email format' },
{ status: 400 }
);
}
const contact = await prisma.contact.create({
data: {
name,
email,
subject,
message,
responded: false
}
});
return NextResponse.json({
message: 'Contact created successfully',
contact
}, { status: 201 });
} catch (error) {
// Handle missing database table gracefully
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
if (process.env.NODE_ENV === 'development') {
console.warn('Contact table does not exist.');
}
return NextResponse.json(
{ error: 'Database table not found. Please run migrations.' },
{ status: 503 }
);
}
if (process.env.NODE_ENV === 'development') {
console.error('Error creating contact:', error);
}
return NextResponse.json(
{ error: 'Failed to create contact' },
{ status: 500 }
);
}
}

View File

@@ -1,139 +0,0 @@
import { type NextRequest, NextResponse } from "next/server";
import { PrismaClient } from '@prisma/client';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
const prisma = new PrismaClient();
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const filter = searchParams.get('filter') || 'all';
const limit = parseInt(searchParams.get('limit') || '50');
const offset = parseInt(searchParams.get('offset') || '0');
let whereClause = {};
switch (filter) {
case 'unread':
whereClause = { responded: false };
break;
case 'responded':
whereClause = { responded: true };
break;
default:
whereClause = {};
}
const [contacts, total] = await Promise.all([
prisma.contact.findMany({
where: whereClause,
orderBy: { createdAt: 'desc' },
take: limit,
skip: offset,
}),
prisma.contact.count({ where: whereClause })
]);
return NextResponse.json({
contacts,
total,
hasMore: offset + contacts.length < total
});
} catch (error) {
// Handle missing database table gracefully
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
if (process.env.NODE_ENV === 'development') {
console.warn('Contact table does not exist. Returning empty result.');
}
return NextResponse.json({
contacts: [],
total: 0,
hasMore: false
});
}
if (process.env.NODE_ENV === 'development') {
console.error('Error fetching contacts:', error);
}
return NextResponse.json(
{ error: 'Failed to fetch contacts' },
{ status: 500 }
);
}
}
export async function POST(request: NextRequest) {
try {
// Rate limiting for POST requests
const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
if (!checkRateLimit(ip, 5, 60000)) { // 5 requests per minute
return new NextResponse(
JSON.stringify({ error: 'Rate limit exceeded' }),
{
status: 429,
headers: {
'Content-Type': 'application/json',
...getRateLimitHeaders(ip, 5, 60000)
}
}
);
}
const body = await request.json();
const { name, email, subject, message } = body;
// Validate required fields
if (!name || !email || !subject || !message) {
return NextResponse.json(
{ error: 'All fields are required' },
{ status: 400 }
);
}
// Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
return NextResponse.json(
{ error: 'Invalid email format' },
{ status: 400 }
);
}
const contact = await prisma.contact.create({
data: {
name,
email,
subject,
message,
responded: false
}
});
return NextResponse.json({
message: 'Contact created successfully',
contact
}, { status: 201 });
} catch (error) {
// Handle missing database table gracefully
if (error instanceof PrismaClientKnownRequestError && error.code === 'P2021') {
if (process.env.NODE_ENV === 'development') {
console.warn('Contact table does not exist.');
}
return NextResponse.json(
{ error: 'Database table not found. Please run migrations.' },
{ status: 503 }
);
}
if (process.env.NODE_ENV === 'development') {
console.error('Error creating contact:', error);
}
return NextResponse.json(
{ error: 'Failed to create contact' },
{ status: 500 }
);
}
}

View File

@@ -50,61 +50,116 @@ interface StatusData {
} }
export default function ActivityFeed() { export default function ActivityFeed() {
const [mounted, setMounted] = useState(false);
const [data, setData] = useState<StatusData | null>(null); const [data, setData] = useState<StatusData | null>(null);
const [isExpanded, setIsExpanded] = useState(true); const [isExpanded, setIsExpanded] = useState(true);
const [isMinimized, setIsMinimized] = useState(false); const [isMinimized, setIsMinimized] = useState(false);
const [hasActivity, setHasActivity] = useState(false); const [hasActivity, setHasActivity] = useState(false);
const [isTrackingEnabled, setIsTrackingEnabled] = useState(() => { // Initialize with default value to prevent hydration mismatch
// Check localStorage for tracking preference const [isTrackingEnabled, setIsTrackingEnabled] = useState(true);
if (typeof window !== "undefined") {
const stored = localStorage.getItem("activityTrackingEnabled");
return stored !== "false"; // Default to true if not set
}
return true;
});
const [quote, setQuote] = useState<{ const [quote, setQuote] = useState<{
content: string; content: string;
author: string; author: string;
} | null>(null); } | null>(null);
// Load tracking preference from localStorage after mount to prevent hydration mismatch
useEffect(() => {
setMounted(true);
if (typeof window !== "undefined") {
try {
const stored = localStorage.getItem("activityTrackingEnabled");
setIsTrackingEnabled(stored !== "false"); // Default to true if not set
} catch (error) {
// localStorage might be disabled
if (process.env.NODE_ENV === 'development') {
console.warn('Failed to read tracking preference:', error);
}
setIsTrackingEnabled(true); // Default to enabled
}
}
}, []);
// Fetch data every 30 seconds (optimized to match server cache) // Fetch data every 30 seconds (optimized to match server cache)
useEffect(() => { useEffect(() => {
// Don't fetch if tracking is disabled // Don't fetch if tracking is disabled or during SSR
if (!isTrackingEnabled) { if (!isTrackingEnabled || typeof window === 'undefined') {
return; return;
} }
const fetchData = async () => { const fetchData = async () => {
try { try {
// Check if fetch is available (should be, but safety check)
if (typeof fetch === 'undefined') {
return;
}
// Add timestamp to prevent aggressive caching but respect server cache // Add timestamp to prevent aggressive caching but respect server cache
const res = await fetch("/api/n8n/status", { const res = await fetch("/api/n8n/status", {
cache: "default", cache: "default",
}).catch((fetchError) => {
// Handle network errors gracefully
if (process.env.NODE_ENV === 'development') {
console.warn('ActivityFeed: Fetch failed:', fetchError);
}
return null;
}); });
if (!res.ok) return;
let json = await res.json();
if (!res || !res.ok) {
if (process.env.NODE_ENV === 'development' && res) {
console.warn('ActivityFeed: API returned non-OK status:', res.status);
}
return;
}
let json: unknown;
try {
json = await res.json();
} catch (parseError) {
if (process.env.NODE_ENV === 'development') {
console.warn('ActivityFeed: Failed to parse JSON response:', parseError);
}
return;
}
if (process.env.NODE_ENV === 'development') {
console.log("ActivityFeed data (raw):", json); console.log("ActivityFeed data (raw):", json);
}
// Handle array response if API returns it wrapped // Handle array response if API returns it wrapped
if (Array.isArray(json)) { if (Array.isArray(json)) {
json = json[0] || null; json = json[0] || null;
} }
if (process.env.NODE_ENV === 'development') {
console.log("ActivityFeed data (processed):", json); console.log("ActivityFeed data (processed):", json);
}
setData(json); if (!json || typeof json !== 'object') {
return;
}
// Type assertion - API should return StatusData format
const activityData = json as StatusData;
setData(activityData);
// Check if there's any active activity // Check if there's any active activity
const hasActiveActivity = const coding = activityData.coding;
json.coding?.isActive || const gaming = activityData.gaming;
json.gaming?.isPlaying || const music = activityData.music;
json.music?.isPlaying;
const hasActiveActivity = Boolean(
coding?.isActive ||
gaming?.isPlaying ||
music?.isPlaying
);
if (process.env.NODE_ENV === 'development') {
console.log("Has activity:", hasActiveActivity, { console.log("Has activity:", hasActiveActivity, {
coding: json.coding?.isActive, coding: coding?.isActive,
gaming: json.gaming?.isPlaying, gaming: gaming?.isPlaying,
music: json.music?.isPlaying, music: music?.isPlaying,
}); });
}
setHasActivity(hasActiveActivity); setHasActivity(hasActiveActivity);
@@ -112,8 +167,12 @@ export default function ActivityFeed() {
if (hasActiveActivity && !isMinimized) { if (hasActiveActivity && !isMinimized) {
setIsExpanded(true); setIsExpanded(true);
} }
} catch (e) { } catch (error) {
console.error("Failed to fetch activity", e); // Silently fail - activity feed is not critical
if (process.env.NODE_ENV === 'development') {
console.error("Failed to fetch activity:", error);
}
// Don't set error state - just fail silently
} }
}; };
@@ -1385,7 +1444,14 @@ export default function ActivityFeed() {
const newValue = !isTrackingEnabled; const newValue = !isTrackingEnabled;
setIsTrackingEnabled(newValue); setIsTrackingEnabled(newValue);
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
try {
localStorage.setItem("activityTrackingEnabled", String(newValue)); localStorage.setItem("activityTrackingEnabled", String(newValue));
} catch (error) {
// localStorage might be full or disabled
if (process.env.NODE_ENV === 'development') {
console.warn('Failed to save tracking preference:', error);
}
}
} }
// Clear data when disabling // Clear data when disabling
if (!newValue) { if (!newValue) {
@@ -1394,6 +1460,9 @@ export default function ActivityFeed() {
} }
}; };
// Don't render until mounted to prevent hydration mismatch
if (!mounted) return null;
// Don't render if tracking is disabled and no data // Don't render if tracking is disabled and no data
if (!isTrackingEnabled && !data) return null; if (!isTrackingEnabled && !data) return null;

View File

@@ -20,21 +20,47 @@ interface Message {
} }
export default function ChatWidget() { export default function ChatWidget() {
// Prevent hydration mismatch by only rendering after mount
const [mounted, setMounted] = useState(false);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [messages, setMessages] = useState<Message[]>([]); const [messages, setMessages] = useState<Message[]>([]);
const [inputValue, setInputValue] = useState(""); const [inputValue, setInputValue] = useState("");
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [conversationId, setConversationId] = useState(() => { const [conversationId, setConversationId] = useState<string>("default");
// Generate or retrieve conversation ID
if (typeof window !== "undefined") { useEffect(() => {
setMounted(true);
// Generate or retrieve conversation ID only on client
try {
const stored = localStorage.getItem("chatSessionId"); const stored = localStorage.getItem("chatSessionId");
if (stored) return stored; if (stored) {
const newId = crypto.randomUUID(); setConversationId(stored);
localStorage.setItem("chatSessionId", newId); return;
return newId;
} }
return "default";
// Generate UUID with fallback for browsers without crypto.randomUUID
let newId: string;
if (typeof crypto !== "undefined" && crypto.randomUUID) {
newId = crypto.randomUUID();
} else {
// Fallback UUID generation
newId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}); });
}
localStorage.setItem("chatSessionId", newId);
setConversationId(newId);
} catch (error) {
// localStorage might be disabled or full
if (process.env.NODE_ENV === 'development') {
console.warn('Failed to access localStorage for chat session:', error);
}
setConversationId(`session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);
}
}, []);
const messagesEndRef = useRef<HTMLDivElement>(null); const messagesEndRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
@@ -62,6 +88,7 @@ export default function ChatWidget() {
// Load messages from localStorage // Load messages from localStorage
useEffect(() => { useEffect(() => {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
try {
const stored = localStorage.getItem("chatMessages"); const stored = localStorage.getItem("chatMessages");
if (stored) { if (stored) {
try { try {
@@ -74,7 +101,24 @@ export default function ChatWidget() {
})), })),
); );
} catch (e) { } catch (e) {
console.error("Failed to load chat history", e); if (process.env.NODE_ENV === 'development') {
console.error("Failed to parse chat history", e);
}
// Clear corrupted data
try {
localStorage.removeItem("chatMessages");
} catch {
// Ignore cleanup errors
}
// Add welcome message
setMessages([
{
id: "welcome",
text: "Hi! I'm Dennis's AI assistant. Ask me anything about his skills, projects, or experience! 🚀",
sender: "bot",
timestamp: new Date(),
},
]);
} }
} else { } else {
// Add welcome message // Add welcome message
@@ -87,13 +131,35 @@ export default function ChatWidget() {
}, },
]); ]);
} }
} catch (error) {
// localStorage might be disabled
if (process.env.NODE_ENV === 'development') {
console.warn("Failed to load chat history from localStorage:", error);
}
// Add welcome message anyway
setMessages([
{
id: "welcome",
text: "Hi! I'm Dennis's AI assistant. Ask me anything about his skills, projects, or experience! 🚀",
sender: "bot",
timestamp: new Date(),
},
]);
}
} }
}, []); }, []);
// Save messages to localStorage // Save messages to localStorage
useEffect(() => { useEffect(() => {
if (typeof window !== "undefined" && messages.length > 0) { if (typeof window !== "undefined" && messages.length > 0) {
try {
localStorage.setItem("chatMessages", JSON.stringify(messages)); localStorage.setItem("chatMessages", JSON.stringify(messages));
} catch (error) {
// localStorage might be full or disabled
if (process.env.NODE_ENV === 'development') {
console.warn("Failed to save chat messages to localStorage:", error);
}
}
} }
}, [messages]); }, [messages]);
@@ -204,6 +270,11 @@ export default function ChatWidget() {
]); ]);
}; };
// Don't render until mounted to prevent hydration mismatch
if (!mounted) {
return null;
}
return ( return (
<> <>
{/* Chat Button */} {/* Chat Button */}

View File

@@ -1,13 +1,22 @@
"use client"; "use client";
import React, { useEffect, useState, Suspense, lazy } from "react"; import React, { useEffect, useState } from "react";
import { usePathname } from "next/navigation"; import { usePathname } from "next/navigation";
import dynamic from "next/dynamic";
import { ToastProvider } from "@/components/Toast"; import { ToastProvider } from "@/components/Toast";
import ErrorBoundary from "@/components/ErrorBoundary";
import { AnalyticsProvider } from "@/components/AnalyticsProvider"; import { AnalyticsProvider } from "@/components/AnalyticsProvider";
// Lazy load heavy components to avoid webpack issues // Dynamic import with SSR disabled to avoid framer-motion issues
const BackgroundBlobs = lazy(() => import("@/components/BackgroundBlobs")); const BackgroundBlobs = dynamic(() => import("@/components/BackgroundBlobs").catch(() => ({ default: () => null })), {
const ChatWidget = lazy(() => import("./ChatWidget")); ssr: false,
loading: () => null,
});
const ChatWidget = dynamic(() => import("./ChatWidget").catch(() => ({ default: () => null })), {
ssr: false,
loading: () => null,
});
export default function ClientProviders({ export default function ClientProviders({
children, children,
@@ -16,37 +25,61 @@ export default function ClientProviders({
}) { }) {
const [mounted, setMounted] = useState(false); const [mounted, setMounted] = useState(false);
const [is404Page, setIs404Page] = useState(false); const [is404Page, setIs404Page] = useState(false);
const pathname = usePathname();
useEffect(() => { useEffect(() => {
setMounted(true); setMounted(true);
// Check if we're on a 404 page by looking for the data attribute // Check if we're on a 404 page by looking for the data attribute or pathname
const check404 = () => { const check404 = () => {
if (typeof window !== "undefined") { try {
if (typeof window !== "undefined" && typeof document !== "undefined") {
const has404Component = document.querySelector('[data-404-page]'); const has404Component = document.querySelector('[data-404-page]');
setIs404Page(!!has404Component); const is404Path = pathname === '/404' || (window.location && (window.location.pathname === '/404' || window.location.pathname.includes('404')));
setIs404Page(!!has404Component || is404Path);
}
} catch (error) {
// Silently fail - 404 detection is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('Error checking 404 status:', error);
}
} }
}; };
// Check immediately and after a short delay // Check immediately and after a short delay
try {
check404(); check404();
const timeout = setTimeout(check404, 100); const timeout = setTimeout(check404, 100);
return () => clearTimeout(timeout); const interval = setInterval(check404, 500);
}, []); return () => {
try {
clearTimeout(timeout);
clearInterval(interval);
} catch {
// Silently fail during cleanup
}
};
} catch (error) {
// If setup fails, just return empty cleanup
if (process.env.NODE_ENV === 'development') {
console.warn('Error setting up 404 check:', error);
}
return () => {};
}
}, [pathname]);
// Wrap in multiple error boundaries to isolate failures
return ( return (
<ErrorBoundary>
<ErrorBoundary>
<AnalyticsProvider> <AnalyticsProvider>
<ErrorBoundary>
<ToastProvider> <ToastProvider>
{mounted && ( {mounted && <BackgroundBlobs />}
<Suspense fallback={null}>
<BackgroundBlobs />
</Suspense>
)}
<div className="relative z-10">{children}</div> <div className="relative z-10">{children}</div>
{mounted && !is404Page && ( {mounted && !is404Page && <ChatWidget />}
<Suspense fallback={null}>
<ChatWidget />
</Suspense>
)}
</ToastProvider> </ToastProvider>
</ErrorBoundary>
</AnalyticsProvider> </AnalyticsProvider>
</ErrorBoundary>
</ErrorBoundary>
); );
} }

View File

@@ -8,6 +8,7 @@ export default function KernelPanic404() {
const inputContainerRef = useRef<HTMLDivElement>(null); const inputContainerRef = useRef<HTMLDivElement>(null);
const overlayRef = useRef<HTMLDivElement>(null); const overlayRef = useRef<HTMLDivElement>(null);
const bodyRef = useRef<HTMLDivElement>(null); // We'll use a wrapper div instead of document.body for some effects if possible, but strict effects might need body. const bodyRef = useRef<HTMLDivElement>(null); // We'll use a wrapper div instead of document.body for some effects if possible, but strict effects might need body.
const bootStartedRef = useRef(false);
useEffect(() => { useEffect(() => {
/* --- SYSTEM CORE --- */ /* --- SYSTEM CORE --- */
@@ -21,20 +22,24 @@ export default function KernelPanic404() {
if (!output || !input || !inputContainer || !overlay) return; if (!output || !input || !inputContainer || !overlay) return;
// Prevent double initialization - check if boot already started or output has content
if (bootStartedRef.current || output.children.length > 0) return;
bootStartedRef.current = true;
let audioCtx: AudioContext | null = null; let audioCtx: AudioContext | null = null;
let systemFrozen = false; let systemFrozen = false;
let currentMusic: any = null; let currentMusic: { stop: () => void } | null = null;
let hawkinsActive = false; let hawkinsActive = false;
let fsocietyActive = false; let fsocietyActive = false;
// Timers storage to clear on unmount // Timers storage to clear on unmount
const timers: (NodeJS.Timeout | number)[] = []; const timers: (NodeJS.Timeout | number)[] = [];
const interval = (fn: Function, ms: number) => { const interval = (fn: () => void, ms: number) => {
const id = setInterval(fn, ms); const id = setInterval(fn, ms);
timers.push(id); timers.push(id);
return id; return id;
}; };
const timeout = (fn: Function, ms: number) => { const timeout = (fn: () => void, ms: number) => {
const id = setTimeout(fn, ms); const id = setTimeout(fn, ms);
timers.push(id); timers.push(id);
return id; return id;
@@ -44,7 +49,7 @@ export default function KernelPanic404() {
function initAudio() { function initAudio() {
if (!audioCtx) { if (!audioCtx) {
const AudioContextClass = const AudioContextClass =
window.AudioContext || (window as any).webkitAudioContext; window.AudioContext || (window as typeof window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
if (AudioContextClass) { if (AudioContextClass) {
audioCtx = new AudioContextClass(); audioCtx = new AudioContextClass();
} }
@@ -439,6 +444,7 @@ export default function KernelPanic404() {
} }
/* --- FILE SYSTEM --- */ /* --- FILE SYSTEM --- */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fileSystem: any = { const fileSystem: any = {
home: { home: {
type: "dir", type: "dir",
@@ -546,7 +552,7 @@ export default function KernelPanic404() {
let currentPath = fileSystem.home.children.guest; let currentPath = fileSystem.home.children.guest;
let pathStr = "~"; let pathStr = "~";
let commandHistory: string[] = []; const commandHistory: string[] = [];
let historyIndex = -1; let historyIndex = -1;
/* --- UTILS --- */ /* --- UTILS --- */
@@ -554,12 +560,19 @@ export default function KernelPanic404() {
if (!output) return; if (!output) return;
const d = document.createElement("div"); const d = document.createElement("div");
d.innerHTML = text; d.innerHTML = text;
if (type === "log-warn") d.style.color = "#ffb000"; // Default color for normal text - use setProperty with important to override globals.css
if (!type || (type !== "log-warn" && type !== "log-err" && type !== "alert" && type !== "log-sys" && type !== "log-k" && type !== "log-dim")) {
d.style.setProperty("color", "var(--phosphor)", "important");
}
if (type === "log-warn") d.style.setProperty("color", "#ffb000", "important");
if (type === "log-err" || type === "alert") if (type === "log-err" || type === "alert")
d.style.color = "var(--alert)"; d.style.setProperty("color", "var(--alert)", "important");
if (type === "log-dim") d.style.opacity = "0.6"; if (type === "log-dim") {
if (type === "log-sys") d.style.color = "cyan"; d.style.opacity = "0.6";
if (type === "log-k") d.style.color = "#fff"; d.style.setProperty("color", "var(--phosphor)", "important");
}
if (type === "log-sys") d.style.setProperty("color", "cyan", "important");
if (type === "log-k") d.style.setProperty("color", "#fff", "important");
if (type === "pulse-red") d.classList.add("pulse-red"); if (type === "pulse-red") d.classList.add("pulse-red");
if (type === "fsociety-mask") d.classList.add("fsociety-mask"); if (type === "fsociety-mask") d.classList.add("fsociety-mask");
if (type === "memory-error") d.classList.add("memory-error"); if (type === "memory-error") d.classList.add("memory-error");
@@ -659,7 +672,7 @@ export default function KernelPanic404() {
// Clear initial output // Clear initial output
output!.innerHTML = ""; output!.innerHTML = "";
for (let msg of bootMessages) { for (const msg of bootMessages) {
printLine(msg.t, msg.type); printLine(msg.t, msg.type);
await sleep(msg.d); await sleep(msg.d);
} }
@@ -782,7 +795,7 @@ export default function KernelPanic404() {
if (suggestions.length === 0) { if (suggestions.length === 0) {
try { try {
playSynth("beep"); playSynth("beep");
} catch (e) {} } catch {}
return; return;
} }
@@ -805,13 +818,13 @@ export default function KernelPanic404() {
input.setSelectionRange(input.value.length, input.value.length); input.setSelectionRange(input.value.length, input.value.length);
try { try {
playSynth("beep"); playSynth("beep");
} catch (e) {} } catch {}
} else { } else {
// Multiple matches // Multiple matches
printLine(`Possible completions: ${suggestions.join(" ")}`, "log-dim"); printLine(`Possible completions: ${suggestions.join(" ")}`, "log-dim");
try { try {
playSynth("beep"); playSynth("beep");
} catch (e) {} } catch {}
} }
} }
@@ -820,7 +833,7 @@ export default function KernelPanic404() {
if (systemFrozen || !input) { if (systemFrozen || !input) {
try { try {
playSynth("beep"); playSynth("beep");
} catch (e) {} } catch {}
return; return;
} }
@@ -859,7 +872,7 @@ export default function KernelPanic404() {
args.includes("-a") || args.includes("-la") || args.includes("-l"); args.includes("-a") || args.includes("-la") || args.includes("-l");
const longFormat = args.includes("-l") || args.includes("-la"); const longFormat = args.includes("-l") || args.includes("-la");
let items = Object.keys(currentPath.children).filter( const items = Object.keys(currentPath.children).filter(
(n) => !n.startsWith(".") || showHidden, (n) => !n.startsWith(".") || showHidden,
); );
@@ -1165,7 +1178,7 @@ export default function KernelPanic404() {
overlay.style.display = "none"; overlay.style.display = "none";
overlay.innerHTML = ""; overlay.innerHTML = "";
const sporeInterval = interval(() => { const _sporeInterval = interval(() => {
const spore = document.createElement("div"); const spore = document.createElement("div");
spore.className = "spore"; spore.className = "spore";
spore.style.left = Math.random() * 100 + "%"; spore.style.left = Math.random() * 100 + "%";
@@ -1175,7 +1188,7 @@ export default function KernelPanic404() {
setTimeout(() => spore.remove(), 3000); setTimeout(() => spore.remove(), 3000);
}, 300); }, 300);
const glitchInterval = interval(() => { const _glitchInterval = interval(() => {
if (!hawkinsActive) return; if (!hawkinsActive) return;
body.style.filter = "hue-rotate(180deg) contrast(1.3) brightness(0.9)"; body.style.filter = "hue-rotate(180deg) contrast(1.3) brightness(0.9)";
setTimeout( setTimeout(
@@ -1400,7 +1413,7 @@ export default function KernelPanic404() {
try { try {
playSynth("key"); playSynth("key");
} catch (e) {} } catch {}
if (e.key === "ArrowUp" && historyIndex > 0) { if (e.key === "ArrowUp" && historyIndex > 0) {
historyIndex--; historyIndex--;
@@ -1442,18 +1455,40 @@ export default function KernelPanic404() {
--phosphor: #33ff00; --phosphor: #33ff00;
--phosphor-sec: #008f11; --phosphor-sec: #008f11;
--alert: #ff3333; --alert: #ff3333;
--font: "Courier New", Courier, monospace; --font: 'Courier New', Courier, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background-color: var(--bg-color);
margin: 0;
height: 100vh;
overflow: hidden;
font-family: var(--font);
color: var(--phosphor);
user-select: none;
cursor: default;
transition: filter 0.5s, transform 0.5s;
} }
/* --- CRT EFFECTS --- */ /* --- CRT EFFECTS --- */
.crt-wrap { .crt-wrap {
width: 100%; width: 100%;
height: 100vh; height: 100%;
padding: 30px; padding: 30px;
box-sizing: border-box; box-sizing: border-box;
background: radial-gradient(circle at center, #111 0%, #000 100%); background: radial-gradient(circle at center, #111 0%, #000 100%);
position: relative; position: relative;
overflow: hidden; }
/* Override globals.css div color rule for 404 page - must be very specific */
html body:has([data-404-page]) .crt-wrap,
html body:has([data-404-page]) .crt-wrap *,
html body:has([data-404-page]) #output,
html body:has([data-404-page]) #output div,
html body:has([data-404-page]) #output * {
color: var(--phosphor) !important;
} }
.crt-wrap::before { .crt-wrap::before {
@@ -1463,25 +1498,22 @@ export default function KernelPanic404() {
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
linear-gradient( background-size: 100% 4px, 3px 100%;
90deg,
rgba(255, 0, 0, 0.06),
rgba(0, 255, 0, 0.02),
rgba(0, 0, 255, 0.06)
);
background-size:
100% 4px,
3px 100%;
pointer-events: none; pointer-events: none;
z-index: 90; z-index: 90;
} }
.glow { .glow {
text-shadow: text-shadow: 0 0 2px var(--phosphor-sec), 0 0 8px var(--phosphor);
0 0 2px var(--phosphor-sec), }
0 0 8px var(--phosphor);
/* Hide chat widget on 404 page */
body:has([data-404-page]) [data-chat-widget] {
display: none !important;
visibility: hidden !important;
opacity: 0 !important;
} }
/* --- TERMINAL --- */ /* --- TERMINAL --- */
@@ -1502,7 +1534,6 @@ export default function KernelPanic404() {
margin-bottom: 20px; margin-bottom: 20px;
font-size: 1.1rem; font-size: 1.1rem;
line-height: 1.4; line-height: 1.4;
color: var(--phosphor);
} }
#output::-webkit-scrollbar { #output::-webkit-scrollbar {
@@ -1522,7 +1553,6 @@ export default function KernelPanic404() {
margin-right: 10px; margin-right: 10px;
font-weight: bold; font-weight: bold;
white-space: nowrap; white-space: nowrap;
color: var(--phosphor);
} }
#cmd-input { #cmd-input {
@@ -1847,7 +1877,7 @@ export default function KernelPanic404() {
<div id="flash-overlay" ref={overlayRef}></div> <div id="flash-overlay" ref={overlayRef}></div>
<div className="crt-wrap glow" ref={bodyRef}> <div className="crt-wrap glow" ref={bodyRef} data-404-page="true">
<div id="terminal"> <div id="terminal">
<div id="output" ref={outputRef}></div> <div id="output" ref={outputRef}></div>
<div <div

View File

@@ -0,0 +1,41 @@
"use client";
import { useEffect } from "react";
export default function KernelPanic404Wrapper() {
useEffect(() => {
// Ensure body and html don't interfere
document.body.style.background = "#020202";
document.body.style.color = "#33ff00";
document.documentElement.style.background = "#020202";
document.documentElement.style.color = "#33ff00";
return () => {
// Cleanup
document.body.style.background = "";
document.body.style.color = "";
document.documentElement.style.background = "";
document.documentElement.style.color = "";
};
}, []);
return (
<iframe
src="/404-terminal.html"
style={{
position: "fixed",
top: 0,
left: 0,
width: "100vw",
height: "100vh",
border: "none",
zIndex: 9999,
margin: 0,
padding: 0,
backgroundColor: "#020202",
}}
data-404-page="true"
allowTransparency={false}
/>
);
}

View File

@@ -2,7 +2,7 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { motion, Variants } from "framer-motion"; import { motion, Variants } from "framer-motion";
import { ExternalLink, Github, Layers, ArrowRight, ArrowLeft, Calendar } from "lucide-react"; import { ExternalLink, Github, ArrowRight, Calendar } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import Image from "next/image"; import Image from "next/image";

View File

@@ -59,7 +59,7 @@ function EditorPageContent() {
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
const [isCreating, setIsCreating] = useState(!projectId); const [isCreating, setIsCreating] = useState(!projectId);
const [showPreview, setShowPreview] = useState(false); const [showPreview, setShowPreview] = useState(false);
const [isTyping, setIsTyping] = useState(false); const [_isTyping, setIsTyping] = useState(false);
const [history, setHistory] = useState<typeof formData[]>([]); const [history, setHistory] = useState<typeof formData[]>([]);
const [historyIndex, setHistoryIndex] = useState(-1); const [historyIndex, setHistoryIndex] = useState(-1);
const [originalFormData, setOriginalFormData] = useState<typeof formData | null>(null); const [originalFormData, setOriginalFormData] = useState<typeof formData | null>(null);

View File

@@ -57,6 +57,9 @@ const AdminPage = () => {
// Check if user is locked out // Check if user is locked out
const checkLockout = useCallback(() => { const checkLockout = useCallback(() => {
if (typeof window === 'undefined') return false;
try {
const lockoutData = localStorage.getItem('admin_lockout'); const lockoutData = localStorage.getItem('admin_lockout');
if (lockoutData) { if (lockoutData) {
try { try {
@@ -72,10 +75,24 @@ const AdminPage = () => {
})); }));
return true; return true;
} else { } else {
try {
localStorage.removeItem('admin_lockout'); localStorage.removeItem('admin_lockout');
} catch {
// Ignore errors
}
} }
} catch { } catch {
try {
localStorage.removeItem('admin_lockout'); localStorage.removeItem('admin_lockout');
} catch {
// Ignore errors
}
}
}
} catch (error) {
// localStorage might be disabled
if (process.env.NODE_ENV === 'development') {
console.warn('Failed to check lockout status:', error);
} }
} }
return false; return false;
@@ -197,7 +214,11 @@ const AdminPage = () => {
attempts: 0, attempts: 0,
isLoading: false isLoading: false
})); }));
try {
localStorage.removeItem('admin_lockout'); localStorage.removeItem('admin_lockout');
} catch {
// Ignore errors
}
} else { } else {
const newAttempts = authState.attempts + 1; const newAttempts = authState.attempts + 1;
setAuthState(prev => ({ setAuthState(prev => ({
@@ -208,10 +229,17 @@ const AdminPage = () => {
})); }));
if (newAttempts >= 5) { if (newAttempts >= 5) {
try {
localStorage.setItem('admin_lockout', JSON.stringify({ localStorage.setItem('admin_lockout', JSON.stringify({
timestamp: Date.now(), timestamp: Date.now(),
attempts: newAttempts attempts: newAttempts
})); }));
} catch (error) {
// localStorage might be full or disabled
if (process.env.NODE_ENV === 'development') {
console.warn('Failed to save lockout data:', error);
}
}
setAuthState(prev => ({ setAuthState(prev => ({
...prev, ...prev,
isLocked: true, isLocked: true,
@@ -252,7 +280,11 @@ const AdminPage = () => {
<p className="text-stone-500">Too many failed attempts. Please try again in 15 minutes.</p> <p className="text-stone-500">Too many failed attempts. Please try again in 15 minutes.</p>
<button <button
onClick={() => { onClick={() => {
try {
localStorage.removeItem('admin_lockout'); localStorage.removeItem('admin_lockout');
} catch {
// Ignore errors
}
window.location.reload(); window.location.reload();
}} }}
className="mt-4 px-6 py-2 bg-stone-900 text-stone-50 rounded-xl hover:bg-stone-800 transition-colors" className="mt-4 px-6 py-2 bg-stone-900 text-stone-50 rounded-xl hover:bg-stone-800 transition-colors"

View File

@@ -1,30 +1,80 @@
"use client"; "use client";
import { Suspense } from "react"; import { useEffect, useState } from "react";
import dynamic from "next/dynamic"; import dynamic from "next/dynamic";
// Dynamically import KernelPanic404 to avoid SSR issues // Dynamically import KernelPanic404Wrapper to avoid SSR issues
const KernelPanic404 = dynamic(() => import("./components/KernelPanic404"), { const KernelPanic404 = dynamic(() => import("./components/KernelPanic404Wrapper"), {
ssr: false, ssr: false,
loading: () => ( loading: () => (
<div className="flex items-center justify-center min-h-screen bg-black text-[#33ff00] font-mono"> <div style={{
position: "fixed",
top: 0,
left: 0,
width: "100%",
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
backgroundColor: "#020202",
color: "#33ff00",
fontFamily: "monospace"
}}>
<div>Loading terminal...</div> <div>Loading terminal...</div>
</div> </div>
), ),
}); });
export default function NotFound() { export default function NotFound() {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return ( return (
<main className="min-h-screen w-full bg-black overflow-hidden relative"> <div style={{
<Suspense position: "fixed",
fallback={ top: 0,
<div className="flex items-center justify-center min-h-screen bg-black text-[#33ff00] font-mono"> left: 0,
<div>Loading terminal...</div> width: "100vw",
height: "100vh",
margin: 0,
padding: 0,
overflow: "hidden",
backgroundColor: "#020202",
zIndex: 9998
}}>
<div style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "100%",
height: "100%",
color: "#33ff00",
fontFamily: "monospace"
}}>
Loading terminal...
</div>
</div>
);
}
return (
<div style={{
position: "fixed",
top: 0,
left: 0,
width: "100vw",
height: "100vh",
margin: 0,
padding: 0,
overflow: "hidden",
backgroundColor: "#020202",
zIndex: 9998
}}>
<KernelPanic404 />
</div> </div>
}
>
<KernelPanic404 />
</Suspense>
</main>
); );
} }

View File

@@ -7,6 +7,7 @@ import Projects from "./components/Projects";
import Contact from "./components/Contact"; import Contact from "./components/Contact";
import Footer from "./components/Footer"; import Footer from "./components/Footer";
import Script from "next/script"; import Script from "next/script";
import ErrorBoundary from "@/components/ErrorBoundary";
import ActivityFeed from "./components/ActivityFeed"; import ActivityFeed from "./components/ActivityFeed";
import { motion } from "framer-motion"; import { motion } from "framer-motion";
@@ -35,7 +36,9 @@ export default function Home() {
}), }),
}} }}
/> />
<ErrorBoundary>
<ActivityFeed /> <ActivityFeed />
</ErrorBoundary>
<Header /> <Header />
{/* Spacer to prevent navbar overlap */} {/* Spacer to prevent navbar overlap */}
<div className="h-24 md:h-32" aria-hidden="true"></div> <div className="h-24 md:h-32" aria-hidden="true"></div>

View File

@@ -1,12 +1,11 @@
"use client"; "use client";
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { ExternalLink, Calendar, Tag, ArrowLeft, Github as GithubIcon, Share2 } from 'lucide-react'; import { ExternalLink, Calendar, ArrowLeft, Github as GithubIcon, Share2 } from 'lucide-react';
import Link from 'next/link'; import Link from 'next/link';
import { useParams } from 'next/navigation'; import { useParams } from 'next/navigation';
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
import Image from 'next/image';
interface Project { interface Project {
id: number; id: number;

View File

@@ -4,9 +4,7 @@ import { useState, useEffect, useCallback } from 'react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { import {
BarChart3, BarChart3,
TrendingUp,
Eye, Eye,
Heart,
Zap, Zap,
Globe, Globe,
Activity, Activity,

View File

@@ -9,12 +9,16 @@ interface AnalyticsProviderProps {
} }
export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }) => { export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }) => {
// Initialize Web Vitals tracking // Initialize Web Vitals tracking - wrapped to prevent crashes
// Hooks must be called unconditionally, but the hook itself handles errors
useWebVitals(); useWebVitals();
useEffect(() => { useEffect(() => {
if (typeof window === 'undefined') return; if (typeof window === 'undefined') return;
// Wrap entire effect in try-catch to prevent any errors from breaking the app
try {
// Track page view // Track page view
const trackPageView = async () => { const trackPageView = async () => {
const path = window.location.pathname; const path = window.location.pathname;
@@ -49,8 +53,15 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
} }
}; };
// Track page load performance // Track page load performance - wrapped in try-catch
try {
trackPageLoad(); trackPageLoad();
} catch (error) {
// Silently fail
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking page load:', error);
}
}
// Track initial page view // Track initial page view
trackPageView(); trackPageView();
@@ -65,18 +76,19 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Wait for page to fully load // Wait for page to fully load
setTimeout(async () => { setTimeout(async () => {
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming; try {
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming | undefined;
const paintEntries = performance.getEntriesByType('paint'); const paintEntries = performance.getEntriesByType('paint');
const lcpEntries = performance.getEntriesByType('largest-contentful-paint'); const lcpEntries = performance.getEntriesByType('largest-contentful-paint');
const fcp = paintEntries.find((e: PerformanceEntry) => e.name === 'first-contentful-paint'); const fcp = paintEntries.find((e: PerformanceEntry) => e.name === 'first-contentful-paint');
const lcp = lcpEntries[lcpEntries.length - 1]; const lcp = lcpEntries.length > 0 ? lcpEntries[lcpEntries.length - 1] : undefined;
const performanceData = { const performanceData = {
loadTime: navigation ? navigation.loadEventEnd - navigation.fetchStart : 0, loadTime: navigation && navigation.loadEventEnd && navigation.fetchStart ? navigation.loadEventEnd - navigation.fetchStart : 0,
fcp: fcp ? fcp.startTime : 0, fcp: fcp ? fcp.startTime : 0,
lcp: lcp ? lcp.startTime : 0, lcp: lcp ? lcp.startTime : 0,
ttfb: navigation ? navigation.responseStart - navigation.fetchStart : 0, ttfb: navigation && navigation.responseStart && navigation.fetchStart ? navigation.responseStart - navigation.fetchStart : 0,
cls: 0, // Will be updated by CLS observer cls: 0, // Will be updated by CLS observer
fid: 0, // Will be updated by FID observer fid: 0, // Will be updated by FID observer
si: 0 // Speed Index - would need to calculate si: 0 // Speed Index - would need to calculate
@@ -95,6 +107,12 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
performance: performanceData performance: performanceData
}) })
}); });
} catch (error) {
// Silently fail - performance tracking is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('Error collecting performance data:', error);
}
}
}, 2000); // Wait 2 seconds for page to stabilize }, 2000); // Wait 2 seconds for page to stabilize
} catch (error) { } catch (error) {
// Silently fail // Silently fail
@@ -124,8 +142,13 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Track user interactions // Track user interactions
const handleClick = (event: MouseEvent) => { const handleClick = (event: MouseEvent) => {
const target = event.target as HTMLElement; try {
const element = target.tagName.toLowerCase(); if (typeof window === 'undefined') return;
const target = event.target as HTMLElement | null;
if (!target) return;
const element = target.tagName ? target.tagName.toLowerCase() : 'unknown';
const className = target.className; const className = target.className;
const id = target.id; const id = target.id;
@@ -135,23 +158,48 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
id: id || undefined, id: id || undefined,
url: window.location.pathname, url: window.location.pathname,
}); });
} catch (error) {
// Silently fail - click tracking is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking click:', error);
}
}
}; };
// Track form submissions // Track form submissions
const handleSubmit = (event: SubmitEvent) => { const handleSubmit = (event: SubmitEvent) => {
const form = event.target as HTMLFormElement; try {
if (typeof window === 'undefined') return;
const form = event.target as HTMLFormElement | null;
if (!form) return;
trackEvent('form-submit', { trackEvent('form-submit', {
formId: form.id || undefined, formId: form.id || undefined,
formClass: form.className || undefined, formClass: form.className || undefined,
url: window.location.pathname, url: window.location.pathname,
}); });
} catch (error) {
// Silently fail - form tracking is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking form submit:', error);
}
}
}; };
// Track scroll depth // Track scroll depth
let maxScrollDepth = 0; let maxScrollDepth = 0;
const handleScroll = () => { const handleScroll = () => {
try {
if (typeof window === 'undefined' || typeof document === 'undefined') return;
const scrollHeight = document.documentElement.scrollHeight;
const innerHeight = window.innerHeight;
if (scrollHeight <= innerHeight) return; // No scrollable content
const scrollDepth = Math.round( const scrollDepth = Math.round(
(window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100 (window.scrollY / (scrollHeight - innerHeight)) * 100
); );
if (scrollDepth > maxScrollDepth) { if (scrollDepth > maxScrollDepth) {
@@ -168,6 +216,12 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
trackEvent('scroll-depth', { depth: 90, url: window.location.pathname }); trackEvent('scroll-depth', { depth: 90, url: window.location.pathname });
} }
} }
} catch (error) {
// Silently fail - scroll tracking is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking scroll:', error);
}
}
}; };
// Add event listeners // Add event listeners
@@ -177,20 +231,36 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Track errors // Track errors
const handleError = (event: ErrorEvent) => { const handleError = (event: ErrorEvent) => {
try {
if (typeof window === 'undefined') return;
trackEvent('error', { trackEvent('error', {
message: event.message, message: event.message || 'Unknown error',
filename: event.filename, filename: event.filename || undefined,
lineno: event.lineno, lineno: event.lineno || undefined,
colno: event.colno, colno: event.colno || undefined,
url: window.location.pathname, url: window.location.pathname,
}); });
} catch (error) {
// Silently fail - error tracking should not cause more errors
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking error event:', error);
}
}
}; };
const handleUnhandledRejection = (event: PromiseRejectionEvent) => { const handleUnhandledRejection = (event: PromiseRejectionEvent) => {
try {
if (typeof window === 'undefined') return;
trackEvent('unhandled-rejection', { trackEvent('unhandled-rejection', {
reason: event.reason?.toString(), reason: event.reason?.toString() || 'Unknown rejection',
url: window.location.pathname, url: window.location.pathname,
}); });
} catch (error) {
// Silently fail - error tracking should not cause more errors
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking unhandled rejection:', error);
}
}
}; };
window.addEventListener('error', handleError); window.addEventListener('error', handleError);
@@ -198,14 +268,27 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Cleanup // Cleanup
return () => { return () => {
try {
window.removeEventListener('popstate', handleRouteChange); window.removeEventListener('popstate', handleRouteChange);
document.removeEventListener('click', handleClick); document.removeEventListener('click', handleClick);
document.removeEventListener('submit', handleSubmit); document.removeEventListener('submit', handleSubmit);
window.removeEventListener('scroll', handleScroll); window.removeEventListener('scroll', handleScroll);
window.removeEventListener('error', handleError); window.removeEventListener('error', handleError);
window.removeEventListener('unhandledrejection', handleUnhandledRejection); window.removeEventListener('unhandledrejection', handleUnhandledRejection);
} catch {
// Silently fail during cleanup
}
}; };
} catch (error) {
// If anything fails, log but don't break the app
if (process.env.NODE_ENV === 'development') {
console.error('AnalyticsProvider initialization error:', error);
}
// Return empty cleanup function
return () => {};
}
}, []); }, []);
// Always render children, even if analytics fails
return <>{children}</>; return <>{children}</>;
}; };

View File

@@ -27,7 +27,16 @@ const BackgroundBlobs = () => {
const x5 = useTransform(springX, (value) => value / 15); const x5 = useTransform(springX, (value) => value / 15);
const y5 = useTransform(springY, (value) => value / 15); const y5 = useTransform(springY, (value) => value / 15);
// Prevent hydration mismatch
const [mounted, setMounted] = useState(false);
useEffect(() => { useEffect(() => {
setMounted(true);
}, []);
useEffect(() => {
if (!mounted) return;
const handleMouseMove = (e: MouseEvent) => { const handleMouseMove = (e: MouseEvent) => {
const x = e.clientX - window.innerWidth / 2; const x = e.clientX - window.innerWidth / 2;
const y = e.clientY - window.innerHeight / 2; const y = e.clientY - window.innerHeight / 2;
@@ -37,14 +46,7 @@ const BackgroundBlobs = () => {
window.addEventListener("mousemove", handleMouseMove); window.addEventListener("mousemove", handleMouseMove);
return () => window.removeEventListener("mousemove", handleMouseMove); return () => window.removeEventListener("mousemove", handleMouseMove);
}, [mouseX, mouseY]); }, [mouseX, mouseY, mounted]);
// Prevent hydration mismatch
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) return null; if (!mounted) return null;

View File

@@ -22,18 +22,20 @@ export default class ErrorBoundary extends React.Component<
render() { render() {
if (this.state.hasError) { if (this.state.hasError) {
// Still render children to prevent white screen - just log the error
if (process.env.NODE_ENV === 'development') {
return ( return (
<div className="p-4 m-4 bg-red-50 border border-red-200 rounded text-red-800"> <div>
<h2>Something went wrong!</h2> <div className="p-2 m-2 bg-yellow-50 border border-yellow-200 rounded text-yellow-800 text-xs">
<button Error boundary triggered - rendering children anyway
className="mt-2 px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700" </div>
onClick={() => this.setState({ hasError: false })} {this.props.children}
>
Try again
</button>
</div> </div>
); );
} }
// In production, just render children silently
return this.props.children;
}
return this.props.children; return this.props.children;
} }

View File

@@ -157,7 +157,7 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
const stats = { const stats = {
totalProjects: projects.length, totalProjects: projects.length,
publishedProjects: projects.filter(p => p.published).length, publishedProjects: projects.filter(p => p.published).length,
totalViews: (analytics?.overview?.totalViews as number) || (analytics?.totalViews as number) || projects.reduce((sum, p) => sum + (p.analytics?.views || 0), 0), totalViews: ((analytics?.overview as Record<string, unknown>)?.totalViews as number) || (analytics?.totalViews as number) || projects.reduce((sum, p) => sum + (p.analytics?.views || 0), 0),
unreadEmails: emails.filter(e => !(e.read as boolean)).length, unreadEmails: emails.filter(e => !(e.read as boolean)).length,
avgPerformance: (() => { avgPerformance: (() => {
// Only show real performance data, not defaults // Only show real performance data, not defaults
@@ -172,9 +172,9 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
}, 0) / projectsWithPerf.length); }, 0) / projectsWithPerf.length);
})(), })(),
systemHealth: (systemStats?.status as string) || 'unknown', systemHealth: (systemStats?.status as string) || 'unknown',
totalUsers: (analytics?.metrics?.totalUsers as number) || (analytics?.totalUsers as number) || 0, totalUsers: ((analytics?.metrics as Record<string, unknown>)?.totalUsers as number) || (analytics?.totalUsers as number) || 0,
bounceRate: (analytics?.metrics?.bounceRate as number) || (analytics?.bounceRate as number) || 0, bounceRate: ((analytics?.metrics as Record<string, unknown>)?.bounceRate as number) || (analytics?.bounceRate as number) || 0,
avgSessionDuration: (analytics?.metrics?.avgSessionDuration as number) || (analytics?.avgSessionDuration as number) || 0 avgSessionDuration: ((analytics?.metrics as Record<string, unknown>)?.avgSessionDuration as number) || (analytics?.avgSessionDuration as number) || 0
}; };
useEffect(() => { useEffect(() => {

View File

@@ -59,7 +59,7 @@ const ToastItem = ({ toast, onRemove }: ToastProps) => {
const getColors = () => { const getColors = () => {
switch (toast.type) { switch (toast.type) {
case 'success': case 'success':
return 'bg-stone-50 border-green-200 text-green-800 shadow-md'; return 'bg-stone-50 border-green-300 text-green-900 shadow-md';
case 'error': case 'error':
return 'bg-stone-50 border-red-200 text-red-800 shadow-md'; return 'bg-stone-50 border-red-200 text-red-800 shadow-md';
case 'warning': case 'warning':
@@ -291,7 +291,7 @@ export const ToastProvider = ({ children }: { children: React.ReactNode }) => {
{children} {children}
{/* Toast Container */} {/* Toast Container */}
<div className="fixed top-4 right-4 z-50 space-y-2 max-w-xs"> <div className="fixed top-4 right-4 z-50 space-y-3 max-w-sm">
<AnimatePresence> <AnimatePresence>
{toasts.map((toast) => ( {toasts.map((toast) => (
<ToastItem <ToastItem

View File

@@ -57,11 +57,13 @@ export const trackWebVitals = (metric: WebVitalsMetric) => {
// Track page load performance // Track page load performance
export const trackPageLoad = () => { export const trackPageLoad = () => {
if (typeof window === 'undefined') return; if (typeof window === 'undefined' || typeof performance === 'undefined') return;
const navigation = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming; try {
const navigationEntries = performance.getEntriesByType('navigation');
const navigation = navigationEntries[0] as PerformanceNavigationTiming | undefined;
if (navigation) { if (navigation && navigation.loadEventEnd && navigation.fetchStart) {
trackPerformance({ trackPerformance({
name: 'page-load', name: 'page-load',
value: navigation.loadEventEnd - navigation.fetchStart, value: navigation.loadEventEnd - navigation.fetchStart,
@@ -72,19 +74,38 @@ export const trackPageLoad = () => {
// Track individual timing phases // Track individual timing phases
trackEvent('page-timing', { trackEvent('page-timing', {
dns: Math.round(navigation.domainLookupEnd - navigation.domainLookupStart), dns: navigation.domainLookupEnd && navigation.domainLookupStart
tcp: Math.round(navigation.connectEnd - navigation.connectStart), ? Math.round(navigation.domainLookupEnd - navigation.domainLookupStart)
request: Math.round(navigation.responseStart - navigation.requestStart), : 0,
response: Math.round(navigation.responseEnd - navigation.responseStart), tcp: navigation.connectEnd && navigation.connectStart
dom: Math.round(navigation.domContentLoadedEventEnd - navigation.responseEnd), ? Math.round(navigation.connectEnd - navigation.connectStart)
load: Math.round(navigation.loadEventEnd - navigation.domContentLoadedEventEnd), : 0,
request: navigation.responseStart && navigation.requestStart
? Math.round(navigation.responseStart - navigation.requestStart)
: 0,
response: navigation.responseEnd && navigation.responseStart
? Math.round(navigation.responseEnd - navigation.responseStart)
: 0,
dom: navigation.domContentLoadedEventEnd && navigation.responseEnd
? Math.round(navigation.domContentLoadedEventEnd - navigation.responseEnd)
: 0,
load: navigation.loadEventEnd && navigation.domContentLoadedEventEnd
? Math.round(navigation.loadEventEnd - navigation.domContentLoadedEventEnd)
: 0,
url: window.location.pathname, url: window.location.pathname,
}); });
} }
} catch (error) {
// Silently fail - performance tracking is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('Error tracking page load:', error);
}
}
}; };
// Track API response times // Track API response times
export const trackApiCall = (endpoint: string, duration: number, status: number) => { export const trackApiCall = (endpoint: string, duration: number, status: number) => {
if (typeof window === 'undefined') return;
trackEvent('api-call', { trackEvent('api-call', {
endpoint, endpoint,
duration: Math.round(duration), duration: Math.round(duration),
@@ -95,6 +116,7 @@ export const trackApiCall = (endpoint: string, duration: number, status: number)
// Track user interactions // Track user interactions
export const trackInteraction = (action: string, element?: string) => { export const trackInteraction = (action: string, element?: string) => {
if (typeof window === 'undefined') return;
trackEvent('interaction', { trackEvent('interaction', {
action, action,
element, element,
@@ -104,6 +126,7 @@ export const trackInteraction = (action: string, element?: string) => {
// Track errors // Track errors
export const trackError = (error: string, context?: string) => { export const trackError = (error: string, context?: string) => {
if (typeof window === 'undefined') return;
trackEvent('error', { trackEvent('error', {
error, error,
context, context,

View File

@@ -13,11 +13,15 @@ interface Metric {
// Simple Web Vitals implementation (since we don't want to add external dependencies) // Simple Web Vitals implementation (since we don't want to add external dependencies)
const getCLS = (onPerfEntry: (metric: Metric) => void) => { const getCLS = (onPerfEntry: (metric: Metric) => void) => {
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
try {
let clsValue = 0; let clsValue = 0;
let sessionValue = 0; let sessionValue = 0;
let sessionEntries: PerformanceEntry[] = []; let sessionEntries: PerformanceEntry[] = [];
const observer = new PerformanceObserver((list) => { const observer = new PerformanceObserver((list) => {
try {
for (const entry of list.getEntries()) { for (const entry of list.getEntries()) {
if (!(entry as PerformanceEntry & { hadRecentInput?: boolean }).hadRecentInput) { if (!(entry as PerformanceEntry & { hadRecentInput?: boolean }).hadRecentInput) {
const firstSessionEntry = sessionEntries[0]; const firstSessionEntry = sessionEntries[0];
@@ -42,28 +46,64 @@ const getCLS = (onPerfEntry: (metric: Metric) => void) => {
} }
} }
} }
} catch (error) {
// Silently fail - CLS tracking is not critical
if (process.env.NODE_ENV === 'development') {
console.warn('CLS tracking error:', error);
}
}
}); });
observer.observe({ type: 'layout-shift', buffered: true }); observer.observe({ type: 'layout-shift', buffered: true });
return observer;
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('CLS observer initialization failed:', error);
}
return null;
}
}; };
const getFID = (onPerfEntry: (metric: Metric) => void) => { const getFID = (onPerfEntry: (metric: Metric) => void) => {
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
try {
const observer = new PerformanceObserver((list) => { const observer = new PerformanceObserver((list) => {
try {
for (const entry of list.getEntries()) { for (const entry of list.getEntries()) {
const processingStart = (entry as PerformanceEntry & { processingStart?: number }).processingStart;
if (processingStart !== undefined) {
onPerfEntry({ onPerfEntry({
name: 'FID', name: 'FID',
value: (entry as PerformanceEntry & { processingStart?: number }).processingStart! - entry.startTime, value: processingStart - entry.startTime,
delta: (entry as PerformanceEntry & { processingStart?: number }).processingStart! - entry.startTime, delta: processingStart - entry.startTime,
id: `fid-${Date.now()}`, id: `fid-${Date.now()}`,
}); });
} }
}
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('FID tracking error:', error);
}
}
}); });
observer.observe({ type: 'first-input', buffered: true }); observer.observe({ type: 'first-input', buffered: true });
return observer;
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('FID observer initialization failed:', error);
}
return null;
}
}; };
const getFCP = (onPerfEntry: (metric: Metric) => void) => { const getFCP = (onPerfEntry: (metric: Metric) => void) => {
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
try {
const observer = new PerformanceObserver((list) => { const observer = new PerformanceObserver((list) => {
try {
for (const entry of list.getEntries()) { for (const entry of list.getEntries()) {
if (entry.name === 'first-contentful-paint') { if (entry.name === 'first-contentful-paint') {
onPerfEntry({ onPerfEntry({
@@ -74,32 +114,67 @@ const getFCP = (onPerfEntry: (metric: Metric) => void) => {
}); });
} }
} }
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('FCP tracking error:', error);
}
}
}); });
observer.observe({ type: 'paint', buffered: true }); observer.observe({ type: 'paint', buffered: true });
return observer;
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('FCP observer initialization failed:', error);
}
return null;
}
}; };
const getLCP = (onPerfEntry: (metric: Metric) => void) => { const getLCP = (onPerfEntry: (metric: Metric) => void) => {
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
try {
const observer = new PerformanceObserver((list) => { const observer = new PerformanceObserver((list) => {
try {
const entries = list.getEntries(); const entries = list.getEntries();
const lastEntry = entries[entries.length - 1]; const lastEntry = entries[entries.length - 1];
if (lastEntry) {
onPerfEntry({ onPerfEntry({
name: 'LCP', name: 'LCP',
value: lastEntry.startTime, value: lastEntry.startTime,
delta: lastEntry.startTime, delta: lastEntry.startTime,
id: `lcp-${Date.now()}`, id: `lcp-${Date.now()}`,
}); });
}
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('LCP tracking error:', error);
}
}
}); });
observer.observe({ type: 'largest-contentful-paint', buffered: true }); observer.observe({ type: 'largest-contentful-paint', buffered: true });
return observer;
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('LCP observer initialization failed:', error);
}
return null;
}
}; };
const getTTFB = (onPerfEntry: (metric: Metric) => void) => { const getTTFB = (onPerfEntry: (metric: Metric) => void) => {
if (typeof window === 'undefined' || typeof PerformanceObserver === 'undefined') return null;
try {
const observer = new PerformanceObserver((list) => { const observer = new PerformanceObserver((list) => {
try {
for (const entry of list.getEntries()) { for (const entry of list.getEntries()) {
if (entry.entryType === 'navigation') { if (entry.entryType === 'navigation') {
const navEntry = entry as PerformanceNavigationTiming; const navEntry = entry as PerformanceNavigationTiming;
if (navEntry.responseStart && navEntry.fetchStart) {
onPerfEntry({ onPerfEntry({
name: 'TTFB', name: 'TTFB',
value: navEntry.responseStart - navEntry.fetchStart, value: navEntry.responseStart - navEntry.fetchStart,
@@ -108,9 +183,22 @@ const getTTFB = (onPerfEntry: (metric: Metric) => void) => {
}); });
} }
} }
}
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('TTFB tracking error:', error);
}
}
}); });
observer.observe({ type: 'navigation', buffered: true }); observer.observe({ type: 'navigation', buffered: true });
return observer;
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn('TTFB observer initialization failed:', error);
}
return null;
}
}; };
// Custom hook for Web Vitals tracking // Custom hook for Web Vitals tracking
@@ -118,11 +206,14 @@ export const useWebVitals = () => {
useEffect(() => { useEffect(() => {
if (typeof window === 'undefined') return; if (typeof window === 'undefined') return;
// Wrap everything in try-catch to prevent errors from breaking the app
try {
// Store web vitals for batch sending // Store web vitals for batch sending
const webVitals: Record<string, number> = {}; const webVitals: Record<string, number> = {};
const path = window.location.pathname; const path = window.location.pathname;
const projectMatch = path.match(/\/projects\/([^\/]+)/); const projectMatch = path.match(/\/projects\/([^\/]+)/);
const projectId = projectMatch ? projectMatch[1] : null; const projectId = projectMatch ? projectMatch[1] : null;
const observers: PerformanceObserver[] = [];
const sendWebVitals = async () => { const sendWebVitals = async () => {
if (Object.keys(webVitals).length >= 3) { // Wait for at least FCP, LCP, CLS if (Object.keys(webVitals).length >= 3) { // Wait for at least FCP, LCP, CLS
@@ -156,7 +247,7 @@ export const useWebVitals = () => {
}; };
// Track Core Web Vitals // Track Core Web Vitals
getCLS((metric) => { const clsObserver = getCLS((metric) => {
webVitals.CLS = metric.value; webVitals.CLS = metric.value;
trackWebVitals({ trackWebVitals({
...metric, ...metric,
@@ -165,8 +256,9 @@ export const useWebVitals = () => {
}); });
sendWebVitals(); sendWebVitals();
}); });
if (clsObserver) observers.push(clsObserver);
getFID((metric) => { const fidObserver = getFID((metric) => {
webVitals.FID = metric.value; webVitals.FID = metric.value;
trackWebVitals({ trackWebVitals({
...metric, ...metric,
@@ -175,8 +267,9 @@ export const useWebVitals = () => {
}); });
sendWebVitals(); sendWebVitals();
}); });
if (fidObserver) observers.push(fidObserver);
getFCP((metric) => { const fcpObserver = getFCP((metric) => {
webVitals.FCP = metric.value; webVitals.FCP = metric.value;
trackWebVitals({ trackWebVitals({
...metric, ...metric,
@@ -185,8 +278,9 @@ export const useWebVitals = () => {
}); });
sendWebVitals(); sendWebVitals();
}); });
if (fcpObserver) observers.push(fcpObserver);
getLCP((metric) => { const lcpObserver = getLCP((metric) => {
webVitals.LCP = metric.value; webVitals.LCP = metric.value;
trackWebVitals({ trackWebVitals({
...metric, ...metric,
@@ -195,8 +289,9 @@ export const useWebVitals = () => {
}); });
sendWebVitals(); sendWebVitals();
}); });
if (lcpObserver) observers.push(lcpObserver);
getTTFB((metric) => { const ttfbObserver = getTTFB((metric) => {
webVitals.TTFB = metric.value; webVitals.TTFB = metric.value;
trackWebVitals({ trackWebVitals({
...metric, ...metric,
@@ -205,6 +300,7 @@ export const useWebVitals = () => {
}); });
sendWebVitals(); sendWebVitals();
}); });
if (ttfbObserver) observers.push(ttfbObserver);
// Track page load performance // Track page load performance
const handleLoad = () => { const handleLoad = () => {
@@ -226,7 +322,27 @@ export const useWebVitals = () => {
} }
return () => { return () => {
// Cleanup all observers
observers.forEach(observer => {
try {
observer.disconnect();
} catch {
// Silently fail
}
});
try {
window.removeEventListener('load', handleLoad); window.removeEventListener('load', handleLoad);
} catch {
// Silently fail
}
}; };
} catch (error) {
// If Web Vitals initialization fails, don't break the app
if (process.env.NODE_ENV === 'development') {
console.warn('Web Vitals initialization failed:', error);
}
// Return empty cleanup function
return () => {};
}
}, []); }, []);
}; };

1700
public/404-terminal.html Normal file

File diff suppressed because it is too large Load Diff