diff --git a/components/SandboxPreview.tsx b/components/SandboxPreview.tsx index d5009ca..502873e 100644 --- a/components/SandboxPreview.tsx +++ b/components/SandboxPreview.tsx @@ -1,33 +1,24 @@ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import { Loader2, ExternalLink, RefreshCw, Terminal } from 'lucide-react'; interface SandboxPreviewProps { - sandboxId: string; - port: number; type: 'vite' | 'nextjs' | 'console'; output?: string; isLoading?: boolean; + sandboxUrl?: string; // Real URL from Vercel Sandbox API } export default function SandboxPreview({ - sandboxId, - port, type, output, - isLoading = false + isLoading = false, + sandboxUrl }: SandboxPreviewProps) { - const [previewUrl, setPreviewUrl] = useState(''); const [showConsole, setShowConsole] = useState(false); const [iframeKey, setIframeKey] = useState(0); - useEffect(() => { - if (sandboxId && type !== 'console') { - // For Vercel Sandbox, we'll receive the full URL from the API - // The URL format is determined by Vercel Sandbox's domain() method - // This is just a fallback format - actual URL comes from sandbox.domain(port) - setPreviewUrl(`https://${sandboxId}.vercel-sandbox.dev`); - } - }, [sandboxId, port, type]); + // Use the real sandbox URL passed from the API + const previewUrl = sandboxUrl || ''; const handleRefresh = () => { setIframeKey(prev => prev + 1); @@ -51,9 +42,13 @@ export default function SandboxPreview({ {type === 'vite' ? '⚡ Vite' : '▲ Next.js'} Preview - - {previewUrl} - + {previewUrl ? ( + + {previewUrl} + + ) : ( + Waiting for sandbox URL... + )}
- - - + {previewUrl && ( + + + + )}
{/* Main Preview */}
- {isLoading && ( + {(isLoading || !previewUrl) && (

- {type === 'vite' ? 'Starting Vite dev server...' : 'Starting Next.js dev server...'} + {!previewUrl + ? 'Setting up sandbox environment...' + : type === 'vite' + ? 'Starting Vite dev server...' + : 'Starting Next.js dev server...' + }

)} -