audio streaming app plyr.fm
38
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: ambient body-null error + scope localStorage by DID (#1133)

Remove early document.body.classList access from <head> inline script
(body doesn't exist yet). Scope ambient_enabled/ambient_location
localStorage keys by user DID so ambient state is per-account.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

authored by

nate nowack
Claude Opus 4.6
and committed by
GitHub
5ee3f243 28ddc6db

+15 -12
+14 -7
frontend/src/lib/ambient.svelte.ts
··· 199 199 private lastFetchTime = 0; 200 200 private readonly STALE_MS = 30 * 60 * 1000; // 30 minutes 201 201 private baseValues: Map<string, string> = new Map(); 202 + private did: string | null = null; 203 + 204 + private key(name: string): string { 205 + return this.did ? `${name}:${this.did}` : name; 206 + } 202 207 203 208 get gradient(): string | null { 204 209 if (!this.weather) return null; ··· 214 219 return `${temp}° · ${condition} · ${time}`; 215 220 } 216 221 217 - initialize(): void { 222 + initialize(did?: string): void { 218 223 if (!browser) return; 219 224 220 - const stored = localStorage.getItem('ambient_enabled'); 225 + this.did = did ?? null; 226 + 227 + const stored = localStorage.getItem(this.key('ambient_enabled')); 221 228 if (stored !== '1') return; 222 229 223 - const locStr = localStorage.getItem('ambient_location'); 230 + const locStr = localStorage.getItem(this.key('ambient_location')); 224 231 if (!locStr) return; 225 232 226 233 try { ··· 243 250 try { 244 251 const coords = await this.requestLocation(); 245 252 this.location = coords; 246 - localStorage.setItem('ambient_location', JSON.stringify(coords)); 247 - localStorage.setItem('ambient_enabled', '1'); 253 + localStorage.setItem(this.key('ambient_location'), JSON.stringify(coords)); 254 + localStorage.setItem(this.key('ambient_enabled'), '1'); 248 255 this.enabled = true; 249 256 await this.fetchWeather(); 250 257 this.startRefreshCycle(); ··· 253 260 ? 'location access denied — ambient mode needs your location to read the sky' 254 261 : 'could not determine location'; 255 262 this.enabled = false; 256 - localStorage.removeItem('ambient_enabled'); 263 + localStorage.removeItem(this.key('ambient_enabled')); 257 264 } finally { 258 265 this.loading = false; 259 266 } ··· 265 272 this.enabled = false; 266 273 this.weather = null; 267 274 this.error = null; 268 - localStorage.setItem('ambient_enabled', '0'); 275 + localStorage.setItem(this.key('ambient_enabled'), '0'); 269 276 270 277 if (this.fetchIntervalId !== null) { 271 278 window.clearInterval(this.fetchIntervalId);
+1 -5
frontend/src/routes/+layout.svelte
··· 66 66 // if authenticated, fetch preferences and reconnect to active jam or personal queue 67 67 if (auth.isAuthenticated) { 68 68 await preferences.initialize(); 69 - ambient.initialize(); 69 + ambient.initialize(auth.user?.did); 70 70 71 71 // check for active jam first — if rejoining, jam owns the queue state 72 72 let joinedJam = false; ··· 434 434 } 435 435 root.classList.add('theme-' + effectiveTheme); 436 436 437 - // ambient: add class early so ::after is visible when gradient loads 438 - if (localStorage.getItem('ambient_enabled') === '1') { 439 - document.body.classList.add('ambient-active'); 440 - } 441 437 })(); 442 438 } 443 439 </script>