Skip to content

Commit 081bcac

Browse files
committed
be more defensive in QPixel#preference about null values from _getPreference
1 parent 2ae9944 commit 081bcac

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

app/assets/javascripts/qpixel_api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ window.QPixel = {
217217
}
218218

219219
let prefs = await QPixel._getPreferences();
220-
let value = community ? prefs.community[name] : prefs.global[name];
220+
let value = community ? prefs?.community[name] : prefs?.global[name];
221221

222222
// Note that null is a valid value for a preference, but undefined means we haven't fetched it.
223-
if (typeof (value) !== 'undefined') {
223+
if (typeof value !== 'undefined') {
224224
return value;
225225
}
226226
// If we haven't fetched a preference, that probably means it's new - run a full re-fetch.

global.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ interface QPixel {
162162
/**
163163
* Get an object containing the current user's preferences. Loads, in order of precedence, from local variable,
164164
* {@link localStorage}, or Redis via AJAX.
165-
* @returns JSON object containing user preferences
165+
* @returns user preferences or `null` on failure
166166
*/
167-
_getPreferences?: () => Promise<UserPreferences>;
167+
_getPreferences?: () => Promise<UserPreferences | null>;
168168

169169
/**
170170
* Get the key to use for storing user preferences in localStorage, to avoid conflating users

0 commit comments

Comments
 (0)