deepsite / PREVIEW_SMOOTH_TRANSITIONS_FIX.md
dr-data
Fix preview component: eliminate blinking, ensure HTML updates, add smooth transitions
dcd5e1d

Preview Smooth Transitions Fix

Problem

The preview component was showing jarring transitions with:

  • Black screen with "Updating preview smoothly..." message
  • Sudden pop-ups of new HTML content
  • Sharp, annoying transitions instead of smooth updates
  • Blinking effect between content changes

Root Causes Identified

  1. Overly intrusive loading overlay - Full-screen overlay blocking content
  2. Dual iframe system not working properly - Both iframes used same content
  3. Immediate srcDoc updates - Causing sudden pop-up effects
  4. Complex update logic - Race conditions and unreliable state management
  5. Black background - Creating harsh visual contrast

Fixes Implemented

1. Fixed HTML Update Logic

  • Immediate updates when AI finishes: Ensures final output is always displayed
  • Seamless content injection: Tries DOM manipulation first for zero-flash updates
  • Dual iframe fallback: Uses smooth iframe swapping when injection fails
  • Simplified debouncing: 300ms debounce for streaming updates only

2. Improved Dual Iframe System

  • Proper content separation: Primary and secondary iframes now use different content
  • Smooth transitions: CSS-based opacity and transform transitions
  • Correct iframe switching: Only active iframe gets new content

3. Reduced Loading Overlay Intrusion

  • Removed full-screen overlay: No more blocking black screen
  • Subtle corner indicator: Small, non-intrusive loading indicator
  • Conditional display: Only shows during actual transitions

4. Enhanced Visual Smoothness

  • White backgrounds: Changed from black to white for softer transitions
  • CSS hardware acceleration: Better performance with will-change and transform3d
  • Smooth easing curves: Cubic-bezier transitions for natural feel

5. Immediate Content Display

  • Initialize displayHtml: Ensures content shows immediately on component mount
  • Skip unnecessary updates: Prevents redundant re-renders
  • Force final updates: Guarantees AI completion results are displayed

Technical Details

Updated Files

  1. /components/editor/preview/index.tsx - Main preview component logic
  2. /assets/globals.css - CSS transitions and background colors

Key Changes

  • Simplified useEffect hook for HTML updates
  • Fixed dual iframe srcDoc assignment
  • Reduced loading state triggers
  • Improved error handling for TypeScript compliance

Benefits

  • ✅ No more jarring black screen transitions
  • ✅ Smooth, fade-based content updates
  • ✅ Reliable display of final AI output
  • ✅ Better performance with hardware acceleration
  • ✅ Reduced visual disruption during streaming

Testing Recommendations

  1. Test initial page load with default HTML
  2. Test AI streaming updates for smoothness
  3. Verify final output always displays after AI completion
  4. Check mobile device responsiveness
  5. Test rapid consecutive AI requests

The preview should now provide smooth, professional transitions without blinking or sudden content changes.