Skip to content

Commit 2e35744

Browse files
authored
fix(chat): fail-safe to noindex if the deployment lookup errors (#5396)
generateMetadata queried the DB with no error handling, unlike the identical query in api/chat/[identifier]/route.ts (which already wraps it in try/catch). There's no error.tsx under app/(interfaces)/chat/ — metadata resolution errors aren't caught by route-segment error boundaries at all, only the root global-error.tsx — so a DB hiccup during this lookup would take the whole page down to a generic error page instead of just failing to determine indexability. Catches the error, logs it, and defaults to noindex: if we can't confirm the deployment is safely public, that's the correct SEO default anyway, not a reason to crash the request. Flagged by Cursor Bugbot on #5388 (already merged); this ships the fix as a standalone follow-up since the underlying code is already live.
1 parent ca2a52c commit 2e35744

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

  • apps/sim/app/(interfaces)/chat/[identifier]

apps/sim/app/(interfaces)/chat/[identifier]/page.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
import { db } from '@sim/db'
22
import { chat } from '@sim/db/schema'
3+
import { createLogger } from '@sim/logger'
4+
import { getErrorMessage } from '@sim/utils/errors'
35
import { and, eq, isNull } from 'drizzle-orm'
46
import type { Metadata } from 'next'
57
import ChatClient from '@/app/(interfaces)/chat/[identifier]/chat'
68
import { OfficeEmbedInit } from '@/app/(interfaces)/chat/[identifier]/office-embed-init'
79

10+
const logger = createLogger('ChatMetadata')
11+
812
/**
913
* Only fully public, active deployments are indexable. Auth-gated (password,
1014
* email, SSO) and inactive/nonexistent chats are noindexed at the page level
1115
* so Google never indexes an auth wall — narrower than blocking `/chat/`
1216
* entirely in robots.ts, which would also hide genuinely public deployments.
17+
*
18+
* Errors from the lookup fail toward noindex rather than throwing: unlike
19+
* the identical query in app/api/chat/[identifier]/route.ts (which must
20+
* surface failures to the caller), a metadata resolution error has no
21+
* error.tsx boundary in this route to catch it — throwing here would take
22+
* the whole page down instead of just skipping indexability, and "can't
23+
* confirm this is safe to index" should default to not indexing it anyway.
1324
*/
1425
export async function generateMetadata({
1526
params,
@@ -18,13 +29,21 @@ export async function generateMetadata({
1829
}): Promise<Metadata> {
1930
const { identifier } = await params
2031

21-
const [deployment] = await db
22-
.select({ authType: chat.authType, isActive: chat.isActive })
23-
.from(chat)
24-
.where(and(eq(chat.identifier, identifier), isNull(chat.archivedAt)))
25-
.limit(1)
32+
let isIndexable = false
33+
try {
34+
const [deployment] = await db
35+
.select({ authType: chat.authType, isActive: chat.isActive })
36+
.from(chat)
37+
.where(and(eq(chat.identifier, identifier), isNull(chat.archivedAt)))
38+
.limit(1)
2639

27-
const isIndexable = Boolean(deployment?.isActive && deployment.authType === 'public')
40+
isIndexable = Boolean(deployment?.isActive && deployment.authType === 'public')
41+
} catch (error) {
42+
logger.error('Failed to resolve chat deployment for metadata', {
43+
identifier,
44+
error: getErrorMessage(error),
45+
})
46+
}
2847

2948
return {
3049
title: 'Chat',

0 commit comments

Comments
 (0)