Skip to content

Commit 117bc2b

Browse files
CopilotPDowney
andauthored
fix: replace window.localStorage with globalThis.localStorage to resolve prefer-globalThis lint warnings
Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/30bea704-71fb-41ba-85b0-a3741ac7829b Co-authored-by: PDowney <[email protected]>
1 parent 1bf819d commit 117bc2b

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Changes are organized by date, with the most recent changes listed first.
88

99
### 🔧 EXTERNAL SERVICES CONTROL PANEL IMPROVEMENTS
1010

11+
- Replaced all `window.localStorage` references in `external-services.js` with `globalThis.localStorage` to satisfy the `prefer-globalThis` lint rule and improve cross-environment compatibility.
12+
1113
- Improved `handleSavePreferences` in `external-services.js` to distinguish between localStorage being unavailable/disabled versus storage being full: a separate availability pre-check now throws `'browser storage is unavailable or disabled'`, while quota-exceeded errors (`QuotaExceededError`, `NS_ERROR_DOM_QUOTA_REACHED`, error code 22/1014) now throw `'browser storage is full'`.
1214
- Added request deduplication to `fetchServiceData` via a lazily-initialised `inFlightRequests` map: concurrent calls for the same uncached service key now share a single in-flight Promise rather than queuing separate fetch operations.
1315
- Refactored `loadServicePreferences` to use flat, sequential try-catch blocks instead of nested ones, eliminating the outer catch that could mask the distinction between localStorage access failures and JSON parse failures.

config/var/www/admin/control-panel/external-services/external-services.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,15 +758,15 @@ export class ExternalServicesManager {
758758
// Save preferences to local storage (avoid tamper-prone cookie storage)
759759
const storageTestKey = '__servicePreferences_storage_test__';
760760
try {
761-
window.localStorage.setItem(storageTestKey, '1');
762-
window.localStorage.removeItem(storageTestKey);
761+
globalThis.localStorage.setItem(storageTestKey, '1');
762+
globalThis.localStorage.removeItem(storageTestKey);
763763
} catch (availabilityError) {
764764
console.error('localStorage availability check failed:', availabilityError);
765765
throw new Error('Unable to save preferences: browser storage is unavailable or disabled.');
766766
}
767767

768768
try {
769-
window.localStorage.setItem('servicePreferences', JSON.stringify(currentPreferences));
769+
globalThis.localStorage.setItem('servicePreferences', JSON.stringify(currentPreferences));
770770
} catch (storageError) {
771771
const isQuotaExceeded = storageError && (
772772
storageError.name === 'QuotaExceededError' ||
@@ -1345,7 +1345,7 @@ export class ExternalServicesManager {
13451345
// Try to load from local storage
13461346
let storedPrefs = null;
13471347
try {
1348-
storedPrefs = window.localStorage.getItem('servicePreferences');
1348+
storedPrefs = globalThis.localStorage.getItem('servicePreferences');
13491349
} catch (storageError) {
13501350
console.error('Failed to access localStorage for service preferences:', storageError);
13511351
return null;
@@ -1367,7 +1367,7 @@ export class ExternalServicesManager {
13671367
console.warn('Corrupted service preferences detected; resetting stored preferences to defaults.');
13681368
// Clear invalid entry
13691369
try {
1370-
window.localStorage.removeItem('servicePreferences');
1370+
globalThis.localStorage.removeItem('servicePreferences');
13711371
} catch (removeError) {
13721372
console.error('Failed to clear invalid stored preferences:', removeError);
13731373
}

0 commit comments

Comments
 (0)