From af415e89e8c074a3f7c84f76f24020a7bd545483 Mon Sep 17 00:00:00 2001 From: Nick Oliver Date: Sat, 29 Feb 2020 21:38:15 -0700 Subject: [PATCH] fix: do not load SearchWorker if disableSearch is `true` (#1191) Blob URLs may be disabled by CORS (ex: #764) but should not block execution when the disableSearch option is true --- src/services/SearchStore.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/services/SearchStore.ts b/src/services/SearchStore.ts index ab80b71c8a..d096debe3f 100644 --- a/src/services/SearchStore.ts +++ b/src/services/SearchStore.ts @@ -4,21 +4,23 @@ import { OperationModel } from './models'; import Worker from './SearchWorker.worker'; -let worker: new () => Worker; - -if (IS_BROWSER) { - try { - // tslint:disable-next-line - worker = require('workerize-loader?inline&fallback=false!./SearchWorker.worker'); - } catch (e) { +function getWorker() { + let worker: new () => Worker; + if (IS_BROWSER) { + try { + // tslint:disable-next-line + worker = require('workerize-loader?inline&fallback=false!./SearchWorker.worker'); + } catch (e) { + worker = require('./SearchWorker.worker').default; + } + } else { worker = require('./SearchWorker.worker').default; } -} else { - worker = require('./SearchWorker.worker').default; + return new worker(); } export class SearchStore { - searchWorker = new worker(); + searchWorker = getWorker(); indexItems(groups: Array) { const recurse = items => {