From d266ce7c9bca24c9f21153bb359f10923a4cb937 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Tue, 1 Oct 2024 21:39:02 +0000 Subject: [PATCH] move null check --- .../src/contexts/StateContextProvider.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/new-log-viewer/src/contexts/StateContextProvider.tsx b/new-log-viewer/src/contexts/StateContextProvider.tsx index 0132dd18..cb834af3 100644 --- a/new-log-viewer/src/contexts/StateContextProvider.tsx +++ b/new-log-viewer/src/contexts/StateContextProvider.tsx @@ -161,15 +161,9 @@ const getPageNumCursor = ( * @param cursor */ const loadPageByCursor = ( - worker: Nullable, + worker: Worker, cursor: CursorType, ) => { - if (null === worker) { - console.error("Unexpected null worker"); - - return; - } - workerPostReq(worker, WORKER_REQ_CODE.LOAD_PAGE, { cursor: cursor, decoderOptions: getConfig(CONFIG_KEY.DECODER_OPTIONS), @@ -291,6 +285,11 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { const loadPageByAction = useCallback((navAction: NavigationAction) => { + if (null === mainWorkerRef.current) { + console.error("Unexpected null mainWorkerRef.current"); + + return; + } const cursor = getPageNumCursor(navAction, pageNumRef.current, numPagesRef.current); if (null === cursor) { console.error(`Error with nav action ${navAction.code}.`); @@ -316,6 +315,12 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { // On `logEventNum` update, clamp it then switch page if necessary or simply update the URL. useEffect(() => { + if (null === mainWorkerRef.current) { + console.error("Unexpected null mainWorkerRef.current"); + + return; + } + if (URL_HASH_PARAMS_DEFAULT.logEventNum === logEventNum) { return; }