fix: use data prop instead of parent() for sensitive images SSR (#481)

* fix: use data prop instead of parent() for sensitive images SSR

The +layout.ts file was incorrectly using parent() to access data from
+layout.server.ts. In SvelteKit, data from a server load function in the
same route comes via the data parameter, not parent(). parent() is only
for accessing data from parent routes.

This fixes SSR meta tag generation for sensitive images.

* fix: handle nullable data parameter in layout load function

TypeScript was complaining that data could be null. Use optional
chaining and extract sensitiveImages to a variable to avoid repetition.

authored by zzstoatzz.io and committed by GitHub 27f05692 46013bd8

Changed files
+14 -15
frontend
src
routes
+14 -15
frontend/src/routes/+layout.ts
··· 23 23 show_sensitive_artwork: false 24 24 }; 25 25 26 - export async function load({ fetch, parent }: LoadEvent): Promise<LayoutData> { 27 - // get server-loaded data (sensitiveImages) 28 - const parentData = await parent(); 26 + export async function load({ fetch, data }: LoadEvent): Promise<LayoutData> { 27 + const sensitiveImages = data?.sensitiveImages ?? { image_ids: [], urls: [] }; 29 28 30 29 if (!browser) { 31 30 return { 32 31 user: null, 33 32 isAuthenticated: false, 34 33 preferences: null, 35 - sensitiveImages: parentData.sensitiveImages ?? { image_ids: [], urls: [] } 34 + sensitiveImages 36 35 }; 37 36 } 38 37 ··· 51 50 credentials: 'include' 52 51 }); 53 52 if (prefsResponse.ok) { 54 - const data = await prefsResponse.json(); 53 + const prefsData = await prefsResponse.json(); 55 54 preferences = { 56 - accent_color: data.accent_color ?? null, 57 - auto_advance: data.auto_advance ?? true, 58 - allow_comments: data.allow_comments ?? true, 59 - hidden_tags: data.hidden_tags ?? ['ai'], 60 - theme: data.theme ?? 'dark', 61 - enable_teal_scrobbling: data.enable_teal_scrobbling ?? false, 62 - teal_needs_reauth: data.teal_needs_reauth ?? false, 63 - show_sensitive_artwork: data.show_sensitive_artwork ?? false 55 + accent_color: prefsData.accent_color ?? null, 56 + auto_advance: prefsData.auto_advance ?? true, 57 + allow_comments: prefsData.allow_comments ?? true, 58 + hidden_tags: prefsData.hidden_tags ?? ['ai'], 59 + theme: prefsData.theme ?? 'dark', 60 + enable_teal_scrobbling: prefsData.enable_teal_scrobbling ?? false, 61 + teal_needs_reauth: prefsData.teal_needs_reauth ?? false, 62 + show_sensitive_artwork: prefsData.show_sensitive_artwork ?? false 64 63 }; 65 64 } 66 65 } catch (e) { ··· 71 70 user, 72 71 isAuthenticated: true, 73 72 preferences, 74 - sensitiveImages: parentData.sensitiveImages ?? { image_ids: [], urls: [] } 73 + sensitiveImages 75 74 }; 76 75 } 77 76 } catch (e) { ··· 82 81 user: null, 83 82 isAuthenticated: false, 84 83 preferences: null, 85 - sensitiveImages: parentData.sensitiveImages ?? { image_ids: [], urls: [] } 84 + sensitiveImages 86 85 }; 87 86 }