Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Move PostHog proxy from Next.js rewrites to middleware
  • Fixes 400 errors on /ingest/s for large session recording payloads (1MB+)

Type of Change

  • Bug fix

Testing

Tested manually - deploy to preview and verify /ingest/s requests return 200

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 29, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 29, 2026 7:38am

Request Review

…yload support

Next.js rewrites can strip request bodies for large payloads (1MB+),
causing 400 errors from CloudFront. PostHog session recordings require
up to 64MB per message. Moving the proxy to middleware ensures proper
body passthrough.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@waleedlatif1 waleedlatif1 force-pushed the fix/posthog-session-recording branch from 8863da8 to 781929e Compare January 29, 2026 07:38
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 29, 2026

Greptile Overview

Greptile Summary

Moved PostHog session recording proxy from Next.js rewrites to middleware to fix 400 errors on large payloads (1MB+), and fixed React hooks violations in credential selector components by using createElement.

Key Changes:

  • Moved /ingest/ proxy logic from next.config.ts rewrites to middleware (proxy.ts) for better large payload handling
  • Added early routing in middleware for /ingest/ paths before authentication checks
  • Fixed React hooks violations in 3 components by replacing direct icon function calls with createElement

Technical Details:

  • The middleware proxy uses NextResponse.rewrite with proper header forwarding including the host header
  • Correctly handles both /ingest/static/ (us-assets.i.posthog.com) and /ingest/ (us.i.posthog.com) paths
  • PostHog proxy executes before authentication logic, which is correct for analytics tracking

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • Well-structured bug fix with clear implementation - the PostHog proxy logic is correctly implemented with proper header forwarding and path handling, and the React hooks violations are properly fixed using createElement
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/proxy.ts Added PostHog /ingest/ proxy routing before authentication checks to handle large session recording payloads
apps/sim/next.config.ts Removed PostHog rewrites configuration as proxy logic moved to middleware

Sequence Diagram

sequenceDiagram
    participant Client as PostHog Client
    participant Middleware as Next.js Middleware (proxy.ts)
    participant PostHog as PostHog US Server
    
    Note over Client,PostHog: Before (Next.js Rewrites)
    Client->>Middleware: POST /ingest/s (1MB+ payload)
    Note over Middleware: Rewrite at routing layer
    Middleware->>PostHog: Forward to us.i.posthog.com
    PostHog-->>Middleware: 400 Error (payload too large)
    Middleware-->>Client: 400 Error
    
    Note over Client,PostHog: After (Middleware Proxy)
    Client->>Middleware: POST /ingest/s (1MB+ payload)
    Note over Middleware: Handle in middleware runtime<br/>with streaming support
    Middleware->>PostHog: Rewrite to us.i.posthog.com<br/>with correct headers
    PostHog-->>Middleware: 200 Success
    Middleware-->>Client: 200 Success
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 1256a15 into staging Jan 29, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/posthog-session-recording branch January 29, 2026 07:50
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.

2 participants