Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions web-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ const DARK_MEDIA = matchMedia("(prefers-color-scheme: dark)")
* listener is otherwise never heard, and the next one is a day away.
*/
function useTheme() {
const [saved, setSaved] = useState(() => localStorage.getItem("theme"))
// Storage can be switched off for the site, and then even reading it throws.
const [saved, setSaved] = useState(() => {
try {
return localStorage.getItem("theme")
} catch {
return null
}
})
const system = useSyncExternalStore(
(notify) => {
DARK_MEDIA.addEventListener("change", notify)
Expand Down Expand Up @@ -80,7 +87,11 @@ function useTheme() {
dark,
() => {
const next = dark ? "light" : "dark"
localStorage.setItem("theme", next)
try {
localStorage.setItem("theme", next)
} catch {
// The choice then lasts until the page is closed.
}
setSaved(next)
},
] as const
Expand Down
14 changes: 11 additions & 3 deletions web-admin/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,19 @@ export function useNodes() {
}, 10_000)
}
watch()
// Only a frame that parses re-arms the watchdog, so a stream whose frames
// cannot be read counts as silent and is replaced.
opened.onmessage = (event) => {
let nodes, admin
try {
;({ nodes, admin } = JSON.parse(event.data))
} catch (e) {
console.warn("live frame dropped:", e)
return
}
watch()
const frame = JSON.parse(event.data)
setNodes(frame.nodes)
setAdmin(frame.admin)
setNodes(nodes)
setAdmin(admin)
setError(null)
// The stream has returned; the poll was only covering for it.
if (poll) {
Expand Down
Loading