Skip to content

refactor: Code cleanup and deduplication#20

Open
PoshanP wants to merge 1 commit into
vercel_deploymentfrom
SCRUM-10/page-level-sticky-notes-with-ai-rewrite-drop-a-not-3
Open

refactor: Code cleanup and deduplication#20
PoshanP wants to merge 1 commit into
vercel_deploymentfrom
SCRUM-10/page-level-sticky-notes-with-ai-rewrite-drop-a-not-3

Conversation

@PoshanP

@PoshanP PoshanP commented Jan 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract magic values to centralized constants (SWR intervals, panel dimensions, URL expiry)
  • Create shared ChatMessage/ChatSession types to eliminate duplicate definitions
  • Create reusable BaseModal component for collection modals, reducing boilerplate
  • Consolidate useUserId hook pattern across data fetching hooks
  • Remove unused code: cache.ts, QueryBuilder, validation helpers, context exports
  • Fix duplicate CSS rules in globals.css
  • Update RAG config to use centralized constants

Test plan

  • Verify collection modals (create, edit, add to collection) work correctly
  • Verify chat functionality with shared types
  • Verify papers page loads with updated constants
  • Run TypeScript compilation to confirm no type errors

- Extract magic values to constants (SWR intervals, panel dimensions, URL expiry)
- Create shared ChatMessage/ChatSession types in lib/types/chat.ts
- Create reusable BaseModal component for collection modals
- Consolidate useUserId hook pattern in useApi.ts
- Remove unused code: cache.ts, QueryBuilder, validation helpers, context exports
- Fix duplicate CSS rules in globals.css
- Update RAG config to use centralized constants
@vercel

vercel Bot commented Jan 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
thinkfolio Ready Ready Preview, Comment Jan 8, 2026 6:43pm

@PoshanP PoshanP left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 CRITICAL ISSUES

  1. Security: Dangerous sanitizeInput Function Still in Production Use

Location: lib/validation/index.ts:1-18, used in app/api/papers/upload/route.ts:15-17

// This is fundamentally broken security:
const sqlPatterns = /(\b(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|ALTER|CREATE)\b)/gi
let sanitized = input.replace(sqlPatterns, '')

Problems:

  • Corrupts legitimate user data: A paper titled "Natural Language Processing for SELECT Query Optimization" becomes "Natural Language Processing for Query Optimization"
  • Blacklist approach is bypassable: Unicode tricks, encoding, case variations can bypass this
  • False sense of security: SQL injection should be prevented via parameterized queries (which Supabase already does!)
  • Still actively used in the upload API for title sanitization

Recommendation: Remove this sanitization entirely. Supabase uses parameterized queries which prevent SQL injection. This code only corrupts user input.


  1. Accessibility: BaseModal Lacks Critical WCAG Requirements

Location: frontend/components/collections/BaseModal.tsx

Missing:

  • role="dialog" and aria-modal="true" attributes
  • Focus trap: Users can Tab outside the modal to elements behind the backdrop
  • Focus management: Focus doesn't move to modal on open or return on close
  • Screen reader announcements: No aria-live or focus on title for announcements

This affects all three modal components using BaseModal.


🟠 SIGNIFICANT ISSUES

  1. Type Safety Escape Hatches

Location: lib/db/index.ts:37

.insert(chunk as any) // Type safety bypassed

The batchInsert method uses as any which defeats TypeScript's purpose.


  1. Inconsistent Type Definitions
  • lib/types/chat.ts defines ChatMessage with session_id?: string (optional)
  • But in actual usage, messages always have a session_id
  • lib/types/index.ts still has Zod schemas (ChatMessageSchema) that duplicate these types
  • Creates confusion about single source of truth

  1. validateFileName Allows Non-PDF Extensions

Location: lib/validation/index.ts:34-35

const allowedExtensions = ['.pdf', '.jpg', '.jpeg', '.png', '.webp']

This is a PDF-only app per CLAUDE.md. Why allow image extensions?


🟡 CODE QUALITY CONCERNS

  1. chat-new/page.tsx is 1014 Lines

This monolithic component handles:

  • Session CRUD
  • Message CRUD
  • PDF viewing
  • Responsive layouts
  • URL parameters
  • Processing status polling
  • Summary generation
  • Resize handling
  • Keyboard navigation
  • DOM manipulation (hiding navbar via useEffect)

Should be split into multiple components/hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant