Documentation

Settings

Troubleshooting Guide

This document outlines common issues you might encounter and their solutions.

Content Security Policy (CSP)

Resource Loading Errors

If you encounter this error:

Refused to load the image 'https://example.com/thing.png' because it violates the following Content Security Policy directive: "img-src 'self'".

This indicates a CSP restriction. To resolve:

  1. Update CSP Configuration:
// server/index.ts
{
  contentSecurityPolicy: {
    directives: {
      'connect-src': [
        MODE === 'development' ? 'ws:' : null,
        process.env.SENTRY_DSN ? '*.sentry.io' : null,
        "'self'",
      ].filter(Boolean),
      'font-src': ["'self'"],
      'frame-src': ["'self'"],
      'img-src': ["'self'", 'data:', 'https://*.example.com']
    }
  }
}

Best Practices

  • Start with restrictive policies
  • Add sources as needed
  • Document policy changes
  • Monitor violations

SVG Icon System

Missing Icons Error

If you see:

X [ERROR] Could not resolve "#app/components/ui/icon.tsx"

Solution:

npm run build:icons

Icon Management

// Correct icon import
import { Icon } from '#app/components/ui/icon'

// Usage
<Icon name="user" size={24} />

React Hydration

Hydration Mismatch

When encountering:

Warning: Hydration failed because the initial UI does not match server-rendered HTML.

Common causes and solutions:

  1. Dynamic Content:
// Problematic
function Component() {
  return <div>{new Date().toLocaleString()}</div>
}

// Fixed
function Component() {
const [date, setDate] = useState(() =>
new Date().toLocaleString()
)
return <div>{date}</div>
}

  1. Browser Extensions:
  • Extensions modifying <head>
  • Content injection
  • DOM modifications
  • Style overrides
  1. Nonce Handling:
// Secure nonce implementation
function getNonce(request: Request) {
  const nonce = createNonce()
  return {
    nonce,
    header: `nonce-${nonce}`
  }
}

Database Issues

Connection Errors

  1. Check Connection String:
// Verify DATABASE_URL format
postgresql://user:password@localhost:5432/dbname
  1. Migration Issues:
# Reset database
npm run db:reset
,[object Object],

npm run db:migrate

Performance Issues

Slow Page Loads

  1. Check Server Timing:
import { time } from '#app/utils/timing.server'

const result = await time(
() => expensiveOperation(),
{ type: 'expensive-op' }
)

  1. Enable Caching:
const data = await cache.fetch(
  'key',
  async () => expensiveOperation(),
  { ttl: 3600 }
)

Environment Setup

Configuration Issues

  1. Verify Environment Variables:
# Check .env file
cat .env
,[object Object],

fly secrets list

  1. Development Setup:
# Reset development environment
npm run clean
npm install
npm run setup

Build Problems

Failed Builds

  1. Clean Build:
# Remove build artifacts
npm run clean
,[object Object],
,[object Object],
,[object Object],

npm run build

  1. Type Errors:
# Run type check
npm run typecheck
,[object Object],

npm run generate

Runtime Errors

Memory Issues

// Monitor memory usage
import { monitorMemoryUsage } from '#app/utils/monitoring'

monitorMemoryUsage({
threshold: 0.8,
interval: 1000
})

Error Handling

// Global error boundary
function ErrorBoundary({ error }: { error: Error }) {
  console.error(error)
  return (
    <div role="alert">
      <h1>Error</h1>
      <pre>{error.message}</pre>
    </div>
  )
}

For more information about security configuration, see the security documentation. For deployment details, refer to the deployment documentation.