Skip to content

Commit 8033e5b

Browse files
Copilotsapphi-red
andauthored
fix(worker): resolve WebKit compat with inline workers by deferring blob URL revocation (#20460)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Co-authored-by: 翠 <green@sapphi.red>
1 parent 22ad43b commit 8033e5b

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

packages/vite/src/node/plugins/worker.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
292292
workerConstructor === 'Worker'
293293
? `${jsContent}
294294
const blob = typeof self !== "undefined" && self.Blob && new Blob([${
295+
// NOTE: Revoke the objURL after creating the worker, otherwise it breaks WebKit-based browsers
295296
workerType === 'classic'
296-
? ''
297+
? `'(self.URL || self.webkitURL).revokeObjectURL(self.location.href);',`
297298
: // `URL` is always available, in `Worker[type="module"]`
298299
`'URL.revokeObjectURL(import.meta.url);',`
299300
}jsContent], { type: "text/javascript;charset=utf-8" });
@@ -312,14 +313,6 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
312313
'data:text/javascript;charset=utf-8,' + encodeURIComponent(jsContent),
313314
${workerTypeOption}
314315
);
315-
}${
316-
// For module workers, we should not revoke the URL until the worker runs,
317-
// otherwise the worker fails to run
318-
workerType === 'classic'
319-
? ` finally {
320-
objURL && (self.URL || self.webkitURL).revokeObjectURL(objURL);
321-
}`
322-
: ''
323316
}
324317
}`
325318
: `${jsContent}

0 commit comments

Comments
 (0)