From f2429eb9ecb0c5673db80dd573d0f4eaad84be1c Mon Sep 17 00:00:00 2001 From: larsi Date: Sat, 14 Nov 2026 01:38:20 +0100 Subject: [PATCH] fix: post pages 500 under SSR with PUBLIC_INTERNAL_INSTANCE On the server profile.current.instance is the internal API address, so the post loader saw an instance mismatch and called goto(), which throws on the server. Compare against the public instance and only redirect in the browser. /post/ now redirects to the public instance instead of the internal one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011c5BZVwWdVLrdQi9htmuth --- src/routes/post/[instance]/+page.ts | 5 ++++- src/routes/post/[instance]/[id=integer]/+page.ts | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/routes/post/[instance]/+page.ts b/src/routes/post/[instance]/+page.ts index f66640da..7a06cfe2 100644 --- a/src/routes/post/[instance]/+page.ts +++ b/src/routes/post/[instance]/+page.ts @@ -1,4 +1,5 @@ import { resolve } from '$app/paths' +import { env } from '$env/dynamic/public' import { profile } from '$lib/app/auth' import { error, redirect } from '@sveltejs/kit' @@ -7,7 +8,9 @@ export function load({ params }) { redirect( 302, resolve(`/post/[instance]/[id=integer]`, { - instance: encodeURIComponent(profile.current.instance.toLowerCase()), + instance: encodeURIComponent( + (env.PUBLIC_INSTANCE_URL || profile.current.instance).toLowerCase(), + ), id: params.instance, }), ) diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index e688a541..b7158177 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -1,4 +1,6 @@ +import { browser } from '$app/environment' import { goto } from '$app/navigation' +import { env } from '$env/dynamic/public' import { resolve } from '$app/paths' import { client } from '$lib/api/client.svelte' import { PiefedClient } from '$lib/api/piefed/adapter.js' @@ -51,7 +53,11 @@ async function findInFeed(id: '/' | '/c/[name]' | '/f/[id]', postId: string) { } export async function load({ params, url, route }) { - if (profile.current.instance != params.instance) { + // On the server profile.current.instance is the internal API address (PUBLIC_INTERNAL_INSTANCE), + // and goto() cannot run there; compare against the public instance and only redirect in the + // browser. + const here = env.PUBLIC_INSTANCE_URL?.toLowerCase() || profile.current.instance + if (browser && here != params.instance && profile.current.instance != params.instance) { goto(resolve('/post/[instance]/[id=integer]/confirm', params), { replaceState: true, })