From 9a748177ef2b4fb21d577a921ad6731b7450f7bf Mon Sep 17 00:00:00 2001 From: KevIsDev Date: Sat, 10 May 2025 13:24:08 +0100 Subject: [PATCH] refactor: optimize error handling and npm install performance Remove redundant error type handling in webcontainer to simplify logic and improve maintainability. Additionally, comment out lock file patterns to speed up npm install process. --- app/components/chat/GitCloneButton.tsx | 3 ++- app/components/git/GitUrlImport.client.tsx | 3 ++- app/lib/webcontainer/index.ts | 20 +++----------------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/app/components/chat/GitCloneButton.tsx b/app/components/chat/GitCloneButton.tsx index 3fcebdc4..aa0182f6 100644 --- a/app/components/chat/GitCloneButton.tsx +++ b/app/components/chat/GitCloneButton.tsx @@ -27,7 +27,8 @@ const IGNORE_PATTERNS = [ '**/npm-debug.log*', '**/yarn-debug.log*', '**/yarn-error.log*', - '**/*lock.json', + + // Include this so npm install runs much faster '**/*lock.json', '**/*lock.yaml', ]; diff --git a/app/components/git/GitUrlImport.client.tsx b/app/components/git/GitUrlImport.client.tsx index 6053acdc..eb1bfbbe 100644 --- a/app/components/git/GitUrlImport.client.tsx +++ b/app/components/git/GitUrlImport.client.tsx @@ -31,7 +31,8 @@ const IGNORE_PATTERNS = [ '**/npm-debug.log*', '**/yarn-debug.log*', '**/yarn-error.log*', - '**/*lock.json', + + // Include this so npm install runs much faster '**/*lock.json', '**/*lock.yaml', ]; diff --git a/app/lib/webcontainer/index.ts b/app/lib/webcontainer/index.ts index 5591e396..f64b59fd 100644 --- a/app/lib/webcontainer/index.ts +++ b/app/lib/webcontainer/index.ts @@ -39,27 +39,13 @@ if (!import.meta.env.SSR) { console.log('WebContainer preview message:', message); // Handle both uncaught exceptions and unhandled promise rejections - if ( - message.type === 'PREVIEW_UNCAUGHT_EXCEPTION' || - message.type === 'PREVIEW_UNHANDLED_REJECTION' || - message.type === 'PREVIEW_CONSOLE_ERROR' - ) { + if (message.type === 'PREVIEW_UNCAUGHT_EXCEPTION' || message.type === 'PREVIEW_UNHANDLED_REJECTION') { const isPromise = message.type === 'PREVIEW_UNHANDLED_REJECTION'; - const isConsoleError = message.type === 'PREVIEW_CONSOLE_ERROR'; - const title = isPromise - ? 'Unhandled Promise Rejection' - : isConsoleError - ? 'Console Error' - : 'Uncaught Exception'; + const title = isPromise ? 'Unhandled Promise Rejection' : 'Uncaught Exception'; workbenchStore.actionAlert.set({ type: 'preview', title, - description: - 'message' in message - ? message.message - : 'args' in message && Array.isArray(message.args) && message.args.length > 0 - ? message.args[0] - : 'Unknown error', + description: 'message' in message ? message.message : 'Unknown error', content: `Error occurred at ${message.pathname}${message.search}${message.hash}\nPort: ${message.port}\n\nStack trace:\n${cleanStackTrace(message.stack || '')}`, source: 'preview', });