From 291dcebcb8d5e3f1d9ba034b016fa0b42d018760 Mon Sep 17 00:00:00 2001 From: Lasse Server Date: Thu, 6 Aug 2026 11:51:07 +0200 Subject: [PATCH] Replace hardcoded slice(6) with slice("speeches/".length) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The magic number 6 is the length of the literal "speeches/" prefix these four call sites strip off an ArangoDB-style id — spelling it out makes that relationship explicit and survives a future rename of the prefix without a silent off-by-N bug. Also swap response.statusText for response.status in fetchTalk's error message: statusText is frequently empty (HTTP/2 drops the reason phrase), so the numeric code is the more reliable thing to show. This mirrors a fix already made directly on rixdagen-prod's production branch (commit 9a87111) that hadn't been brought upstream yet. --- frontend/src/api.ts | 2 +- frontend/src/components/ResultsTable.tsx | 2 +- frontend/src/components/TalkView.tsx | 2 +- frontend/src/context/TalkDrawerContext.tsx | 2 +- frontend/src/utils/markdown.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index ae2b1c7..d44e865 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -162,7 +162,7 @@ export async function fetchTalk(id: string): Promise { headers: getSessionHeaders(), }); if (!response.ok) { - throw new Error(`Failed to fetch talk: ${response.statusText}`); + throw new Error(`Failed to fetch talk: ${response.status}`); } return response.json(); } diff --git a/frontend/src/components/ResultsTable.tsx b/frontend/src/components/ResultsTable.tsx index ab4b79f..c589bf8 100644 --- a/frontend/src/components/ResultsTable.tsx +++ b/frontend/src/components/ResultsTable.tsx @@ -74,7 +74,7 @@ export function ResultsTable({ results, exportResults, onLoadMore, nextBatchSize {results.map((hit) => { // Always use _id, and strip "speeches/" prefix for routing - const talkKey = hit._id?.startsWith("speeches/") ? hit._id.slice(6) : hit._id; + const talkKey = hit._id?.startsWith("speeches/") ? hit._id.slice("speeches/".length) : hit._id; if (!talkKey) { console.warn("Result hit missing _id:", hit); } diff --git a/frontend/src/components/TalkView.tsx b/frontend/src/components/TalkView.tsx index 68e3710..2cd0641 100644 --- a/frontend/src/components/TalkView.tsx +++ b/frontend/src/components/TalkView.tsx @@ -77,7 +77,7 @@ export function TalkView() { const idString = typeof rawId === 'object' && rawId !== null && '_id' in rawId ? (rawId as any)._id : String(rawId); - const result = idString.startsWith("speeches/") ? idString.slice(6) : idString; + const result = idString.startsWith("speeches/") ? idString.slice("speeches/".length) : idString; return result; }; const previousId = normalizeTalkId(previousTalk); diff --git a/frontend/src/context/TalkDrawerContext.tsx b/frontend/src/context/TalkDrawerContext.tsx index 428ec20..c2af952 100644 --- a/frontend/src/context/TalkDrawerContext.tsx +++ b/frontend/src/context/TalkDrawerContext.tsx @@ -10,7 +10,7 @@ const TalkDrawerContext = createContext(null); /** Strips the ArangoDB "speeches/" collection prefix so callers can pass either form. */ export function normalizeTalkId(rawId: string): string { - return rawId.startsWith("speeches/") ? rawId.slice(6) : rawId; + return rawId.startsWith("speeches/") ? rawId.slice("speeches/".length) : rawId; } export function TalkDrawerProvider({ children }: { children: ReactNode }) { diff --git a/frontend/src/utils/markdown.ts b/frontend/src/utils/markdown.ts index 2286c3c..01c1209 100644 --- a/frontend/src/utils/markdown.ts +++ b/frontend/src/utils/markdown.ts @@ -28,7 +28,7 @@ export const convertMarkdownToHtml = (markdown: string, sources?: ChatSource[]): if (raw.startsWith("documents/")) { talkPathByIndex.set(i + 1, `/motion/${raw.slice("documents/".length)}`); } else { - const key = raw.startsWith("speeches/") ? raw.slice(6) : raw; + const key = raw.startsWith("speeches/") ? raw.slice("speeches/".length) : raw; if (key) talkPathByIndex.set(i + 1, `/talk/${key}`); } });