Skip to content

Conversation

@RaenonX
Copy link

@RaenonX RaenonX commented Nov 24, 2025

The original implementation would show Cannot read private member #state from an object whose class did not declare it error.

Production shows nothing (only return 500).

The app was built and ran on Windows.

@vercel
Copy link

vercel bot commented Nov 24, 2025

@RaenonX is attempting to deploy a commit to the umami-software Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 24, 2025

Greptile Overview

Greptile Summary

This PR fixes a critical runtime error in the /api/batch endpoint where creating a new Request object by cloning an existing request would fail with a "Cannot read private member #state" error. The issue manifested as a 500 error in production environments, particularly on Windows builds. The batch API endpoint processes arrays of data items by creating individual HTTP requests for each item to send to other API endpoints.

The fix replaces the problematic new Request(request, { body: JSON.stringify(data) }) pattern with manual Request construction using the original URL, method, and headers. This approach avoids the Node.js Request constructor's internal state management issues when cloning requests. The new implementation properly handles HTTP headers by copying the original request headers, setting the content-type to application/json, and removing the content-length header to prevent conflicts. This change ensures the batch endpoint can successfully process multiple data items in production environments.

Important Files Changed

Filename Score Overview
src/app/api/batch/route.ts 4/5 Fixed Request object cloning issue by manually reconstructing requests instead of using problematic clone constructor

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it fixes a critical production issue without introducing breaking changes
  • Score reflects that the fix addresses a well-documented Node.js environment issue with a clean, straightforward solution that properly handles HTTP headers
  • Pay close attention to src/app/api/batch/route.ts to verify the header handling logic is correct

Sequence Diagram

sequenceDiagram
    participant User
    participant BatchAPI as "/api/batch"
    participant ParseRequest as "parseRequest"
    participant SendAPI as "/api/send"
    
    User->>BatchAPI: "POST /api/batch with array of data"
    BatchAPI->>ParseRequest: "parseRequest(request, schema, {skipAuth: true})"
    ParseRequest-->>BatchAPI: "return {body, error}"
    
    alt error exists
        BatchAPI-->>User: "return error response"
    else no error
        loop for each data item in body
            BatchAPI->>BatchAPI: "create new Headers from request.headers"
            BatchAPI->>BatchAPI: "set content-type to application/json"
            BatchAPI->>BatchAPI: "delete content-length header"
            BatchAPI->>BatchAPI: "create new Request with copied headers and JSON.stringify(data)"
            BatchAPI->>SendAPI: "send.POST(newRequest)"
            SendAPI-->>BatchAPI: "return response"
            
            alt response not ok
                BatchAPI->>BatchAPI: "add error to errors array"
            end
        end
        
        BatchAPI-->>User: "return JSON summary {size, processed, errors, details}"
    end
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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

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