Skip to content

Commit c84dd32

Browse files
jeski-brightJedrzej Sadowskichristian-bromann
authoredJun 26, 2024··
fix(compiler): try to create web worker with the workerPath before falling back to blob (#3513)
Co-authored-by: Jedrzej Sadowski <jedrzej.sadowski@justeattakeaway.com> Co-authored-by: Christian Bromann <git@bromann.dev>
1 parent 27109d2 commit c84dd32

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎src/compiler/bundle/worker-plugin.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,17 @@ import { createWorker } from '${WORKER_HELPER_ID}';
416416
export const workerName = '${workerName}';
417417
export const workerMsgId = '${workerMsgId}';
418418
export const workerPath = /*@__PURE__*/import.meta.ROLLUP_FILE_URL_${referenceId};
419-
const blob = new Blob(['importScripts("' + workerPath + '")'], { type: 'text/javascript' });
420-
const url = URL.createObjectURL(blob);
421-
export const worker = /*@__PURE__*/createWorker(url, workerName, workerMsgId);
422-
URL.revokeObjectURL(url);
419+
export let worker;
420+
try {
421+
// first try directly starting the worker with the URL
422+
worker = /*@__PURE__*/createWorker(workerPath, workerName, workerMsgId);
423+
} catch(e) {
424+
// probably a cross-origin issue, try using a Blob instead
425+
const blob = new Blob(['importScripts("' + workerPath + '")'], { type: 'text/javascript' });
426+
const url = URL.createObjectURL(blob);
427+
worker = /*@__PURE__*/createWorker(url, workerName, workerMsgId);
428+
URL.revokeObjectURL(url);
429+
}
423430
`;
424431
};
425432

0 commit comments

Comments
 (0)
Please sign in to comment.