DEV: Gracefully handle missing localstorage in dev-tools initializer (#30643)

I'm not sure if this is a real-world consideration... but our `test/smoke-test.mjs` script runs chrome with `--disable-local-storage`, so it needs to work.
This commit is contained in:
David Taylor 2025-01-08 16:11:17 +00:00 committed by GitHub
parent 498481e5be
commit 2ff511a4e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,7 +4,7 @@ import { isDevelopment } from "discourse-common/config/environment";
const KEY = "discourse__dev_tools";
function parseStoredValue() {
const val = window.localStorage.getItem(KEY);
const val = window.localStorage?.getItem(KEY);
if (val === "true") {
return true;
} else if (val === "false") {
@ -26,9 +26,9 @@ export default {
function storeValue(value) {
if (value === defaultEnabled) {
window.localStorage.removeItem(KEY);
window.localStorage?.removeItem(KEY);
} else {
window.localStorage.setItem(KEY, value);
window.localStorage?.setItem(KEY, value);
}
}