From f7003c391dc957f9be2f1839af49dff3f51f1d9b Mon Sep 17 00:00:00 2001 From: Albert Date: Sun, 9 Nov 2025 18:28:23 +0000 Subject: [PATCH] fix: Resolve TypeScript error with atp_cid used before assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added rootPost variable to store first post's URI and CID - Fixed thread reply references to use rootPost instead of atp_cid before it's assigned - Resolves production build TypeScript error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/api/nodes/route.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/api/nodes/route.ts b/app/api/nodes/route.ts index a499ad6..4efeed2 100644 --- a/app/api/nodes/route.ts +++ b/app/api/nodes/route.ts @@ -133,6 +133,7 @@ export async function POST(request: NextRequest) { // Create the thread posts let previousPost: { uri: string; cid: string } | null = null; + let rootPost: { uri: string; cid: string } | null = null; const threadUris: string[] = []; for (let i = 0; i < chunks.length; i++) { @@ -169,12 +170,10 @@ export async function POST(request: NextRequest) { tags: ['ponderants-node'], }; - // If not first post, add reply reference - if (previousPost && threadUris.length > 0) { - // Get the first post (root) CID from the stored thread data - const rootCid = atp_cid; // First post's CID + // If not first post, add reply reference to create a thread + if (previousPost && rootPost) { postRecord.reply = { - root: { uri: threadUris[0], cid: rootCid }, + root: { uri: rootPost.uri, cid: rootPost.cid }, parent: { uri: previousPost.uri, cid: previousPost.cid }, }; } @@ -189,8 +188,9 @@ export async function POST(request: NextRequest) { threadUris.push(response.data.uri); previousPost = { uri: response.data.uri, cid: response.data.cid }; - // Store the first post's URI as the main atp_uri + // Store the first post's URI and CID as both the root and the main atp_uri if (isFirstPost) { + rootPost = { uri: response.data.uri, cid: response.data.cid }; atp_uri = response.data.uri; atp_cid = response.data.cid; }