diff --git a/specifyweb/frontend/js_src/lib/components/Atoms/index.tsx b/specifyweb/frontend/js_src/lib/components/Atoms/index.tsx index c053ec0655c..805ddb91797 100644 --- a/specifyweb/frontend/js_src/lib/components/Atoms/index.tsx +++ b/specifyweb/frontend/js_src/lib/components/Atoms/index.tsx @@ -94,6 +94,8 @@ export const Key = wrap( 'bg-gray-200 border-1 dark:border-none dark:bg-neutral-700 rounded-sm mx-1 p-0.5' ); +const defaultOneRem = 16; export const oneRem = Number.parseFloat( - getComputedStyle(document.documentElement).fontSize + globalThis.getComputedStyle?.(document.documentElement).fontSize ?? + defaultOneRem ); diff --git a/specifyweb/frontend/js_src/lib/components/Core/Entrypoint.tsx b/specifyweb/frontend/js_src/lib/components/Core/Entrypoint.tsx index fcf1b7fd7ca..575b5eba5e3 100644 --- a/specifyweb/frontend/js_src/lib/components/Core/Entrypoint.tsx +++ b/specifyweb/frontend/js_src/lib/components/Core/Entrypoint.tsx @@ -30,7 +30,7 @@ function entrypoint(): void { console.log(entrypointName); unlockInitialContext(entrypointName); - globalThis.window.addEventListener('load', () => { + globalThis.addEventListener?.('load', () => { const root = document.getElementById('root'); const portalRoot = document.getElementById('portal-root'); if (root === null || portalRoot === null) diff --git a/specifyweb/frontend/js_src/lib/components/Core/OnlineStatus.tsx b/specifyweb/frontend/js_src/lib/components/Core/OnlineStatus.tsx index 666fa6df1a5..274232eb9ee 100644 --- a/specifyweb/frontend/js_src/lib/components/Core/OnlineStatus.tsx +++ b/specifyweb/frontend/js_src/lib/components/Core/OnlineStatus.tsx @@ -22,12 +22,12 @@ export function OnlineStatus(): JSX.Element | null { setShowOnlineStatus(false); } - window.addEventListener('online', handleOnline); - window.addEventListener('offline', handleOffline); + globalThis.addEventListener('online', handleOnline); + globalThis.addEventListener('offline', handleOffline); return () => { - window.removeEventListener('online', handleOnline); - window.removeEventListener('offline', handleOffline); + globalThis.removeEventListener('online', handleOnline); + globalThis.removeEventListener('offline', handleOffline); }; }, []); diff --git a/specifyweb/frontend/js_src/lib/components/Molecules/Dialog.tsx b/specifyweb/frontend/js_src/lib/components/Molecules/Dialog.tsx index 724b87fe657..cf3ea52c8cb 100644 --- a/specifyweb/frontend/js_src/lib/components/Molecules/Dialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Molecules/Dialog.tsx @@ -76,12 +76,13 @@ const dialogIndexes = new Set(); const getNextIndex = (): number => dialogIndexes.size === 0 ? initialIndex : Math.max(...dialogIndexes) + 1; -const supportsBackdropBlur = globalThis.CSS.supports( - '((-webkit-backdrop-filter: none) or (backdrop-filter: none))' -); +const supportsBackdropBlur = + globalThis.CSS?.supports( + '((-webkit-backdrop-filter: none) or (backdrop-filter: none))' + ) ?? false; // Used for 'inert' attribute addition -const root = document.getElementById('root'); +const root = globalThis.document?.getElementById('root'); /** * Modal or non-modal dialog. Highly customizable. Used all over the place diff --git a/specifyweb/frontend/js_src/lib/components/Molecules/GeoLocate.tsx b/specifyweb/frontend/js_src/lib/components/Molecules/GeoLocate.tsx index f2f83dd0dd2..53040fd33d1 100644 --- a/specifyweb/frontend/js_src/lib/components/Molecules/GeoLocate.tsx +++ b/specifyweb/frontend/js_src/lib/components/Molecules/GeoLocate.tsx @@ -45,7 +45,7 @@ export function GenericGeoLocate({ handleUpdate?.({ latitude, longitude, uncertainty, polygon }); } - globalThis.window.addEventListener('message', listener); + globalThis.addEventListener('message', listener); return (): void => globalThis.removeEventListener('message', listener); }, [handleUpdate]); diff --git a/specifyweb/frontend/js_src/lib/components/Molecules/Tooltips.tsx b/specifyweb/frontend/js_src/lib/components/Molecules/Tooltips.tsx index 7a3f8173e9f..205abeca782 100644 --- a/specifyweb/frontend/js_src/lib/components/Molecules/Tooltips.tsx +++ b/specifyweb/frontend/js_src/lib/components/Molecules/Tooltips.tsx @@ -219,7 +219,7 @@ let delayFocusIn = 400; /** Delay before showing tooltip if using mouse */ let delayMouseIn = 1000; // Disable delays on touch screen devices -window?.addEventListener( +globalThis.addEventListener?.( 'touchstart', () => { delayFocusIn = 0; diff --git a/specifyweb/frontend/js_src/lib/components/WorkBench/WbView.tsx b/specifyweb/frontend/js_src/lib/components/WorkBench/WbView.tsx index 64ee45dab9b..5ea8aaaef1d 100644 --- a/specifyweb/frontend/js_src/lib/components/WorkBench/WbView.tsx +++ b/specifyweb/frontend/js_src/lib/components/WorkBench/WbView.tsx @@ -300,7 +300,7 @@ export class WbView extends Backbone.View { this.wbUtils.toggleCellTypes('invalidCells', 'remove'); this.cells.flushIndexedCellData = true; - globalThis.window.addEventListener('resize', this.handleResize); + globalThis.addEventListener('resize', this.handleResize); return this; } diff --git a/specifyweb/frontend/js_src/lib/utils/cache/index.ts b/specifyweb/frontend/js_src/lib/utils/cache/index.ts index 08ee8123751..f1a0d685c81 100644 --- a/specifyweb/frontend/js_src/lib/utils/cache/index.ts +++ b/specifyweb/frontend/js_src/lib/utils/cache/index.ts @@ -51,7 +51,7 @@ let eventListenerIsInitialized = false; /** Listen for changes to localStorage from other tabs */ function initialize(): void { - globalThis.addEventListener( + globalThis.addEventListener?.( 'storage', ({ storageArea, key: formattedKey, newValue }) => { // "key" is null only when running `localStorage.clear()`