@@ -22,36 +22,9 @@ import {
2222 classifyErrorSeverity ,
2323 SEVERITY_CONFIG ,
2424} from '~/utils/errors/errorConfig' ;
25- import {
26- autoFixStore ,
27- startAutoFix ,
28- shouldContinueFix ,
29- hasExceededMaxRetries ,
30- type ErrorSource ,
31- } from '~/lib/stores/autofix' ;
32- import type { AutoFixCallback } from './terminalErrorDetector' ;
3325
3426const logger = createScopedLogger ( 'PreviewErrorHandler' ) ;
3527
36- // Global auto-fix callback - shared with terminal error detector
37- let globalPreviewAutoFixCallback : AutoFixCallback | null = null ;
38-
39- /**
40- * Register a callback to handle auto-fix requests from preview errors
41- */
42- export function registerPreviewAutoFixCallback ( callback : AutoFixCallback ) : void {
43- globalPreviewAutoFixCallback = callback ;
44- logger . debug ( 'Preview auto-fix callback registered' ) ;
45- }
46-
47- /**
48- * Unregister the preview auto-fix callback
49- */
50- export function unregisterPreviewAutoFixCallback ( ) : void {
51- globalPreviewAutoFixCallback = null ;
52- logger . debug ( 'Preview auto-fix callback unregistered' ) ;
53- }
54-
5528/**
5629 * Simple hash function for error deduplication
5730 */
@@ -195,43 +168,11 @@ class PreviewErrorHandler {
195168 const content = contentParts . join ( '\n' ) ;
196169
197170 /*
198- * Check if we should trigger auto-fix instead of showing alert
199- * Auto-fixable errors are typically code issues (SyntaxError, TypeError, ReferenceError, etc.)
171+ * Preview errors are NOT auto-fixed — always show the alert and let the user
172+ * decide whether to ask Devonz for help. Auto-fix from previews was too aggressive,
173+ * triggering on transient build errors (e.g., missing files while AI is still writing)
174+ * and wasting tokens on unnecessary LLM calls.
200175 */
201- const isAutoFixable = this . #isAutoFixableError( errorMessage ) ;
202- const canAutoFix = isAutoFixable && shouldContinueFix ( ) && globalPreviewAutoFixCallback ;
203-
204- if ( canAutoFix ) {
205- // Trigger auto-fix instead of showing alert
206- const started = startAutoFix ( {
207- source : 'preview' as ErrorSource ,
208- type : severity ,
209- message : description ,
210- content,
211- } ) ;
212-
213- if ( started && globalPreviewAutoFixCallback ) {
214- logger . info ( `Auto-fix triggered for preview error: ${ title } ` ) ;
215-
216- // Add delay before triggering fix
217- const autoFixState = autoFixStore . get ( ) ;
218- setTimeout ( ( ) => {
219- globalPreviewAutoFixCallback ?.( {
220- source : 'preview' as ErrorSource ,
221- type : severity ,
222- message : description ,
223- content,
224- } ) ;
225- } , autoFixState . settings . delayBetweenAttempts ) ;
226-
227- return ; // Don't show alert, auto-fix is handling it
228- }
229- }
230-
231- // If auto-fix didn't trigger, show max retries warning if applicable
232- if ( isAutoFixable && hasExceededMaxRetries ( ) ) {
233- logger . warn ( 'Max auto-fix retries exceeded for preview error, showing alert to user' ) ;
234- }
235176
236177 /* Lazy import to avoid circular dependency */
237178 const { workbenchStore } = await import ( '~/lib/stores/workbench' ) ;
@@ -248,36 +189,6 @@ class PreviewErrorHandler {
248189 }
249190
250191 /**
251- * Check if an error is auto-fixable (code issues that the LLM can fix)
252- */
253- #isAutoFixableError( errorMessage : string ) : boolean {
254- const autoFixablePatterns = [
255- / S y n t a x E r r o r / i,
256- / T y p e E r r o r / i,
257- / R e f e r e n c e E r r o r / i,
258- / R a n g e E r r o r / i,
259- / C a n n o t f i n d m o d u l e / i,
260- / M o d u l e n o t f o u n d / i,
261- / d o e s n o t p r o v i d e a n e x p o r t / i,
262- / F a i l e d t o r e s o l v e i m p o r t / i,
263- / U n e x p e c t e d t o k e n / i,
264- / i s n o t d e f i n e d / i,
265- / i s n o t a f u n c t i o n / i,
266- / C a n n o t r e a d p r o p e r t / i,
267- / E l e m e n t t y p e i s i n v a l i d / i,
268- / O b j e c t s a r e n o t v a l i d a s a R e a c t c h i l d / i,
269- / M a x i m u m u p d a t e d e p t h e x c e e d e d / i,
270- / I n v a l i d h o o k c a l l / i,
271- / m u s t b e u s e d w i t h i n / i,
272- / I n v a r i a n t V i o l a t i o n / i,
273- / C h u n k L o a d E r r o r / i,
274- / F a i l e d t o f e t c h d y n a m i c a l l y i m p o r t e d m o d u l e / i,
275- / C a n n o t u s e i m p o r t s t a t e m e n t o u t s i d e a m o d u l e / i,
276- ] ;
277-
278- return autoFixablePatterns . some ( ( pattern ) => pattern . test ( errorMessage ) ) ;
279- }
280-
281192 /**
282193 * Reset the handler state
283194 * Call this when user clicks "Ask Devonz" so the same error can be caught again
0 commit comments