Files
twenty/packages
Sonarly Claude Code a77cbf6cbd fix: optimize metadata payload size and file response parsing for record index pageload
https://sonarly.com/issue/22045?type=bug

The /objects/products record index page takes ~6 seconds to load due to a 494KB metadata response, a 5.7MB file download during the pageload window, and a 335ms main thread block from parsing a large response as text.

Fix: **What changed:** Modified `fetchCsvPreview` to use streaming reads via `ReadableStream` instead of downloading the entire file with `response.text()`.

**Why:** The original code called `response.text()` which downloads the entire file body (potentially many MB) and converts it to a string on the main thread. For a 5.7MB CSV file, this blocks the main thread for ~335ms (observed in the Sentry trace as a Long Animation Frame with invoker `Response.text.then`). The fix uses `response.body.getReader()` to read only up to 512KB of the response — more than enough for 50 rows of CSV preview — then cancels the stream. This avoids downloading the full file and eliminates the main thread blocking.

**Changes:**
1. `fetchCsvPreview.ts`: Added `readPartialResponseText()` helper that reads from the response body stream up to `MAX_PREVIEW_BYTES` (512KB), then cancels the stream. Falls back to `response.text()` if the body stream is not available.
2. `fetchCsvPreview.test.ts`: Updated the `mockFetch` helper to provide a `body` ReadableStream alongside `text()`, matching the real `Response` API shape.

**Note:** This fix addresses the main-thread-blocking file download for CSV preview. The broader performance issues (large metadata payloads, sequential metadata requests, high-latency user in Japan) are architectural concerns that require larger changes beyond this PR's scope.
2026-04-06 04:00:47 +00:00
..
2026-04-04 06:05:51 +00:00
2026-04-03 12:44:03 +00:00
2026-04-04 06:05:51 +00:00