From 79d57b49c9390ae002d2cb78d7cf9f78fdca3103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jamr=C3=B3z?= Date: Fri, 22 Nov 2024 15:19:02 +0100 Subject: [PATCH] Add more docs --- public/app/core/utils/CorsSharedWorker.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/app/core/utils/CorsSharedWorker.ts b/public/app/core/utils/CorsSharedWorker.ts index 2f935a2b4ae..89bf9218b0b 100644 --- a/public/app/core/utils/CorsSharedWorker.ts +++ b/public/app/core/utils/CorsSharedWorker.ts @@ -14,10 +14,22 @@ class SharedWorkerNotSupported implements SharedWorker { addEventListener(): void {} removeEventListener(): void {} } + +/** + * The base class is created dynamically here to allow later on syntax like: + * import { CorsSharedWorker as SharedWorker } from '../utils/CorsSharedWorker'; + * And also take into account cases where SharedWorked is not available in the browser (mainly mobile browsers) + * + * It's important to use: new SharedWorker(...) syntax instead of new CorsSharedWorker(...) due to how web-workers + * are processing workers syntax (more details https://webpack.js.org/guides/web-workers/) + */ const BaseSharedWorkerClass = sharedWorkersSupported() ? window.SharedWorker : SharedWorkerNotSupported; export class CorsSharedWorker extends BaseSharedWorkerClass { constructor(url: URL, options?: WorkerOptions) { + if (!sharedWorkersSupported()) { + return; + } // by default, worker inherits HTML document's location and pathname which leads to wrong public path value // the CorsWorkerPlugin will override it with the value based on the initial worker chunk, ie. // initial worker chunk: http://host.com/cdn/scripts/worker-123.js