Skip to content

Commit 4c79376

Browse files
[autofix.ci] apply automated fixes
1 parent a3d2888 commit 4c79376

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

frontend/src/components/chat/code-engine/web-view.tsx

+45-31
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ function PreviewContent({
4848
method: 'HEAD',
4949
cache: 'no-store',
5050
signal: controller.signal,
51-
headers: { 'Cache-Control': 'no-cache' }
51+
headers: { 'Cache-Control': 'no-cache' },
5252
});
53-
53+
5454
clearTimeout(timeoutId);
55-
55+
5656
// Service is ready if we get a successful response (not 404 or 5xx)
57-
const isReady = response.ok || (response.status !== 404 && response.status < 500);
58-
console.log(`Service check: ${url} - Status: ${response.status} - Ready: ${isReady}`);
57+
const isReady =
58+
response.ok || (response.status !== 404 && response.status < 500);
59+
console.log(
60+
`Service check: ${url} - Status: ${response.status} - Ready: ${isReady}`
61+
);
5962
return isReady;
6063
} catch (error) {
6164
// Don't log abort errors (expected when timeout occurs)
@@ -76,19 +79,19 @@ function PreviewContent({
7679
setServiceCheckAttempts(0);
7780
setIsServiceReady(false);
7881
setLoadingMessage('Loading preview...');
79-
82+
8083
// Try immediately first (don't wait for interval)
8184
const initialReady = await checkServiceReady(url);
8285
if (initialReady) {
8386
console.log('Frontend service is ready immediately!');
8487
setIsServiceReady(true);
8588
return; // Exit early if service is ready immediately
8689
}
87-
90+
8891
// Progressive check intervals (check more frequently at first)
8992
const checkIntervals = [500, 1000, 1000, 1500, 1500]; // First few checks are faster
9093
let checkIndex = 0;
91-
94+
9295
// Set a fallback timer - show preview after 45 seconds no matter what
9396
const fallbackTimer = setTimeout(() => {
9497
console.log('Fallback timer triggered - showing preview anyway');
@@ -98,17 +101,19 @@ function PreviewContent({
98101
serviceCheckTimerRef.current = null;
99102
}
100103
}, 45000);
101-
104+
102105
const runServiceCheck = async () => {
103-
setServiceCheckAttempts(prev => prev + 1);
104-
106+
setServiceCheckAttempts((prev) => prev + 1);
107+
105108
// Update loading message with attempts
106109
if (serviceCheckAttempts > 3) {
107-
setLoadingMessage(`Starting frontend service... (${serviceCheckAttempts}/${MAX_CHECK_ATTEMPTS})`);
110+
setLoadingMessage(
111+
`Starting frontend service... (${serviceCheckAttempts}/${MAX_CHECK_ATTEMPTS})`
112+
);
108113
}
109-
114+
110115
const ready = await checkServiceReady(url);
111-
116+
112117
if (ready) {
113118
console.log('Frontend service is ready!');
114119
setIsServiceReady(true);
@@ -119,27 +124,32 @@ function PreviewContent({
119124
}
120125
} else if (serviceCheckAttempts >= MAX_CHECK_ATTEMPTS) {
121126
// Service didn't become ready after max attempts
122-
console.log('Max attempts reached. Service might still be initializing.');
123-
setLoadingMessage('Preview might not be fully loaded. Click refresh to try again.');
124-
127+
console.log(
128+
'Max attempts reached. Service might still be initializing.'
129+
);
130+
setLoadingMessage(
131+
'Preview might not be fully loaded. Click refresh to try again.'
132+
);
133+
125134
// Show the preview anyway after max attempts
126135
setIsServiceReady(true);
127136
clearTimeout(fallbackTimer);
128-
137+
129138
if (serviceCheckTimerRef.current) {
130139
clearInterval(serviceCheckTimerRef.current);
131140
serviceCheckTimerRef.current = null;
132141
}
133142
} else {
134143
// Schedule next check with dynamic interval
135-
const nextInterval = checkIndex < checkIntervals.length
136-
? checkIntervals[checkIndex++]
137-
: 2000; // Default to 2000ms after initial fast checks
138-
144+
const nextInterval =
145+
checkIndex < checkIntervals.length
146+
? checkIntervals[checkIndex++]
147+
: 2000; // Default to 2000ms after initial fast checks
148+
139149
setTimeout(runServiceCheck, nextInterval);
140150
}
141151
};
142-
152+
143153
// Start the first check
144154
setTimeout(runServiceCheck, 500);
145155
};
@@ -164,7 +174,7 @@ function PreviewContent({
164174
}
165175

166176
lastProjectPathRef.current = projectPath;
167-
177+
168178
// Reset service ready state for new project
169179
setIsServiceReady(false);
170180

@@ -187,7 +197,7 @@ function PreviewContent({
187197
console.log('baseUrl:', baseUrl);
188198
setBaseUrl(baseUrl);
189199
setDisplayPath('/');
190-
200+
191201
// Start checking if the service is ready
192202
startServiceReadyCheck(baseUrl);
193203
} catch (error) {
@@ -250,7 +260,7 @@ function PreviewContent({
250260
setIsServiceReady(false);
251261
startServiceReadyCheck(baseUrl);
252262
}
253-
263+
254264
const iframe = document.getElementById('myIframe') as HTMLIFrameElement;
255265
if (iframe) {
256266
const src = iframe.src;
@@ -290,7 +300,9 @@ function PreviewContent({
290300
size="icon"
291301
className="h-6 w-6"
292302
onClick={goForward}
293-
disabled={!baseUrl || currentIndex >= history.length - 1 || !isServiceReady}
303+
disabled={
304+
!baseUrl || currentIndex >= history.length - 1 || !isServiceReady
305+
}
294306
>
295307
<ChevronRight className="h-4 w-4" />
296308
</Button>
@@ -379,11 +391,13 @@ function PreviewContent({
379391
<div className="flex flex-col items-center gap-2">
380392
<div className="flex items-center gap-2">
381393
<div className="animate-spin w-4 h-4 border-2 border-primary border-t-transparent rounded-full"></div>
382-
<p className="text-sm text-muted-foreground">{loadingMessage}</p>
394+
<p className="text-sm text-muted-foreground">
395+
{loadingMessage}
396+
</p>
383397
</div>
384398
{serviceCheckAttempts > 5 && (
385-
<Button
386-
variant="outline"
399+
<Button
400+
variant="outline"
387401
size="sm"
388402
onClick={() => {
389403
if (baseUrl) {
@@ -414,4 +428,4 @@ export default function WebPreview() {
414428
}
415429

416430
return <PreviewContent curProject={curProject} getWebUrl={getWebUrl} />;
417-
}
431+
}

0 commit comments

Comments
 (0)