From bd123c4bb91ddb6d30ee5ef240e1872affb5f795 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Thu, 26 Jun 2025 10:57:24 -0700 Subject: [PATCH] fix(src/utils): enforce consistent formatting and enhance worker script initialization Refactored worker script initialization in `src/utils/workerUtils.ts` by introducing global variables for safer script execution. Applied consistent formatting adjustments, including removal of redundant semicolons, to improve code readability and maintainability without altering functionality. --- src/utils/workerUtils.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/utils/workerUtils.ts b/src/utils/workerUtils.ts index 263d4d30..46d80f51 100644 --- a/src/utils/workerUtils.ts +++ b/src/utils/workerUtils.ts @@ -15,18 +15,24 @@ export function executeInWebWorker(fnString: string, args: any): Promise { return new Promise((resolve, reject) => { // Create a blob URL for the worker script const workerScript = ` + // Define global variables to prevent "is not defined" errors + // This ensures that any minified variable names used by bundlers are available + self.index = {} + self.index$1 = {} + self.index$2 = {} + self.onmessage = async function(e) { try { - const fn = ${fnString}; - const result = await fn(e.data); - self.postMessage({ success: true, data: result }); + const fn = ${fnString} + const result = await fn(e.data) + self.postMessage({ success: true, data: result }) } catch (error) { self.postMessage({ success: false, error: error instanceof Error ? error.message : String(error) - }); + }) } - }; + } ` const blob = new Blob([workerScript], { type: 'application/javascript' }) @@ -78,20 +84,20 @@ export function executeInWorkerThread( // Create a worker script const workerScript = ` - const { parentPort } = require('worker_threads'); + const { parentPort } = require('worker_threads') parentPort.once('message', async (data) => { try { - const fn = ${fnString}; - const result = await fn(data); - parentPort.postMessage({ success: true, data: result }); + const fn = ${fnString} + const result = await fn(data) + parentPort.postMessage({ success: true, data: result }) } catch (error) { parentPort.postMessage({ success: false, error: error instanceof Error ? error.message : String(error) - }); + }) } - }); + }) ` // Create a worker