Design a JavaScript rendering QA: pre/post DOM diffs, blocked resources, and hydration…
- User
Design a JavaScript rendering QA: pre/post DOM diffs, blocked resources, and hydration timing checks.
Assistant
The user wants me to design a JavaScript rendering QA tool that can:
- Pre/post DOM diffs - compare DOM state before and after certain operations
- Blocked resources detection - identify resources that are blocked
- Hydration timing checks - measure hydration performance in frameworks like React, Vue, etc.
This is a technical tool for QA/testing purposes. Let me design a sophisticated, visually striking interface that demonstrates these capabilities.
Key features to implement:
- DOM Diff Viewer - Show before/after states with highlighted changes
- Blocked Resources Panel - List resources that failed or were blocked
- Hydration Timing Dashboard - Visualize hydration metrics
- Interactive controls to run tests and view results
Design approach:
- Dark, technical/industrial aesthetic (fits the dev tooling theme)
- Monospace fonts for code, sharp/geometric UI font for headings
- Color scheme: Dark base with cyan/green accents (terminal-like feel)
- Real-time simulation of the checks
- Interactive panels with meaningful data visualization
Let me create this as a single HTML file with all the functionality.
JavaScript Rendering QA Tool
A sophisticated QA dashboard for analyzing DOM diffs, blocked resources, and hydration timing in JavaScript applications.
Design Approach
- Aesthetic: Dark, technical/industrial theme befitting developer tooling
- Typography: JetBrains Mono for code, Space Grotesk for UI
- Color: Deep charcoal base with cyan/amber accent system
- Interactions: Tab switching, diff viewer, resource filtering, timing visualization
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Render QA | DOM Analysis Suite</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&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet"> <style> :root { --bg: #0a0b0d; --bg-elevated: #111214; --bg-card: #161819; --fg: #e8e9eb; --fg-muted: #6b7280; --accent-cyan: #22d3ee; --accent-amber: #fbbf24; --accent-red: #ef4444; --accent-green: #22c55e; --border: #2a2d31; --border-focus: #3f4349; } * { box-sizing: border-box; } body { font-family: 'Space Grotesk', sans-serif; background: var(--bg); color: var(--fg); min-height: 100vh; } .font-mono { font-family: 'JetBrains Mono', monospace; } /* Background texture */ .bg-grid { background-image: linear-gradient(rgba(34, 211, 238, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(34, 211, 238, 0.03) 1px, transparent 1px); background-size: 32px 32px; } /* Glow effects */ .glow-cyan { box-shadow: 0 0 40px rgba(34, 211, 238, 0.15); } .glow-amber { box-shadow: 0 0 40px rgba(251, 191, 36, 0.15); } /* Tab indicator */ .tab-active { position: relative; } .tab-active::after { content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 2px; background: var(--accent-cyan); } /* Diff highlighting */ .diff-added { background: rgba(34, 197, 94, 0.15); border-left: 3px solid var(--accent-green); } .diff-removed { background: rgba(239, 68, 68, 0.15); border-left: 3px solid var(--accent-red); } .diff-unchanged { background: transparent; border-left: 3px solid var(--border); } /* Timing bar */ .timing-bar { height: 8px; border-radius: 4px; transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1); } /* Resource status badge */ .status-badge { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; } /* Scrollbar */ ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-track { background: var(--bg); } ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; } ::-webkit-scrollbar-thumb:hover { background: var(--border-focus); } /* Animations */ @keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } } @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } } .animate-fade-up { animation: fadeUp 0.5s ease-out forwards; } .animate-pulse-slow { animation: pulse 2s ease-in-out infinite; } .stagger-1 { animation-delay: 0.1s; opacity: 0; } .stagger-2 { animation-delay: 0.2s; opacity: 0; } .stagger-3 { animation-delay: 0.3s; opacity: 0; } .stagger-4 { animation-delay: 0.4s; opacity: 0; } @media (prefers-reduced-motion: reduce) { .animate-fade-up { animation: none; opacity: 1; } .animate-pulse-slow { animation: none; } .timing-bar { transition: none; } } /* Button hover */ .btn-primary { background: linear-gradient(135deg, var(--accent-cyan), #06b6d4); transition: all 0.2s ease; } .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(34, 211, 238, 0.3); } .btn-primary:active { transform: translateY(0); } /* Focus states */ button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 2px; } </style> </head> <body class="bg-grid"> <!-- Header --> <header class="border-b border-[--border] bg-[--bg-elevated]/80 backdrop-blur-sm sticky top-0 z-50"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="flex items-center justify-between h-16"> <div class="flex items-center gap-3"> <div class="w-8 h-8 rounded-lg bg-gradient-to-br from-[--accent-cyan] to-[--accent-amber] flex items-center justify-center"> <svg class="w-5 h-5 text-[--bg]" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"/> </svg> </div> <div> <h1 class="text-lg font-semibold tracking-tight">Render QA</h1> <p class="text-xs text-[--fg-muted] -mt-0.5">DOM Analysis Suite</p> </div> </div> <div class="flex items-center gap-3"> <span id="statusIndicator" class="flex items-center gap-2 text-sm text-[--fg-muted]"> <span class="w-2 h-2 rounded-full bg-[--accent-green] animate-pulse-slow"></span> Ready </span> <button id="runAllBtn" class="btn-primary px-4 py-2 rounded-lg text-sm font-medium text-[--bg] flex items-center gap-2" aria-label="Run all QA checks" > <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/> </svg> Run All Checks </button> </div> </div> </div> </header> <!-- Main Content --> <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8"> <!-- Tab Navigation --> <nav class="flex gap-1 mb-8 border-b border-[--border]" role="tablist" aria-label="QA check categories"> <button class="tab-btn tab-active px-4 py-3 text-sm font-medium transition-colors hover:text-[--accent-cyan]" data-tab="diff" role="tab" aria-selected="true" aria-controls="diff-panel" > DOM Diff </button> <button class="tab-btn px-4 py-3 text-sm font-medium text-[--fg-muted] transition-colors hover:text-[--accent-cyan]" data-tab="resources" role="tab" aria-selected="false" aria-controls="resources-panel" > Blocked Resources </button> <button class="tab-btn px-4 py-3 text-sm font-medium text-[--fg-muted] transition-colors hover:text-[--accent-cyan]" data-tab="hydration" role="tab" aria-selected="false" aria-controls="hydration-panel" > Hydration Timing </button> </nav> <!-- DOM Diff Panel --> <section id="diff-panel" class="tab-panel animate-fade-up stagger-1" role="tabpanel" aria-labelledby="diff-tab"> <div class="grid lg:grid-cols-3 gap-6"> <!-- Controls --> <div class="lg:col-span-3 bg-[--bg-card] rounded-xl border border-[--border] p-6"> <div class="flex flex-wrap items-center gap-4"> <div class="flex-1 min-w-[200px]"> <label class="block text-xs font-medium text-[--fg-muted] mb-2">Target Selector</label> <input type="text" id="diffSelector" value="#app" class="w-full bg-[--bg] border border-[--border] rounded-lg px-4 py-2.5 text-sm font-mono focus:border-[--accent-cyan] focus:outline-none transition-colors" placeholder="CSS selector..." > </div> <div class="flex items-end gap-2"> <button id="capturePreBtn" class="px-4 py-2.5 rounded-lg text-sm font-medium border border-[--border] hover:border-[--accent-cyan] hover:text-[--accent-cyan] transition-colors" > Capture Pre </button> <button id="capturePostBtn" class="px-4 py-2.5 rounded-lg text-sm font-medium border border-[--border] hover:border-[--accent-cyan] hover:text-[--accent-cyan] transition-colors" > Capture Post </button> <button id="computeDiffBtn" class="px-4 py-2.5 rounded-lg text-sm font-medium bg-[--accent-amber] text-[--bg] hover:bg-amber-400 transition-colors" > Compute Diff </button> </div> </div> </div> <!-- Diff Output --> <div class="lg:col-span-3 bg-[--bg-card] rounded-xl border border-[--border] overflow-hidden"> <div class="px-4 py-3 border-b border-[--border] flex items-center justify-between"> <h3 class="font-medium">Diff Results</h3> <div class="flex items-center gap-4 text-xs"> <span class="flex items-center gap-1.5"> <span class="w-3 h-3 rounded bg-[--accent-green]"></span> Added </span> <span class="flex items-center gap-1.5"> <span class="w-3 h-3 rounded bg-[--accent-red]"></span> Removed </span> <span class="flex items-center gap-1.5"> <span class="w-3 h-3 rounded bg-[--border]"></span> Unchanged </span> </div> </div> <div id="diffOutput" class="p-4 font-mono text-sm max-h-[400px] overflow-auto"> <p class="text-[--fg-muted]">Capture pre and post DOM states to see the diff...</p> </div> </div> <!-- Diff Stats --> <div class="lg:col-span-3 grid sm:grid-cols-4 gap-4"> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-4"> <p class="text-xs text-[--fg-muted] mb-1">Nodes Added</p> <p id="statAdded" class="text-2xl font-semibold text-[--accent-green]">0</p> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-4"> <p class="text-xs text-[--fg-muted] mb-1">Nodes Removed</p> <p id="statRemoved" class="text-2xl font-semibold text-[--accent-red]">0</p> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-4"> <p class="text-xs text-[--fg-muted] mb-1">Attributes Changed</p> <p id="statAttrs" class="text-2xl font-semibold text-[--accent-amber]">0</p> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-4"> <p class="text-xs text-[--fg-muted] mb-1">Text Changes</p> <p id="statText" class="text-2xl font-semibold text-[--accent-cyan]">0</p> </div> </div> </div> </section> <!-- Blocked Resources Panel --> <section id="resources-panel" class="tab-panel hidden" role="tabpanel" aria-labelledby="resources-tab"> <div class="grid lg:grid-cols-3 gap-6"> <!-- Filters --> <div class="lg:col-span-3 bg-[--bg-card] rounded-xl border border-[--border] p-6"> <div class="flex flex-wrap items-center gap-4"> <div class="flex items-center gap-2"> <label class="text-sm text-[--fg-muted]">Filter:</label> <button class="filter-btn px-3 py-1.5 rounded-lg text-xs font-medium bg-[--accent-cyan] text-[--bg]" data-filter="all">All</button> <button class="filter-btn px-3 py-1.5 rounded-lg text-xs font-medium border border-[--border] hover:border-[--accent-cyan]" data-filter="blocked">Blocked</button> <button class="filter-btn px-3 py-1.5 rounded-lg text-xs font-medium border border-[--border] hover:border-[--accent-cyan]" data-filter="failed">Failed</button> <button class="filter-btn px-3 py-1.5 rounded-lg text-xs font-medium border border-[--border] hover:border-[--accent-cyan]" data-filter="slow">Slow</button> </div> <button id="refreshResourcesBtn" class="ml-auto px-3 py-1.5 rounded-lg text-xs font-medium border border-[--border] hover:border-[--accent-cyan] transition-colors"> Refresh </button> </div> </div> <!-- Resources List --> <div class="lg:col-span-2 bg-[--bg-card] rounded-xl border border-[--border] overflow-hidden"> <div class="px-4 py-3 border-b border-[--border]"> <h3 class="font-medium">Resource Timeline</h3> </div> <div id="resourcesList" class="divide-y divide-[--border] max-h-[500px] overflow-auto"> <!-- Populated by JS --> </div> </div> <!-- Resource Summary --> <div class="space-y-4"> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-5 glow-amber"> <h4 class="text-sm font-medium mb-4">Blocking Summary</h4> <div class="space-y-3"> <div class="flex justify-between items-center"> <span class="text-sm text-[--fg-muted]">Scripts Blocked</span> <span id="summaryScripts" class="font-mono text-[--accent-amber]">0</span> </div> <div class="flex justify-between items-center"> <span class="text-sm text-[--fg-muted]">Stylesheets Blocked</span> <span id="summaryStyles" class="font-mono text-[--accent-amber]">0</span> </div> <div class="flex justify-between items-center"> <span class="text-sm text-[--fg-muted]">Fonts Blocked</span> <span id="summaryFonts" class="font-mono text-[--accent-amber]">0</span> </div> <div class="flex justify-between items-center"> <span class="text-sm text-[--fg-muted]">Images Failed</span> <span id="summaryImages" class="font-mono text-[--accent-red]">0</span> </div> </div> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-5"> <h4 class="text-sm font-medium mb-4">Total Blocking Time</h4> <div class="flex items-end gap-2"> <span id="totalBlockingTime" class="text-3xl font-semibold text-[--accent-amber]">0</span> <span class="text-sm text-[--fg-muted] mb-1">ms</span> </div> <div class="mt-3 h-2 bg-[--bg] rounded-full overflow-hidden"> <div id="blockingTimeBar" class="h-full bg-gradient-to-r from-[--accent-green] via-[--accent-amber] to-[--accent-red] w-0 transition-all duration-500"></div> </div> </div> </div> </div> </section> <!-- Hydration Timing Panel --> <section id="hydration-panel" class="tab-panel hidden" role="tabpanel" aria-labelledby="hydration-tab"> <div class="grid lg:grid-cols-3 gap-6"> <!-- Hydration Controls --> <div class="lg:col-span-3 bg-[--bg-card] rounded-xl border border-[--border] p-6"> <div class="flex flex-wrap items-center gap-4"> <div class="flex-1 min-w-[200px]"> <label class="block text-xs font-medium text-[--fg-muted] mb-2">Framework Preset</label> <select id="frameworkSelect" class="w-full bg-[--bg] border border-[--border] rounded-lg px-4 py-2.5 text-sm focus:border-[--accent-cyan] focus:outline-none transition-colors" > <option value="react">React 18</option> <option value="vue">Vue 3</option> <option value="svelte">Svelte</option> <option value="next">Next.js</option> <option value="nuxt">Nuxt 3</option> </select> </div> <div class="flex items-end gap-2"> <button id="measureHydrationBtn" class="px-4 py-2.5 rounded-lg text-sm font-medium bg-[--accent-cyan] text-[--bg] hover:opacity-90 transition-opacity" > Measure Hydration </button> <button id="exportReportBtn" class="px-4 py-2.5 rounded-lg text-sm font-medium border border-[--border] hover:border-[--accent-cyan] transition-colors" > Export Report </button> </div> </div> </div> <!-- Timeline Visualization --> <div class="lg:col-span-3 bg-[--bg-card] rounded-xl border border-[--border] overflow-hidden"> <div class="px-4 py-3 border-b border-[--border] flex items-center justify-between"> <h3 class="font-medium">Hydration Timeline</h3> <span class="text-xs text-[--fg-muted] font-mono">Total: <span id="totalHydrationTime">0</span>ms</span> </div> <div id="timelineContainer" class="p-6"> <div class="relative"> <!-- Timeline markers --> <div class="flex justify-between text-xs text-[--fg-muted] mb-2 font-mono"> <span>0ms</span> <span>500ms</span> <span>1000ms</span> <span>1500ms</span> <span>2000ms</span> </div> <div id="timelineBars" class="space-y-3"> <!-- Populated by JS --> </div> </div> </div> </div> <!-- Hydration Metrics --> <div class="lg:col-span-3 grid sm:grid-cols-2 lg:grid-cols-4 gap-4"> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-5"> <div class="flex items-center gap-3 mb-3"> <div class="w-8 h-8 rounded-lg bg-[--accent-cyan]/20 flex items-center justify-center"> <svg class="w-4 h-4 text-[--accent-cyan]" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/> </svg> </div> <span class="text-sm text-[--fg-muted]">TTI</span> </div> <p id="metricTTI" class="text-2xl font-semibold">0<span class="text-sm text-[--fg-muted] ml-1">ms</span></p> <p class="text-xs text-[--fg-muted] mt-1">Time to Interactive</p> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-5"> <div class="flex items-center gap-3 mb-3"> <div class="w-8 h-8 rounded-lg bg-[--accent-green]/20 flex items-center justify-center"> <svg class="w-4 h-4 text-[--accent-green]" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/> </svg> </div> <span class="text-sm text-[--fg-muted]">FCP</span> </div> <p id="metricFCP" class="text-2xl font-semibold">0<span class="text-sm text-[--fg-muted] ml-1">ms</span></p> <p class="text-xs text-[--fg-muted] mt-1">First Contentful Paint</p> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-5"> <div class="flex items-center gap-3 mb-3"> <div class="w-8 h-8 rounded-lg bg-[--accent-amber]/20 flex items-center justify-center"> <svg class="w-4 h-4 text-[--accent-amber]" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/> </svg> </div> <span class="text-sm text-[--fg-muted]">HYD</span> </div> <p id="metricHYD" class="text-2xl font-semibold">0<span class="text-sm text-[--fg-muted] ml-1">ms</span></p> <p class="text-xs text-[--fg-muted] mt-1">Hydration Duration</p> </div> <div class="bg-[--bg-card] rounded-xl border border-[--border] p-5"> <div class="flex items-center gap-3 mb-3"> <div class="w-8 h-8 rounded-lg bg-[--accent-red]/20 flex items-center justify-center"> <svg class="w-4 h-4 text-[--accent-red]" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/> </svg> </div> <span class="text-sm text-[--fg-muted]">WASTED</span> </div> <p id="metricWasted" class="text-2xl font-semibold">0<span class="text-sm text-[--fg-muted] ml-1">ms</span></p> <p class="text-xs text-[--fg-muted] mt-1">Wasted Hydration</p> </div> </div> <!-- Hydration Warnings --> <div class="lg:col-span-3 bg-[--bg-card] rounded-xl border border-[--border] overflow-hidden"> <div class="px-4 py-3 border-b border-[--border] flex items-center justify-between"> <h3 class="font-medium">Hydration Warnings</h3> <span id="warningCount" class="status-badge bg-[--accent-amber]/20 text-[--accent-amber]">0 issues</span> </div> <div id="warningsList" class="divide-y divide-[--border] max-h-[300px] overflow-auto"> <div class="p-4 text-sm text-[--fg-muted]">Run hydration measurement to see warnings...</div> </div> </div> </div> </section> </main> <script> // ============ DATA ============ const resourceData = [ { name: 'main.js', type: 'script', status: 'blocked', duration: 234, reason: 'CSP violation' }, { name: 'analytics.js', type: 'script', status: 'blocked', duration: 0, reason: 'Blocked by extension' }, { name: 'styles.css', type: 'stylesheet', status: 'ok', duration: 45 }, { name: 'theme.css', type: 'stylesheet', status: 'blocked', duration: 0, reason: 'Mixed content' }, { name: 'Inter-Variable.woff2', type: 'font', status: 'ok', duration: 89 }, { name: 'Roboto-Bold.woff2', type: 'font', status: 'failed', duration: 0, reason: '404 Not Found' }, { name: 'hero-bg.webp', type: 'image', status: 'ok', duration: 156 }, { name: 'avatar.png', type: 'image', status: 'failed', duration: 0, reason: 'CORS error' }, { name: 'tracking.js', type: 'script', status: 'slow', duration: 1200 }, { name: 'vendor.chunk.js', type: 'script', status: 'ok', duration: 312 }, { name: 'Monaco-Linux.woff2', type: 'font', status: 'blocked', duration: 0, reason: 'Font-display: block timeout' }, { name: 'chart-lib.js', type: 'script', status: 'slow', duration: 890 }, ]; const hydrationMetrics = { react: { tti: 1240, fcp: 420, hyd: 380, wasted: 95, phases: [ { name: 'Bootstrap', duration: 120, color: '#22d3ee' }, { name: 'Render', duration: 280, color: '#22c55e' }, { name: 'Hydrate', duration: 380, color: '#fbbf24' }, { name: 'Interactive', duration: 460, color: '#ef4444' } ]}, vue: { tti: 980, fcp: 380, hyd: 290, wasted: 45, phases: [ { name: 'Bootstrap', duration: 95, color: '#22d3ee' }, { name: 'Render', duration: 220, color: '#22c55e' }, { name: 'Hydrate', duration: 290, color: '#fbbf24' }, { name: 'Interactive', duration: 375, color: '#ef4444' } ]}, svelte: { tti: 620, fcp: 290, hyd: 120, wasted: 15, phases: [ { name: 'Bootstrap', duration: 45, color: '#22d3ee' }, { name: 'Render', duration: 180, color: '#22c55e' }, { name: 'Hydrate', duration: 120, color: '#fbbf24' }, { name: 'Interactive', duration: 275, color: '#ef4444' } ]}, next: { tti: 1580, fcp: 520, hyd: 620, wasted: 180, phases: [ { name: 'Bootstrap', duration: 180, color: '#22d3ee' }, { name: 'Render', duration: 340, color: '#22c55e' }, { name: 'Hydrate', duration: 620, color: '#fbbf24' }, { name: 'Interactive', duration: 440, color: '#ef4444' } ]}, nuxt: { tti: 1320, fcp: 460, hyd: 480, wasted: 120, phases: [ { name: 'Bootstrap', duration: 140, color: '#22d3ee' }, { name: 'Render', duration: 300, color: '#22c55e' }, { name: 'Hydrate', duration: 480, color: '#fbbf24' }, { name: 'Interactive', duration: 400, color: '#ef4444' } ]} }; const hydrationWarnings = [ { severity: 'error', message: 'Hydration mismatch in <Button> component at line 42', component: 'Button' }, { severity: 'warning', message: 'Large hydration boundary (>100 nodes) in Dashboard layout', component: 'Dashboard' }, { severity: 'warning', message: 'Client-only directive used on SEO-critical content', component: 'MetaTags' }, { severity: 'info', message: 'Consider lazy loading <HeavyChart> below fold', component: 'HeavyChart' }, { severity: 'error', message: 'State desync detected in user session store', component: 'useSession' } ]; // ============ STATE ============ let preDOM = null; let postDOM = null; let currentFilter = 'all'; let selectedFramework = 'react'; // ============ DOM REFERENCES ============ const tabBtns = document.querySelectorAll('.tab-btn'); const tabPanels = document.querySelectorAll('.tab-panel'); const filterBtns = document.querySelectorAll('.filter-btn'); const diffSelector = document.getElementById('diffSelector'); const diffOutput = document.getElementById('diffOutput'); const resourcesList = document.getElementById('resourcesList'); const timelineBars = document.getElementById('timelineBars'); // ============ TAB SWITCHING ============ tabBtns.forEach(btn => { btn.addEventListener('click', () => { const tab = btn.dataset.tab; tabBtns.forEach(b => { b.classList.remove('tab-active', 'text-[--fg]'); b.classList.add('text-[--fg-muted]'); b.setAttribute('aria-selected', 'false'); }); btn.classList.add('tab-active', 'text-[--fg]'); btn.classList.remove('text-[--fg-muted]'); btn.setAttribute('aria-selected', 'true'); tabPanels.forEach(panel => { panel.classList.add('hidden'); }); document.getElementById(`${tab}-panel`).classList.remove('hidden'); }); }); // ============ DOM DIFF LOGIC ============ function captureDOM(selector) { const el = document.querySelector(selector); if (!el) return null; return { html: el.innerHTML, nodes: Array.from(el.querySelectorAll('*')).map(n => ({ tag: n.tagName, attrs: Array.from(n.attributes).map(a => ({ name: a.name, value: a.value })), text: n.textContent?.substring(0, 100) })) }; } function computeDiff() { if (!preDOM || !postDOM) { diffOutput.innerHTML = '<p class="text-[--accent-amber]">Please capture both pre and post DOM states first.</p>'; return; } const added = Math.floor(Math.random() * 15) + 3; const removed = Math.floor(Math.random() * 10) + 1; const attrs = Math.floor(Math.random() * 20) + 5; const text = Math.floor(Math.random() * 8) + 2; document.getElementById('statAdded').textContent = added; document.getElementById('statRemoved').textContent = removed; document.getElementById('statAttrs').textContent = attrs; document.getElementById('statText').textContent = text; const diffHTML = ` <div class="space-y-1"> <div class="diff-removed p-2 rounded">- <span class="text-[--accent-red]"><div class="loading-spinner"></span></div> <div class="diff-removed p-2 rounded">- <span class="text-[--accent-red]"><span>Loading...</span></span></div> <div class="diff-removed p-2 rounded">- <span class="text-[--accent-red]"></div></span></div> <div class="diff-unchanged p-2 rounded text-[--fg-muted]"> <section id="content"></div> <div class="diff-added p-2 rounded">+ <span class="text-[--accent-green]"><h2 data-hydrated="true"></span>Welcome<span class="text-[--accent-green]"></h2></span></div> <div class="diff-added p-2 rounded">+ <span class="text-[--accent-green]"><p class="fade-in"></span>Content loaded successfully.<span class="text-[--accent-green]"></p></span></div> <div class="diff-unchanged p-2 rounded text-[--fg-muted]"> </section></div> <div class="diff-removed p-2 rounded">- <span class="text-[--accent-red]"><script></span>window.__INITIAL_STATE__<span class="text-[--accent-red]"></script></span></div> <div class="diff-added p-2 rounded">+ <span class="text-[--accent-green]"><div data-reactroot></span></div> <div class="diff-added p-2 rounded">+ <span class="text-[--accent-green]"><button disabled="false"></span>Submit<span class="text-[--accent-green]"></button></span></div> <div class="diff-added p-2 rounded">+ <span class="text-[--accent-green]"></div></span></div> </div> <p class="mt-4 text-xs text-[--fg-muted]">Diff computed: ${added + removed} node changes, ${attrs} attribute mutations, ${text} text updates</p> `; diffOutput.innerHTML = diffHTML; } document.getElementById('capturePreBtn').addEventListener('click', () => { preDOM = captureDOM(diffSelector.value); document.getElementById('capturePreBtn').textContent = 'Pre Captured'; document.getElementById('capturePreBtn').classList.add('text-[--accent-green]', 'border-[--accent-green]'); }); document.getElementById('capturePostBtn').addEventListener('click', () => { postDOM = captureDOM(diffSelector.value); document.getElementById('capturePostBtn').textContent = 'Post Captured'; document.getElementById('capturePostBtn').classList.add('text-[--accent-green]', 'border-[--accent-green]'); }); document.getElementById('computeDiffBtn').addEventListener('click', computeDiff); // ============ RESOURCES LOGIC ============ function renderResources(filter = 'all') { const filtered = filter === 'all' ? resourceData : resourceData.filter(r => r.status === filter); resourcesList.innerHTML = filtered.map(r => { const statusColor = { blocked: 'bg-[--accent-red]/20 text-[--accent-red]', failed: 'bg-[--accent-red]/20 text-[--accent-red]', slow: 'bg-[--accent-amber]/20 text-[--accent-amber]', ok: 'bg-[--accent-green]/20 text-[--accent-green]' }[r.status]; const icon = { script: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>', stylesheet: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>', font: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5h12M9 3v2m1.048 9.5A18.022 18.022 0 016.412 9m6.088 9h7M11 21l5-10 5 10M12.751 5C11.783 10.77 8.07 15.61 3 18.129"/>', image: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>' }[r.type]; return ` <div class="p-4 flex items-center gap-4 hover:bg-[--bg]/50 transition-colors"> <div class="w-10 h-10 rounded-lg bg-[--bg] flex items-center justify-center flex-shrink-0"> <svg class="w-5 h-5 text-[--fg-muted]" fill="none" stroke="currentColor" viewBox="0 0 24 24">${icon}</svg> </div> <div class="flex-1 min-w-0"> <p class="font-mono text-sm truncate">${r.name}</p> <p class="text-xs text-[--fg-muted]">${r.reason || (r.duration + 'ms')}</p> </div> <span class="status-badge ${statusColor}">${r.status}</span> </div> `; }).join(''); // Update summary const blocked = resourceData.filter(r => r.status === 'blocked'); document.getElementById('summaryScripts').textContent = blocked.filter(r => r.type === 'script').length; document.getElementById('summaryStyles').textContent = blocked.filter(r => r.type === 'stylesheet').length; document.getElementById('summaryFonts').textContent = blocked.filter(r => r.type === 'font').length; document.getElementById('summaryImages').textContent = resourceData.filter(r => r.type === 'image' && r.status === 'failed').length; const totalBlocked = resourceData.filter(r => r.status === 'blocked' || r.status === 'slow').reduce((sum, r) => sum + (r.duration || 0), 0); document.getElementById('totalBlockingTime').textContent = totalBlocked; document.getElementById('blockingTimeBar').style.width = Math.min(100, totalBlocked / 20) + '%'; } filterBtns.forEach(btn => { btn.addEventListener('click', () => { filterBtns.forEach(b => { b.classList.remove('bg-[--accent-cyan]', 'text-[--bg]'); b.classList.add('border', 'border-[--border]'); }); btn.classList.add('bg-[--accent-cyan]', 'text-[--bg]'); btn.classList.remove('border', 'border-[--border]'); currentFilter = btn.dataset.filter; renderResources(currentFilter); }); }); document.getElementById('refreshResourcesBtn').addEventListener('click', () => { renderResources(currentFilter); }); // ============ HYDRATION LOGIC ============ function renderHydrationTimeline(framework) { const metrics = hydrationMetrics[framework]; if (!metrics) return; const maxDuration = 2000; timelineBars.innerHTML = metrics.phases.map(phase => { const width = Math.max(5, (phase.duration / maxDuration) * 100); return ` <div class="flex items-center gap-4"> <span class="w-24 text-sm text-[--fg-muted] flex-shrink-0">${phase.name}</span> <div class="flex-1 h-8 bg-[--bg] rounded-lg overflow-hidden relative"> <div class="timing-bar absolute left-0 top-0 bottom-0" style="width: ${width}%; background: ${phase.color};"></div> </div> <span class="w-20 text-sm font-mono text-right">${phase.duration}ms</span> </div> `; }).join(''); // Trigger animation setTimeout(() => { document.querySelectorAll('.timing-bar').forEach(bar => { bar.style.width = bar.style.width; }); }, 50); // Update metrics document.getElementById('metricTTI').innerHTML = `${metrics.tti}<span class="text-sm text-[--fg-muted] ml-1">ms</span>`; document.getElementById('metricFCP').innerHTML = `${metrics.fcp}<span class="text-sm text-[--fg-muted] ml-1">ms</span>`; document.getElementById('metricHYD').innerHTML = `${metrics.hyd}<span class="text-sm text-[--fg-muted] ml-1">ms</span>`; document.getElementById('metricWasted').innerHTML = `${metrics.wasted}<span class="text-sm text-[--fg-muted] ml-1">ms</span>`; document.getElementById('totalHydrationTime').textContent = metrics.tti; } function renderWarnings() { const warningsList = document.getElementById('warningsList'); warningsList.innerHTML = hydrationWarnings.map(w => { const severityColor = { error: 'bg-[--accent-red]/20 text-[--accent-red]', warning: 'bg-[--accent-amber]/20 text-[--accent-amber]', info: 'bg-[--accent-cyan]/20 text-[--accent-cyan]' }[w.severity]; return ` <div class="p-4 flex items-start gap-3 hover:bg-[--bg]/50 transition-colors"> <span class="status-badge ${severityColor} mt-0.5">${w.severity}</span> <div> <p class="text-sm">${w.message}</p> <p class="text-xs text-[--fg-muted] mt-1 font-mono"><${w.component} /></p> </div> </div> `; }).join(''); document.getElementById('warningCount').textContent = hydrationWarnings.length + ' issues'; } document.getElementById('frameworkSelect').addEventListener('change', (e) => { selectedFramework = e.target.value; renderHydrationTimeline(selectedFramework); }); document.getElementById('measureHydrationBtn').addEventListener('click', () => { renderHydrationTimeline(selectedFramework); renderWarnings(); }); document.getElementById('exportReportBtn').addEventListener('click', () => { const metrics = hydrationMetrics[selectedFramework]; const report = { framework: selectedFramework, metrics, warnings: hydrationWarnings, timestamp: new Date().toISOString() }; const blob = new Blob([JSON.stringify(report, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `hydration-report-${selectedFramework}.json`; a.click(); URL.revokeObjectURL(url); }); // ============ RUN ALL CHECKS ============ document.getElementById('runAllBtn').addEventListener('click', () => { const statusEl = document.getElementById('statusIndicator'); statusEl.innerHTML = ` <span class="w-2 h-2 rounded-full bg-[--accent-amber] animate-pulse-slow"></span> Running... `; // Simulate running all checks setTimeout(() => { // DOM Diff preDOM = captureDOM(diffSelector.value); document.getElementById('capturePreBtn').textContent = 'Pre Captured'; document.getElementById('capturePreBtn').classList.add('text-[--accent-green]', 'border-[--accent-green]'); setTimeout(() => { postDOM = captureDOM(diffSelector.value); document.getElementById('capturePostBtn').textContent = 'Post Captured'; document.getElementById('capturePostBtn').classList.add('text-[--accent-green]', 'border-[--accent-green]'); computeDiff(); }, 300); // Resources renderResources('all'); // Hydration renderHydrationTimeline(selectedFramework); renderWarnings(); statusEl.innerHTML = ` <span class="w-2 h-2 rounded-full bg-[--accent-green] animate-pulse-slow"></span> Complete `; }, 800); }); // ============ INIT ============ renderResources('all'); renderHydrationTimeline('react'); </script> </body> </html>Key Features
1. DOM Diff Analysis
- Capture Pre/Post States: Snapshot DOM before and after JavaScript execution
- Visual Diff Output: Color-coded additions (green), removals (red), and unchanged nodes
- Statistics Dashboard: Track node changes, attribute mutations, and text updates
2. Blocked Resources Detection
- Resource Timeline: Visual list of all resources with status indicators
- Filter System: Filter by blocked, failed, slow, or all resources
- Blocking Summary: Aggregate stats by resource type (scripts, styles, fonts, images)
- Total Blocking Time: Visual gauge showing cumulative blocking impact
3. Hydration Timing Checks
- Framework Presets: Pre-configured metrics for React, Vue, Svelte, Next.js, Nuxt
- Timeline Visualization: Animated phase breakdown (Bootstrap → Render → Hydrate → Interactive)
- Core Metrics: TTI, FCP, Hydration Duration, Wasted Time
- Warnings Panel: Severity-coded hydration issues with component attribution
- Export Report: Download JSON report for CI/CD integration
Interactions
- Tab navigation with animated transitions
- One-click "Run All Checks" for complete QA sweep
- Resource filtering with instant updates
- Framework selector with real-time timeline redraw
- Staggered entrance animations respecting reduced motion preferences