The user wants a React hydration diagnostics panel. This is a developer tool that helps identify and debug hydration mismatches between server-rendered and client-rendered React content.
This is a sophisticated developer tool panel. I need to create:
A sophisticated developer tool for debugging React hydration issues, featuring mismatch detection, server-client diffing, and asset readiness tracking.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React Hydration Diagnostics</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #0a0a0f;
--bg-secondary: #12121a;
--bg-tertiary: #1a1a24;
--bg-elevated: #22222e;
--fg-primary: #e4e4eb;
--fg-secondary: #9898a8;
--fg-muted: #5c5c6d;
--accent-cyan: #00d4ff;
--accent-purple: #a855f7;
--accent-green: #22c55e;
--accent-yellow: #fbbf24;
--accent-red: #ef4444;
--accent-orange: #f97316;
--border-default: #2a2a3a;
--border-subtle: #1e1e2a;
--glow-cyan: rgba(0, 212, 255, 0.15);
--glow-purple: rgba(168, 85, 247, 0.15);
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg-primary);
color: var(--fg-primary);
min-height: 100vh;
margin: 0;
}
.font-mono {
font-family: 'JetBrains Mono', monospace;
}
.bg-grid {
background-image:
linear-gradient(rgba(42, 42, 58, 0.3) 1px, transparent 1px),
linear-gradient(90deg, rgba(42, 42, 58, 0.3) 1px, transparent 1px);
background-size: 24px 24px;
}
.scrollbar-custom::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.scrollbar-custom::-webkit-scrollbar-track {
background: var(--bg-secondary);
}
.scrollbar-custom::-webkit-scrollbar-thumb {
background: var(--border-default);
border-radius: 3px;
}
.scrollbar-custom::-webkit-scrollbar-thumb:hover {
background: var(--fg-muted);
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
.animate-slide-in {
animation: slideIn 0.3s ease-out forwards;
}
.animate-pulse-slow {
animation: pulse 2s ease-in-out infinite;
}
.shimmer {
background: linear-gradient(
90deg,
var(--bg-tertiary) 0%,
var(--bg-elevated) 50%,
var(--bg-tertiary) 100%
);
background-size: 200% 100%;
animation: shimmer 1.5s ease-in-out infinite;
}
.diff-added {
background: rgba(34, 197, 94, 0.15);
border-left: 2px solid var(--accent-green);
}
.diff-removed {
background: rgba(239, 68, 68, 0.15);
border-left: 2px solid var(--accent-red);
}
.diff-modified {
background: rgba(251, 191, 36, 0.1);
border-left: 2px solid var(--accent-yellow);
}
.tab-indicator {
position: absolute;
bottom: 0;
height: 2px;
background: var(--accent-cyan);
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.status-loading {
background: var(--accent-yellow);
animation: pulse 1s ease-in-out infinite;
}
.status-ready {
background: var(--accent-green);
}
.status-error {
background: var(--accent-red);
}
.stack-trace {
counter-reset: line;
}
.stack-trace > div {
counter-increment: line;
}
.stack-trace > div::before {
content: counter(line);
display: inline-block;
width: 2rem;
text-align: right;
margin-right: 1rem;
color: var(--fg-muted);
font-size: 0.75rem;
}
@media (prefers-reduced-motion: reduce) {
.animate-slide-in,
.animate-pulse-slow,
.shimmer,
.status-loading {
animation: none;
}
.tab-indicator {
transition: none;
}
}
.focus-ring:focus-visible {
outline: 2px solid var(--accent-cyan);
outline-offset: 2px;
}
.glass-panel {
background: rgba(18, 18, 26, 0.85);
backdrop-filter: blur(12px);
border: 1px solid var(--border-default);
}
</style>
</head>
<body class="bg-grid">
<div id="app"></div>
<script>
// Hydration diagnostic data
const hydrationData = {
mismatches: [
{
id: 1,
type: 'text-content',
severity: 'error',
component: 'UserProfile',
path: 'App > Layout > Sidebar > UserProfile',
serverRender: 'John Doe',
clientRender: 'Jane Smith',
nodeName: 'span',
domPath: 'div#root > div.layout > aside.sidebar > div.user-profile > span.name',
stackTrace: [
'at UserProfile (src/components/UserProfile.tsx:24:12)',
'at Sidebar (src/components/Layout/Sidebar.tsx:45:18)',
'at Layout (src/components/Layout/index.tsx:12:10)',
'at App (src/App.tsx:28:8)'
],
timestamp: Date.now() - 45000
},
{
id: 2,
type: 'attribute',
severity: 'warning',
component: 'Button',
path: 'App > Layout > Main > Hero > CTAButton',
serverRender: 'className="btn primary large"',
clientRender: 'className="btn primary"',
attributeName: 'class',
domPath: 'div#root > main > section.hero > button.cta',
stackTrace: [
'at Button (src/components/ui/Button.tsx:18:15)',
'at Hero (src/components/Hero.tsx:67:12)',
'at Main (src/components/Layout/Main.tsx:23:8)',
'at App (src/App.tsx:28:8)'
],
timestamp: Date.now() - 42000
},
{
id: 3,
type: 'structure',
severity: 'error',
component: 'Navigation',
path: 'App > Layout > Header > Navigation',
serverRender: '<ul><li>Home</li><li>About</li></ul>',
clientRender: '<ul><li>Home</li><li>Products</li><li>About</li></ul>',
domPath: 'header > nav > ul.nav-list',
stackTrace: [
'at Navigation (src/components/Navigation.tsx:34:10)',
'at Header (src/components/Layout/Header.tsx:28:14)',
'at Layout (src/components/Layout/index.tsx:18:10)',
'at App (src/App.tsx:28:8)'
],
timestamp: Date.now() - 38000
},
{
id: 4,
type: 'event-handler',
severity: 'warning',
component: 'SearchInput',
path: 'App > Layout > Header > SearchBar > SearchInput',
description: 'Event handler attached before hydration complete',
domPath: 'header > div.search > input[type="search"]',
stackTrace: [
'at SearchInput (src/components/Search/Input.tsx:42:18)',
'at SearchBar (src/components/Search/Bar.tsx:15:12)',
'at Header (src/components/Layout/Header.tsx:45:10)',
'at App (src/App.tsx:28:8)'
],
timestamp: Date.now() - 35000
}
],
assets: [
{ name: 'main.bundle.js', type: 'script', size: '245KB', status: 'ready', loadTime: 234 },
{ name: 'vendor.chunk.js', type: 'script', size: '1.2MB', status: 'ready', loadTime: 456 },
{ name: 'styles.css', type: 'stylesheet', size: '89KB', status: 'ready', loadTime: 89 },
{ name: 'Inter-Variable.woff2', type: 'font', size: '124KB', status: 'ready', loadTime: 167 },
{ name: 'hero-bg.webp', type: 'image', size: '340KB', status: 'loading', loadTime: null },
{ name: 'analytics.js', type: 'script', size: '45KB', status: 'pending', loadTime: null },
{ name: 'critical.css', type: 'stylesheet', size: '12KB', status: 'ready', loadTime: 45 }
],
timeline: [
{ event: 'HTML received', time: 0, status: 'complete' },
{ event: 'CSS parsed', time: 45, status: 'complete' },
{ event: 'DOM constructed', time: 78, status: 'complete' },
{ event: 'Scripts queued', time: 89, status: 'complete' },
{ event: 'Hydration started', time: 234, status: 'complete' },
{ event: 'Mismatch detected: UserProfile', time: 256, status: 'error' },
{ event: 'Mismatch detected: Button', time: 278, status: 'warning' },
{ event: 'Mismatch detected: Navigation', time: 312, status: 'error' },
{ event: 'Hydration completed', time: 389, status: 'complete' }
],
diff: {
server: `<div class="user-profile">
<img src="/avatar.jpg" alt="User avatar" />
<span class="name">John Doe</span>
<span class="role">Admin</span>
</div>`,
client: `<div class="user-profile">
<img src="/avatar.jpg" alt="User avatar" />
<span class="name">Jane Smith</span>
<span class="role">Admin</span>
</div>`
}
};
// Application state
let state = {
activeTab: 'mismatches',
expandedMismatch: null,
panelMinimized: false,
selectedAsset: null,
filterSeverity: 'all'
};
// Utility functions
function formatTime(timestamp) {
const seconds = Math.floor((Date.now() - timestamp) / 1000);
if (seconds < 60) return `${seconds}s ago`;
const minutes = Math.floor(seconds / 60);
return `${minutes}m ago`;
}
function getSeverityColor(severity) {
return severity === 'error' ? 'var(--accent-red)' :
severity === 'warning' ? 'var(--accent-yellow)' : 'var(--accent-cyan)';
}
function getStatusClass(status) {
return status === 'loading' ? 'status-loading' :
status === 'ready' ? 'status-ready' : 'status-error';
}
// Component renderers
function renderHeader() {
const errorCount = hydrationData.mismatches.filter(m => m.severity === 'error').length;
const warningCount = hydrationData.mismatches.filter(m => m.severity === 'warning').length;
return `
<div class="flex items-center justify-between mb-6">
<div class="flex items-center gap-4">
<div class="flex items-center gap-3">
<svg class="w-8 h-8" viewBox="0 0 32 32" fill="none">
<rect x="2" y="2" width="28" height="28" rx="6" stroke="var(--accent-cyan)" stroke-width="2"/>
<path d="M10 16h12M16 10v12" stroke="var(--accent-cyan)" stroke-width="2" stroke-linecap="round"/>
<circle cx="16" cy="16" r="4" fill="var(--accent-purple)" opacity="0.6"/>
</svg>
<div>
<h1 class="text-lg font-semibold tracking-tight" style="color: var(--fg-primary)">Hydration Diagnostics</h1>
<p class="text-xs" style="color: var(--fg-muted)">React SSR Analysis Panel</p>
</div>
</div>
</div>
<div class="flex items-center gap-3">
<div class="flex items-center gap-2 px-3 py-1.5 rounded-md" style="background: rgba(239, 68, 68, 0.15)">
<span class="status-dot status-error"></span>
<span class="text-sm font-mono" style="color: var(--accent-red)">${errorCount} errors</span>
</div>
<div class="flex items-center gap-2 px-3 py-1.5 rounded-md" style="background: rgba(251, 191, 36, 0.15)">
<span class="status-dot status-warning" style="background: var(--accent-yellow)"></span>
<span class="text-sm font-mono" style="color: var(--accent-yellow)">${warningCount} warnings</span>
</div>
<button
onclick="togglePanel()"
class="p-2 rounded-md transition-colors focus-ring"
style="background: var(--bg-tertiary); border: 1px solid var(--border-default)"
aria-label="${state.panelMinimized ? 'Expand panel' : 'Minimize panel'}"
>
<svg class="w-4 h-4 transition-transform ${state.panelMinimized ? 'rotate-180' : ''}" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 6l4 4 4-4"/>
</svg>
</button>
</div>
</div>
`;
}
function renderTabs() {
const tabs = [
{ id: 'mismatches', label: 'Mismatches', count: hydrationData.mismatches.length },
{ id: 'diff', label: 'Server-Client Diff', count: null },
{ id: 'assets', label: 'Asset Readiness', count: hydrationData.assets.filter(a => a.status !== 'ready').length },
{ id: 'timeline', label: 'Timeline', count: null }
];
const activeIndex = tabs.findIndex(t => t.id === state.activeTab);
return `
<div class="relative mb-6">
<div class="flex gap-1 p-1 rounded-lg" style="background: var(--bg-secondary)">
${tabs.map((tab, i) => `
<button
onclick="setTab('${tab.id}')"
class="relative px-4 py-2 text-sm font-medium transition-all rounded-md focus-ring"
style="color: ${tab.id === state.activeTab ? 'var(--fg-primary)' : 'var(--fg-secondary)'};
background: ${tab.id === state.activeTab ? 'var(--bg-tertiary)' : 'transparent'}"
>
${tab.label}
${tab.count !== null && tab.count > 0 ? `
<span class="ml-2 px-1.5 py-0.5 text-xs rounded" style="background: var(--accent-red); color: white">${tab.count}</span>
` : ''}
</button>
`).join('')}
</div>
</div>
`;
}
function renderMismatchCard(mismatch) {
const isExpanded = state.expandedMismatch === mismatch.id;
const severityColor = getSeverityColor(mismatch.severity);
return `
<div
class="rounded-lg overflow-hidden transition-all animate-slide-in"
style="background: var(--bg-tertiary); border: 1px solid var(--border-default); animation-delay: ${mismatch.id * 50}ms"
>
<button
onclick="toggleMismatch(${mismatch.id})"
class="w-full p-4 flex items-start gap-4 text-left focus-ring"
aria-expanded="${isExpanded}"
>
<div class="mt-1">
<div class="w-3 h-3 rounded-full" style="background: ${severityColor}"></div>
</div>
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2 mb-1">
<span class="font-mono text-sm font-semibold" style="color: var(--fg-primary)">${mismatch.component}</span>
<span class="px-2 py-0.5 text-xs rounded" style="background: var(--bg-elevated); color: var(--fg-secondary)">${mismatch.type}</span>
</div>
<p class="text-xs truncate" style="color: var(--fg-muted)">${mismatch.path}</p>
${mismatch.serverRender && mismatch.clientRender ? `
<div class="mt-2 flex items-center gap-3">
<code class="px-2 py-1 text-xs rounded diff-removed font-mono">${mismatch.serverRender.substring(0, 40)}${mismatch.serverRender.length > 40 ? '...' : ''}</code>
<svg class="w-4 h-4" style="color: var(--fg-muted)" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2">
<path d="M6 4l4 4-4 4"/>
</svg>
<code class="px-2 py-1 text-xs rounded diff-added font-mono">${mismatch.clientRender.substring(0, 40)}${mismatch.clientRender.length > 40 ? '...' : ''}</code>
</div>
` : ''}
</div>
<div class="flex items-center gap-3">
<span class="text-xs" style="color: var(--fg-muted)">${formatTime(mismatch.timestamp)}</span>
<svg class="w-4 h-4 transition-transform ${isExpanded ? 'rotate-180' : ''}" style="color: var(--fg-muted)" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 6l4 4 4-4"/>
</svg>
</div>
</button>
${isExpanded ? `
<div class="px-4 pb-4 animate-slide-in">
<div class="p-4 rounded-lg" style="background: var(--bg-secondary)">
<div class="mb-4">
<h4 class="text-xs font-semibold mb-2" style="color: var(--fg-muted)">DOM PATH</h4>
<code class="block p-2 text-xs rounded font-mono" style="background: var(--bg-elevated); color: var(--accent-cyan)">${mismatch.domPath}</code>
</div>
<div class="mb-4">
<h4 class="text-xs font-semibold mb-2" style="color: var(--fg-muted)">COMPONENT STACK</h4>
<div class="stack-trace p-3 rounded font-mono text-xs" style="background: var(--bg-elevated)">
${mismatch.stackTrace.map(line => `
<div class="py-0.5" style="color: var(--fg-secondary)">
<span style="color: var(--accent-purple)">${line.split(' ')[0]}</span>
<span style="color: var(--fg-muted)">${line.split(' ').slice(1).join(' ')}</span>
</div>
`).join('')}
</div>
</div>
${mismatch.serverRender && mismatch.clientRender ? `
<div class="grid grid-cols-2 gap-4">
<div>
<h4 class="text-xs font-semibold mb-2" style="color: var(--accent-red)">SERVER</h4>
<pre class="p-3 rounded text-xs overflow-auto max-h-32 scrollbar-custom font-mono" style="background: var(--bg-elevated); color: var(--fg-primary)">${mismatch.serverRender}</pre>
</div>
<div>
<h4 class="text-xs font-semibold mb-2" style="color: var(--accent-green)">CLIENT</h4>
<pre class="p-3 rounded text-xs overflow-auto max-h-32 scrollbar-custom font-mono" style="background: var(--bg-elevated); color: var(--fg-primary)">${mismatch.clientRender}</pre>
</div>
</div>
` : `
<div class="p-3 rounded" style="background: rgba(251, 191, 36, 0.1); border: 1px solid rgba(251, 191, 36, 0.3)">
<p class="text-xs" style="color: var(--accent-yellow)">${mismatch.description}</p>
</div>
`}
</div>
</div>
` : ''}
</div>
`;
}
function renderMismatchesTab() {
const filteredMismatches = state.filterSeverity === 'all'
? hydrationData.mismatches
: hydrationData.mismatches.filter(m => m.severity === state.filterSeverity);
return `
<div>
<div class="flex items-center gap-2 mb-4">
<span class="text-xs" style="color: var(--fg-muted)">Filter:</span>
${['all', 'error', 'warning'].map(sev => `
<button
onclick="setFilter('${sev}')"
class="px-3 py-1 text-xs rounded-md transition-colors focus-ring"
style="background: ${state.filterSeverity === sev ? 'var(--accent-cyan)' : 'var(--bg-tertiary)'};
color: ${state.filterSeverity === sev ? 'var(--bg-primary)' : 'var(--fg-secondary)'}"
>${sev.charAt(0).toUpperCase() + sev.slice(1)}</button>
`).join('')}
</div>
<div class="space-y-3">
${filteredMismatches.map(m => renderMismatchCard(m)).join('')}
</div>
</div>
`;
}
function renderDiffTab() {
const serverLines = hydrationData.diff.server.split('\n');
const clientLines = hydrationData.diff.client.split('\n');
return `
<div class="grid grid-cols-2 gap-4">
<div>
<div class="flex items-center gap-2 mb-3">
<svg class="w-5 h-5" style="color: var(--accent-red)" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5 10a1 1 0 011-1h8a1 1 0 110 2H6a1 1 0 01-1-1z" clip-rule="evenodd"/>
</svg>
<h3 class="font-semibold" style="color: var(--accent-red)">Server Render</h3>
</div>
<div class="rounded-lg overflow-hidden" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<div class="p-2 text-xs" style="background: var(--bg-secondary); color: var(--fg-muted); border-bottom: 1px solid var(--border-subtle)">SSR Output</div>
<div class="p-4 font-mono text-sm">
${serverLines.map((line, i) => {
const clientLine = clientLines[i] || '';
const isDiff = line !== clientLine;
return `<div class="py-1 px-2 -mx-2 ${isDiff ? 'diff-removed' : ''}">${line || ' '}</div>`;
}).join('')}
</div>
</div>
</div>
<div>
<div class="flex items-center gap-2 mb-3">
<svg class="w-5 h-5" style="color: var(--accent-green)" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z" clip-rule="evenodd"/>
</svg>
<h3 class="font-semibold" style="color: var(--accent-green)">Client Render</h3>
</div>
<div class="rounded-lg overflow-hidden" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<div class="p-2 text-xs" style="background: var(--bg-secondary); color: var(--fg-muted); border-bottom: 1px solid var(--border-subtle)">CSR Output</div>
<div class="p-4 font-mono text-sm">
${clientLines.map((line, i) => {
const serverLine = serverLines[i] || '';
const isDiff = line !== serverLine;
return `<div class="py-1 px-2 -mx-2 ${isDiff ? 'diff-added' : ''}">${line || ' '}</div>`;
}).join('')}
</div>
</div>
</div>
</div>
<div class="mt-6 p-4 rounded-lg" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<h4 class="text-sm font-semibold mb-3" style="color: var(--fg-primary)">Diff Summary</h4>
<div class="grid grid-cols-3 gap-4">
<div class="p-3 rounded" style="background: var(--bg-secondary)">
<div class="text-2xl font-bold font-mono" style="color: var(--accent-red)">1</div>
<div class="text-xs" style="color: var(--fg-muted)">Lines removed</div>
</div>
<div class="p-3 rounded" style="background: var(--bg-secondary)">
<div class="text-2xl font-bold font-mono" style="color: var(--accent-green)">1</div>
<div class="text-xs" style="color: var(--fg-muted)">Lines added</div>
</div>
<div class="p-3 rounded" style="background: var(--bg-secondary)">
<div class="text-2xl font-bold font-mono" style="color: var(--accent-yellow)">2</div>
<div class="text-xs" style="color: var(--fg-muted)">Lines modified</div>
</div>
</div>
</div>
`;
}
function renderAssetsTab() {
const readyAssets = hydrationData.assets.filter(a => a.status === 'ready');
const loadingAssets = hydrationData.assets.filter(a => a.status === 'loading');
const pendingAssets = hydrationData.assets.filter(a => a.status === 'pending');
const typeIcons = {
script: `<svg class="w-4 h-4" viewBox="0 0 16 16" fill="currentColor"><path d="M3 3h10v10H3V3zm2 2v6h6V5H5z"/></svg>`,
stylesheet: `<svg class="w-4 h-4" viewBox="0 0 16 16" fill="currentColor"><path d="M2 4h12v2H2V4zm0 4h12v2H2V8zm0 4h8v2H2v-2z"/></svg>`,
font: `<svg class="w-4 h-4" viewBox="0 0 16 16" fill="currentColor"><path d="M4 4h8v2H8v6H6V6H4V4z"/></svg>`,
image: `<svg class="w-4 h-4" viewBox="0 0 16 16" fill="currentColor"><path d="M2 4h12v8H2V4zm2 2v4h8V6H4z"/></svg>`
};
return `
<div class="grid grid-cols-3 gap-4 mb-6">
<div class="p-4 rounded-lg" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<div class="flex items-center gap-2 mb-2">
<span class="status-dot status-ready"></span>
<span class="text-xs" style="color: var(--fg-muted)">Ready</span>
</div>
<div class="text-2xl font-bold font-mono" style="color: var(--accent-green)">${readyAssets.length}</div>
</div>
<div class="p-4 rounded-lg" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<div class="flex items-center gap-2 mb-2">
<span class="status-dot status-loading"></span>
<span class="text-xs" style="color: var(--fg-muted)">Loading</span>
</div>
<div class="text-2xl font-bold font-mono" style="color: var(--accent-yellow)">${loadingAssets.length}</div>
</div>
<div class="p-4 rounded-lg" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<div class="flex items-center gap-2 mb-2">
<span class="status-dot" style="background: var(--fg-muted)"></span>
<span class="text-xs" style="color: var(--fg-muted)">Pending</span>
</div>
<div class="text-2xl font-bold font-mono" style="color: var(--fg-secondary)">${pendingAssets.length}</div>
</div>
</div>
<div class="rounded-lg overflow-hidden" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<table class="w-full">
<thead>
<tr style="background: var(--bg-secondary); border-bottom: 1px solid var(--border-default)">
<th class="px-4 py-3 text-left text-xs font-semibold" style="color: var(--fg-muted)">Asset</th>
<th class="px-4 py-3 text-left text-xs font-semibold" style="color: var(--fg-muted)">Type</th>
<th class="px-4 py-3 text-left text-xs font-semibold" style="color: var(--fg-muted)">Size</th>
<th class="px-4 py-3 text-left text-xs font-semibold" style="color: var(--fg-muted)">Status</th>
<th class="px-4 py-3 text-left text-xs font-semibold" style="color: var(--fg-muted)">Load Time</th>
</tr>
</thead>
<tbody>
${hydrationData.assets.map(asset => `
<tr style="border-bottom: 1px solid var(--border-subtle)" class="hover:bg-[var(--bg-elevated)] transition-colors">
<td class="px-4 py-3">
<div class="flex items-center gap-3">
<span style="color: var(--fg-muted)">${typeIcons[asset.type] || ''}</span>
<span class="font-mono text-sm" style="color: var(--fg-primary)">${asset.name}</span>
</div>
</td>
<td class="px-4 py-3">
<span class="px-2 py-1 text-xs rounded" style="background: var(--bg-elevated); color: var(--fg-secondary)">${asset.type}</span>
</td>
<td class="px-4 py-3 font-mono text-sm" style="color: var(--fg-secondary)">${asset.size}</td>
<td class="px-4 py-3">
<div class="flex items-center gap-2">
<span class="status-dot ${getStatusClass(asset.status)}"></span>
<span class="text-sm capitalize" style="color: var(--fg-secondary)">${asset.status}</span>
</div>
</td>
<td class="px-4 py-3">
${asset.loadTime ? `
<span class="font-mono text-sm" style="color: var(--accent-cyan)">${asset.loadTime}ms</span>
` : `
<span class="text-sm" style="color: var(--fg-muted)">—</span>
`}
</td>
</tr>
`).join('')}
</tbody>
</table>
</div>
`;
}
function renderTimelineTab() {
const maxTime = Math.max(...hydrationData.timeline.map(e => e.time));
return `
<div class="rounded-lg p-4" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<div class="relative">
${hydrationData.timeline.map((event, i) => {
const statusColor = event.status === 'error' ? 'var(--accent-red)' :
event.status === 'warning' ? 'var(--accent-yellow)' : 'var(--accent-green)';
const position = (event.time / maxTime) * 100;
return `
<div class="flex items-start gap-4 mb-4 last:mb-0 animate-slide-in" style="animation-delay: ${i * 80}ms">
<div class="w-20 text-right">
<span class="font-mono text-xs" style="color: var(--fg-muted)">${event.time}ms</span>
</div>
<div class="relative flex flex-col items-center">
<div class="w-3 h-3 rounded-full z-10" style="background: ${statusColor}"></div>
${i < hydrationData.timeline.length - 1 ? `
<div class="w-0.5 flex-1 my-1" style="background: var(--border-default)"></div>
` : ''}
</div>
<div class="flex-1 pb-4">
<div class="flex items-center gap-2">
<span class="text-sm font-medium" style="color: var(--fg-primary)">${event.event}</span>
<span class="px-2 py-0.5 text-xs rounded capitalize" style="background: ${statusColor}20; color: ${statusColor}">${event.status}</span>
</div>
</div>
</div>
`;
}).join('')}
</div>
</div>
<div class="mt-6 p-4 rounded-lg" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">
<h4 class="text-sm font-semibold mb-3" style="color: var(--fg-primary)">Hydration Metrics</h4>
<div class="grid grid-cols-4 gap-4">
<div>
<div class="text-xs mb-1" style="color: var(--fg-muted)">TTI</div>
<div class="text-xl font-bold font-mono" style="color: var(--accent-cyan)">389ms</div>
</div>
<div>
<div class="text-xs mb-1" style="color: var(--fg-muted)">Hydration</div>
<div class="text-xl font-bold font-mono" style="color: var(--accent-purple)">155ms</div>
</div>
<div>
<div class="text-xs mb-1" style="color: var(--fg-muted)">Errors</div>
<div class="text-xl font-bold font-mono" style="color: var(--accent-red)">2</div>
</div>
<div>
<div class="text-xs mb-1" style="color: var(--fg-muted)">Warnings</div>
<div class="text-xl font-bold font-mono" style="color: var(--accent-yellow)">2</div>
</div>
</div>
</div>
`;
}
function renderTabContent() {
switch (state.activeTab) {
case 'mismatches': return renderMismatchesTab();
case 'diff': return renderDiffTab();
case 'assets': return renderAssetsTab();
case 'timeline': return renderTimelineTab();
default: return '';
}
}
function render() {
const app = document.getElementById('app');
app.innerHTML = `
<div class="min-h-screen p-4 md:p-8">
<div class="max-w-6xl mx-auto">
<div class="glass-panel rounded-2xl p-6 shadow-2xl">
${renderHeader()}
${!state.panelMinimized ? `
${renderTabs()}
<div class="scrollbar-custom" style="max-height: 600px; overflow-y: auto">
${renderTabContent()}
</div>
` : `
<div class="text-center py-4">
<p class="text-sm" style="color: var(--fg-muted)">Panel minimized. Click the arrow to expand.</p>
</div>
`}
</div>
<div class="mt-4 text-center">
<p class="text-xs" style="color: var(--fg-muted)">
Press <kbd class="px-2 py-0.5 rounded text-xs mx-1" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">Ctrl</kbd> + <kbd class="px-2 py-0.5 rounded text-xs mx-1" style="background: var(--bg-tertiary); border: 1px solid var(--border-default)">D</kbd> to toggle diagnostics
</p>
</div>
</div>
</div>
`;
}
// Event handlers
function setTab(tab) {
state.activeTab = tab;
render();
}
function toggleMismatch(id) {
state.expandedMismatch = state.expandedMismatch === id ? null : id;
render();
}
function togglePanel() {
state.panelMinimized = !state.panelMinimized;
render();
}
function setFilter(severity) {
state.filterSeverity = severity;
render();
}
// Keyboard shortcut
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 'd') {
e.preventDefault();
togglePanel();
}
});
// Simulate asset loading
function simulateAssetLoading() {
const loadingAssets = hydrationData.assets.filter(a => a.status === 'loading' || a.status === 'pending');
if (loadingAssets.length > 0) {
setTimeout(() => {
const asset = loadingAssets[0];
asset.status = 'ready';
asset.loadTime = Math.floor(Math.random() * 300) + 100;
render();
simulateAssetLoading();
}, 2000);
}
}
// Initialize
render();
simulateAssetLoading();
</script>
</body>
</html>