Skip to content

Commit

Permalink
fix(compiler): try to create web worker with the workerPath before fa…
Browse files Browse the repository at this point in the history
…lling back to blob (#3513)

Co-authored-by: Jedrzej Sadowski <[email protected]>
Co-authored-by: Christian Bromann <[email protected]>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 27109d2 commit c84dd32
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/compiler/bundle/worker-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,17 @@ import { createWorker } from '${WORKER_HELPER_ID}';
export const workerName = '${workerName}';
export const workerMsgId = '${workerMsgId}';
export const workerPath = /*@__PURE__*/import.meta.ROLLUP_FILE_URL_${referenceId};
const blob = new Blob(['importScripts("' + workerPath + '")'], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
export const worker = /*@__PURE__*/createWorker(url, workerName, workerMsgId);
URL.revokeObjectURL(url);
export let worker;
try {
// first try directly starting the worker with the URL
worker = /*@__PURE__*/createWorker(workerPath, workerName, workerMsgId);
} catch(e) {
// probably a cross-origin issue, try using a Blob instead
const blob = new Blob(['importScripts("' + workerPath + '")'], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
worker = /*@__PURE__*/createWorker(url, workerName, workerMsgId);
URL.revokeObjectURL(url);
}
`;
};

Expand Down

0 comments on commit c84dd32

Please sign in to comment.