Repository navigation
Build end-to-end dashboard inbox workflow - #7
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA comprehensive inbox workbench UI was added to the dashboard route with full client-side data flows powered by React Query. An accompanying ORPC client module was created to establish typed RPC communication with the server backend. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/routes/dashboard.tsx (1)
43-45: Let the route own metadata and the first loading boundary.This stays a bare
componentroute, so the dashboard never declares its ownhead, and initial auth/data work can only begin after mount. Even if some queries must remain client-side, this route should still ownheadand any preloading/redirect logic it can. Based on learnings,Use route loader for data loading and head for metadata.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/routes/dashboard.tsx` around lines 43 - 45, The Route currently registers only a bare component via createFileRoute('/dashboard') with component: DashboardPage, so the route doesn't own metadata or a loader/first loading boundary; change the route registration to provide a loader (e.g., dashboardLoader) for initial auth/data preloading and a head function (e.g., dashboardHead) so the route controls metadata and can perform redirects/preload before mount, and ensure the DashboardPage component is passed as the component or as children while the loader and head are on the Route definition (referencing Route, createFileRoute, DashboardPage for where to apply the changes).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/dashboard-api.ts`:
- Around line 111-116: The helpers listThreadsByInbox and listThreadMessages
currently hardcode page 1; update them to accept an optional cursor parameter
(e.g., cursor?: string) and forward it into the requestJson call so callers can
fetch subsequent pages returned in ListThreadsResult.nextCursor and
ListMessagesResult.nextCursor. Concretely, change the signatures of
listThreadsByInbox(inboxId: string, cursor?: string) and
listThreadMessages(threadId: string, cursor?: string) and build the query string
for requestJson(`/api/inboxes/${inboxId}/threads?limit=25${cursor ?
`&cursor=${encodeURIComponent(cursor)}` : ''}`) and similarly for
`/api/threads/${threadId}/messages?limit=100...`, ensuring you URL-encode the
cursor before appending.
In `@src/routes/dashboard.tsx`:
- Around line 93-132: The UI currently hides query failures by treating
query.data fallback to empty arrays; update the render logic for the inboxes,
threads, messages and message detail panels to check each query's isError
(inboxesQuery.isError, threadsQuery.isError, messagesQuery.isError,
messageDetailQuery.isError) and render an error state (message + retry control
or error details) instead of the empty-state UI when true; implement this by
branching before using the normalized data (inboxes, threads, threadMessages,
selectedMessage) so that on isError you display an error panel (and optionally a
retry trigger like refetch) and only fall back to the empty-state when there is
no error and the data is empty.
- Around line 945-949: The dashboard currently injects unsanitized HTML via
dangerouslySetInnerHTML when hasHtml is true using message.htmlBody; update this
to sanitize the inbound HTML before rendering (or render in a sandboxed iframe).
Import and use a trusted sanitizer (e.g., DOMPurify) and replace direct usage of
message.htmlBody with a sanitized variable (e.g., const sanitizedHtml =
DOMPurify.sanitize(message.htmlBody || '', {ALLOWED_TAGS: ..., ALLOWED_ATTR:
...})) then pass sanitizedHtml to dangerouslySetInnerHTML; alternatively, render
the content inside a sandboxed iframe component if isolation is preferred.
Ensure the sanitization happens in the component that renders the HTML (the code
path using hasHtml / message.htmlBody) so no raw HTML is injected into the DOM.
- Around line 134-165: The reconciliation effects are overwriting freshly
selected IDs because they run before refetch completes; introduce and use
“pending” selection markers set by your mutation success handlers (e.g.
createInboxMutation, createThreadMutation, sendMessageMutation) — e.g.
pendingInboxId, pendingThreadId, pendingMessageId — and update
selectedInboxId/selectedThreadId/selectedMessageId immediately in those
handlers; then change each effect (the ones referencing inboxes +
selectedInboxId, threads + selectedThreadId, threadMessages + selectedMessageId)
to skip resetting the selection when the current selected ID equals a pending*Id
or a pending*Id exists (i.e. only auto-select when selected... is null or not
found AND no pending*Id is present), and clear the corresponding pending*Id once
the refetch/invalidateQueries completes or when the item appears in the list.
---
Nitpick comments:
In `@src/routes/dashboard.tsx`:
- Around line 43-45: The Route currently registers only a bare component via
createFileRoute('/dashboard') with component: DashboardPage, so the route
doesn't own metadata or a loader/first loading boundary; change the route
registration to provide a loader (e.g., dashboardLoader) for initial auth/data
preloading and a head function (e.g., dashboardHead) so the route controls
metadata and can perform redirects/preload before mount, and ensure the
DashboardPage component is passed as the component or as children while the
loader and head are on the Route definition (referencing Route, createFileRoute,
DashboardPage for where to apply the changes).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 485ba990-58ed-42b1-ae8b-b9c68377dec3
📒 Files selected for processing (2)
src/lib/dashboard-api.tssrc/routes/dashboard.tsx
| export async function listThreadsByInbox(inboxId: string) { | ||
| return requestJson<ListThreadsResult>(`/api/inboxes/${inboxId}/threads?limit=25`) | ||
| } | ||
|
|
||
| export async function listThreadMessages(threadId: string) { | ||
| return requestJson<ListMessagesResult>(`/api/threads/${threadId}/messages?limit=100`) |
There was a problem hiding this comment.
Expose cursor arguments in these list helpers.
ListThreadsResult and ListMessagesResult already carry nextCursor, but these helpers hardcode the first page and give the route no way to ask for older results. Once an inbox exceeds 25 threads or a thread exceeds 100 messages, the workbench will silently truncate what users can browse.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lib/dashboard-api.ts` around lines 111 - 116, The helpers
listThreadsByInbox and listThreadMessages currently hardcode page 1; update them
to accept an optional cursor parameter (e.g., cursor?: string) and forward it
into the requestJson call so callers can fetch subsequent pages returned in
ListThreadsResult.nextCursor and ListMessagesResult.nextCursor. Concretely,
change the signatures of listThreadsByInbox(inboxId: string, cursor?: string)
and listThreadMessages(threadId: string, cursor?: string) and build the query
string for requestJson(`/api/inboxes/${inboxId}/threads?limit=25${cursor ?
`&cursor=${encodeURIComponent(cursor)}` : ''}`) and similarly for
`/api/threads/${threadId}/messages?limit=100...`, ensuring you URL-encode the
cursor before appending.
| const inboxes = inboxesQuery.data ?? [] | ||
| const selectedInbox = useMemo( | ||
| () => inboxes.find((inbox) => inbox.id === selectedInboxId) ?? null, | ||
| [inboxes, selectedInboxId], | ||
| ) | ||
|
|
||
| const threadsQuery = useQuery({ | ||
| enabled: isReady && Boolean(selectedInboxId), | ||
| queryFn: () => listThreadsByInbox(selectedInboxId!), | ||
| queryKey: [...DASHBOARD_QUERY_KEY, 'threads', selectedInboxId], | ||
| staleTime: 3_000, | ||
| }) | ||
|
|
||
| const threads = threadsQuery.data?.items ?? [] | ||
| const selectedThread = useMemo( | ||
| () => threads.find((thread) => thread.id === selectedThreadId) ?? null, | ||
| [threads, selectedThreadId], | ||
| ) | ||
|
|
||
| const messagesQuery = useQuery({ | ||
| enabled: isReady && Boolean(selectedThreadId), | ||
| queryFn: () => listThreadMessages(selectedThreadId!), | ||
| queryKey: [...DASHBOARD_QUERY_KEY, 'messages', selectedThreadId], | ||
| staleTime: 3_000, | ||
| }) | ||
|
|
||
| const threadMessages = messagesQuery.data?.items ?? [] | ||
| const selectedMessageSummary = useMemo( | ||
| () => threadMessages.find((message) => message.id === selectedMessageId) ?? null, | ||
| [threadMessages, selectedMessageId], | ||
| ) | ||
|
|
||
| const messageDetailQuery = useQuery({ | ||
| enabled: isReady && Boolean(selectedMessageId), | ||
| queryFn: () => getMessage(selectedMessageId!), | ||
| queryKey: [...DASHBOARD_QUERY_KEY, 'message', selectedMessageId], | ||
| staleTime: 3_000, | ||
| }) | ||
|
|
||
| const selectedMessage = messageDetailQuery.data ?? null |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n src/routes/dashboard.tsx | head -150Repository: KMKoushik/clankr-email
Length of output: 5207
🏁 Script executed:
cat -n src/routes/dashboard.tsx | sed -n '160,250p'Repository: KMKoushik/clankr-email
Length of output: 3549
🏁 Script executed:
cat -n src/routes/dashboard.tsx | sed -n '250,350p'Repository: KMKoushik/clankr-email
Length of output: 5876
🏁 Script executed:
cat -n src/routes/dashboard.tsx | sed -n '335,385p'Repository: KMKoushik/clankr-email
Length of output: 2750
🏁 Script executed:
cat -n src/routes/dashboard.tsx | sed -n '500,570p'Repository: KMKoushik/clankr-email
Length of output: 3812
🏁 Script executed:
cat -n src/routes/dashboard.tsx | sed -n '655,730p'Repository: KMKoushik/clankr-email
Length of output: 4691
Add error state rendering to query panels.
These four query handlers normalize failed requests to empty data without checking isError, so network failures silently display empty state messages ("No inboxes yet", "No threads yet", etc.) instead of error feedback. Users cannot distinguish between truly empty results and actual failures.
Add error branches for inboxesQuery.isError, threadsQuery.isError, messagesQuery.isError, and messageDetailQuery.isError at lines 335, 504, 659, and 714 respectively.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/routes/dashboard.tsx` around lines 93 - 132, The UI currently hides query
failures by treating query.data fallback to empty arrays; update the render
logic for the inboxes, threads, messages and message detail panels to check each
query's isError (inboxesQuery.isError, threadsQuery.isError,
messagesQuery.isError, messageDetailQuery.isError) and render an error state
(message + retry control or error details) instead of the empty-state UI when
true; implement this by branching before using the normalized data (inboxes,
threads, threadMessages, selectedMessage) so that on isError you display an
error panel (and optionally a retry trigger like refetch) and only fall back to
the empty-state when there is no error and the data is empty.
| useEffect(() => { | ||
| if (inboxes.length === 0) { | ||
| setSelectedInboxId(null) | ||
| return | ||
| } | ||
|
|
||
| if (!selectedInboxId || !inboxes.some((inbox) => inbox.id === selectedInboxId)) { | ||
| setSelectedInboxId(inboxes[0]!.id) | ||
| } | ||
| }, [inboxes, selectedInboxId]) | ||
|
|
||
| useEffect(() => { | ||
| if (threads.length === 0) { | ||
| setSelectedThreadId(null) | ||
| return | ||
| } | ||
|
|
||
| if (!selectedThreadId || !threads.some((thread) => thread.id === selectedThreadId)) { | ||
| setSelectedThreadId(threads[0]!.id) | ||
| } | ||
| }, [selectedThreadId, threads]) | ||
|
|
||
| useEffect(() => { | ||
| if (threadMessages.length === 0) { | ||
| setSelectedMessageId(null) | ||
| return | ||
| } | ||
|
|
||
| if (!selectedMessageId || !threadMessages.some((message) => message.id === selectedMessageId)) { | ||
| setSelectedMessageId(threadMessages.at(-1)?.id ?? null) | ||
| } | ||
| }, [selectedMessageId, threadMessages]) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the file and understand its structure
wc -l src/routes/dashboard.tsxRepository: KMKoushik/clankr-email
Length of output: 95
🏁 Script executed:
# Read the specific lines mentioned in the review (134-165 and 173-230)
sed -n '130,240p' src/routes/dashboard.tsx | cat -nRepository: KMKoushik/clankr-email
Length of output: 4264
🏁 Script executed:
# Search for the mutation definitions mentioned
rg -n "createInboxMutation|sendMessageMutation" src/routes/dashboard.tsx -A 5Repository: KMKoushik/clankr-email
Length of output: 2102
🏁 Script executed:
# Look for cache invalidation logic
rg -n "invalidateQueries|refetch" src/routes/dashboard.tsx -B 2 -A 2Repository: KMKoushik/clankr-email
Length of output: 1052
🏁 Script executed:
# Search for queryClient initialization/configuration
rg -n "new QueryClient|createQueryClient|queryClient.*=" src/routes/dashboard.tsx -B 3 -A 5Repository: KMKoushik/clankr-email
Length of output: 482
🏁 Script executed:
# Check for any refetch synchronization patterns or options
rg -n "refetchType|await.*refetch|queryClient\." src/routes/dashboard.tsx | head -30Repository: KMKoushik/clankr-email
Length of output: 293
🏁 Script executed:
# Look for the query definitions and how inboxes/threads/messages are queried
rg -n "useQuery.*inboxes|useQuery.*threads|useQuery.*messages" src/ -A 8Repository: KMKoushik/clankr-email
Length of output: 48
🏁 Script executed:
# Check if invalidateQueries has any specific options being passed
rg -n "invalidateQueries" src/routes/dashboard.tsx -B 2 -A 3Repository: KMKoushik/clankr-email
Length of output: 890
🏁 Script executed:
# Let's get the exact line numbers for the full context of mutations and effects
sed -n '130,235p' src/routes/dashboard.tsx | head -110 | cat -nRepository: KMKoushik/clankr-email
Length of output: 3926
🏁 Script executed:
# Check TanStack Query version to understand invalidateQueries behavior
cat package.json | grep -A 2 -B 2 "@tanstack/react-query"Repository: KMKoushik/clankr-email
Length of output: 327
🏁 Script executed:
# Look for any awaited refetch patterns or synchronization mechanisms
rg -n "refetch()" src/routes/dashboard.tsx -B 2 -A 2Repository: KMKoushik/clankr-email
Length of output: 259
🏁 Script executed:
# Let's understand what happens after invalidateQueries by checking query setup
# First, find where inboxesQuery is defined
rg -n "inboxesQuery|const.*inboxes.*useQuery" src/routes/dashboard.tsx -B 2 -A 8Repository: KMKoushik/clankr-email
Length of output: 1142
🏁 Script executed:
# Check the actual query key structure and any refetch settings
rg -n "DASHBOARD_QUERY_KEY\|queryKey:" src/routes/dashboard.tsx | head -20Repository: KMKoushik/clankr-email
Length of output: 48
🏁 Script executed:
# Let's verify the exact line numbers for the "Also applies to: 173-230" section
sed -n '173,230p' src/routes/dashboard.tsx | cat -nRepository: KMKoushik/clankr-email
Length of output: 2401
🏁 Script executed:
# Check if there are any utility functions or patterns for handling optimistic updates
rg -n "optimistic|onMutate|setQueryData" src/routes/dashboard.tsx -B 2 -A 3Repository: KMKoushik/clankr-email
Length of output: 48
🏁 Script executed:
# Let's verify the full query definitions including threadsQuery and messagesQuery
sed -n '86,125p' src/routes/dashboard.tsx | cat -nRepository: KMKoushik/clankr-email
Length of output: 1638
🏁 Script executed:
# Check what happens during the actual data refetch - search for any success handlers on queries
rg -n "threadsQuery|messagesQuery" src/routes/dashboard.tsx | head -15Repository: KMKoushik/clankr-email
Length of output: 730
Fix reconciliation effects to avoid overwriting freshly selected IDs.
After mutations (createInboxMutation, sendMessageMutation) set a new inbox/thread/message ID, the reconciliation effects immediately overwrite it because the new item isn't in the cache yet. The effects run with stale lists before invalidateQueries() completes the refetch, causing the selected ID to fail validation and reset to inboxes[0], threads[0], or the last cached message. Newly created or sent items do not stay selected.
Affected code
useEffect(() => {
if (inboxes.length === 0) {
setSelectedInboxId(null)
return
}
if (!selectedInboxId || !inboxes.some((inbox) => inbox.id === selectedInboxId)) {
setSelectedInboxId(inboxes[0]!.id)
}
}, [inboxes, selectedInboxId])
useEffect(() => {
if (threads.length === 0) {
setSelectedThreadId(null)
return
}
if (!selectedThreadId || !threads.some((thread) => thread.id === selectedThreadId)) {
setSelectedThreadId(threads[0]!.id)
}
}, [selectedThreadId, threads])
useEffect(() => {
if (threadMessages.length === 0) {
setSelectedMessageId(null)
return
}
if (!selectedMessageId || !threadMessages.some((message) => message.id === selectedMessageId)) {
setSelectedMessageId(threadMessages.at(-1)?.id ?? null)
}
}, [selectedMessageId, threadMessages])
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/routes/dashboard.tsx` around lines 134 - 165, The reconciliation effects
are overwriting freshly selected IDs because they run before refetch completes;
introduce and use “pending” selection markers set by your mutation success
handlers (e.g. createInboxMutation, createThreadMutation, sendMessageMutation) —
e.g. pendingInboxId, pendingThreadId, pendingMessageId — and update
selectedInboxId/selectedThreadId/selectedMessageId immediately in those
handlers; then change each effect (the ones referencing inboxes +
selectedInboxId, threads + selectedThreadId, threadMessages + selectedMessageId)
to skip resetting the selection when the current selected ID equals a pending*Id
or a pending*Id exists (i.e. only auto-select when selected... is null or not
found AND no pending*Id is present), and clear the corresponding pending*Id once
the refetch/invalidateQueries completes or when the item appears in the list.
| {hasHtml ? ( | ||
| <div | ||
| className="prose prose-neutral dark:prose-invert max-w-none break-words prose-pre:overflow-x-auto" | ||
| dangerouslySetInnerHTML={{ __html: message.htmlBody ?? '' }} | ||
| /> |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
wc -l src/routes/dashboard.tsxRepository: KMKoushik/clankr-email
Length of output: 95
🏁 Script executed:
# Read around the flagged lines to understand context
sed -n '900,1000p' src/routes/dashboard.tsxRepository: KMKoushik/clankr-email
Length of output: 4693
🏁 Script executed:
# Search for where message comes from and any sanitization imports
rg -i "sanitize|purify|htmlBody" src/routes/dashboard.tsx -B 5 -A 5Repository: KMKoushik/clankr-email
Length of output: 878
🏁 Script executed:
# Check what dependencies are available for HTML sanitization
cat package.json | grep -i "dompurify\|sanitize"Repository: KMKoushik/clankr-email
Length of output: 48
🏁 Script executed:
# Find MessageDetail type definition
rg "type MessageDetail|interface MessageDetail" src/ -A 20Repository: KMKoushik/clankr-email
Length of output: 1984
🏁 Script executed:
# Look for the route loader and how message data is fetched
sed -n '1,100p' src/routes/dashboard.tsxRepository: KMKoushik/clankr-email
Length of output: 2660
🏁 Script executed:
# Check if there are any API utilities that might sanitize HTML
rg -i "sanitize|htmlbody" src/ --type ts --type tsxRepository: KMKoushik/clankr-email
Length of output: 93
🏁 Script executed:
# Look at the dashboard-api to see where htmlBody comes from
cat src/lib/dashboard-api.tsRepository: KMKoushik/clankr-email
Length of output: 4416
🏁 Script executed:
# Search for getMessage function to see how the API response is processed
rg "function getMessage|const getMessage" src/Repository: KMKoushik/clankr-email
Length of output: 313
🏁 Script executed:
# Look at the backend read.ts file
cat src/lib/email/read.tsRepository: KMKoushik/clankr-email
Length of output: 11489
🏁 Script executed:
# Search for the API route handler
rg "/api/messages" src/ -A 5Repository: KMKoushik/clankr-email
Length of output: 1973
🏁 Script executed:
# Look for server-side code
find src -name "*.server.ts" -o -name "*.api.ts" | head -20Repository: KMKoushik/clankr-email
Length of output: 48
🏁 Script executed:
# Search for email parsing and htmlBody population
rg "htmlBody|parseEmail|extractBody" src/ --type ts -B 3 -A 3Repository: KMKoushik/clankr-email
Length of output: 16793
🏁 Script executed:
# Look for mail provider integration or MIME parsing
rg "mime|mail|email.*parse|parseMessage" src/ -i --type ts | head -30Repository: KMKoushik/clankr-email
Length of output: 2162
🏁 Script executed:
# Verify where parsedEmail comes from - look for email parsing library
rg "parsedEmail|parse.*email" src/lib/email/inbound.ts -B 5 -A 5Repository: KMKoushik/clankr-email
Length of output: 2840
Sanitize inbound HTML before rendering it.
Email HTML from arbitrary senders is parsed by PostalMime and stored directly without sanitization. When rendered via dangerouslySetInnerHTML in the dashboard, this creates an authenticated XSS surface where a malicious email sender can execute JavaScript in the context of the dashboard application. Sanitize the HTML (e.g., with DOMPurify) before storing or rendering it, or isolate it in a sandboxed iframe.
🧰 Tools
🪛 ast-grep (0.41.0)
[warning] 947-947: Usage of dangerouslySetInnerHTML detected. This bypasses React's built-in XSS protection. Always sanitize HTML content using libraries like DOMPurify before injecting it into the DOM to prevent XSS attacks.
Context: dangerouslySetInnerHTML
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml
- https://cwe.mitre.org/data/definitions/79.html
(react-unsafe-html-injection)
🪛 Biome (2.4.4)
[error] 948-948: Avoid passing content using the dangerouslySetInnerHTML prop.
(lint/security/noDangerouslySetInnerHtml)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/routes/dashboard.tsx` around lines 945 - 949, The dashboard currently
injects unsanitized HTML via dangerouslySetInnerHTML when hasHtml is true using
message.htmlBody; update this to sanitize the inbound HTML before rendering (or
render in a sandboxed iframe). Import and use a trusted sanitizer (e.g.,
DOMPurify) and replace direct usage of message.htmlBody with a sanitized
variable (e.g., const sanitizedHtml = DOMPurify.sanitize(message.htmlBody || '',
{ALLOWED_TAGS: ..., ALLOWED_ATTR: ...})) then pass sanitizedHtml to
dangerouslySetInnerHTML; alternatively, render the content inside a sandboxed
iframe component if isolation is preferred. Ensure the sanitization happens in
the component that renders the HTML (the code path using hasHtml /
message.htmlBody) so no raw HTML is injected into the DOM.
Summary
Validation
Summary by CodeRabbit
New Features