File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -124,12 +124,22 @@ export function JavaScriptProvider({ children }: { children: ReactNode }) {
124124 // Create a new worker
125125 initializeWorker ( ) ;
126126
127- // Wait for initialization - use a different approach
128- await new Promise < void > ( ( resolve ) => {
127+ // Wait for initialization with timeout
128+ const maxRetries = 50 ; // 5 seconds total
129+ let retries = 0 ;
130+
131+ await new Promise < void > ( ( resolve , reject ) => {
129132 const checkInterval = setInterval ( ( ) => {
133+ retries ++ ;
134+ if ( retries > maxRetries ) {
135+ clearInterval ( checkInterval ) ;
136+ reject ( new Error ( "Worker initialization timeout" ) ) ;
137+ return ;
138+ }
139+
130140 if ( workerRef . current ) {
131- // Try to initialize and restore
132- postMessage < InitPayloadFromWorker > ( {
141+ // Try to restore state
142+ postMessage < { success : boolean } > ( {
133143 type : "restoreState" ,
134144 } ) . then ( ( ) => {
135145 clearInterval ( checkInterval ) ;
Original file line number Diff line number Diff line change @@ -46,7 +46,8 @@ async function runJavaScript(id, payload) {
4646 // Save the successfully executed command for state recovery
4747 executedCommands . push ( code ) ;
4848 } catch ( e ) {
49- console . log ( e ) ;
49+ // Use self.console to avoid recursion with our console proxy
50+ self . console . log ( e ) ;
5051 if ( e instanceof Error ) {
5152 jsOutput . push ( {
5253 type : "error" ,
@@ -105,7 +106,8 @@ async function restoreState(id) {
105106 executedCommands . push ( command ) ;
106107 } catch ( e ) {
107108 // If restoration fails, we still continue with other commands
108- console . error ( "Failed to restore command:" , command , e ) ;
109+ // Use self.console to avoid recursion with our console proxy
110+ self . console . error ( "Failed to restore command:" , command , e ) ;
109111 }
110112 }
111113
You can’t perform that action at this time.
0 commit comments