Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): large GBK CSV previews show readable cells on first open #48146

ClosedStiensWout(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/48146/headopened View on GitHub

Opening a GBK-encoded CSV larger than the first-screen prefix showed replacement characters in its first rows until the worker finished indexing, because the prefetched 16 KB prefix was always decoded as UTF-8. The first-screen fetch now decodes its bytes with the shared preview decoder (UTF-8, then GB18030, dropping a character cut at the range end), matching how the worker reads the file, so the first table shows readable Chinese text.

Related: #46590, #37889, #48133, #45854

Reproduction on main

Commit 450925de8a (main). The first row shows replacement characters until the rest of the preview catches up. Expected: The first table the preview displays shows the Chinese characters correctly.

  1. Attach a GBK-encoded CSV larger than 1 MB with Chinese characters in its first data row to a draft message.
  2. Open the attachment preview.
  3. Look at the first row as the table appears.

The cause is at apps/web/src/components/files/LargeTextViewer.tsx:232. Ran pnpm scenarios:prove scripts/scenarios/large-gbk-csv-first-screen.e2e.ts --target web with the repro scenario added: it failed in 2 of 2 runs on a clean boat.dev VM, with expected "����" to be "中文" in the output.

Evidence

Environment: Linux x64 on a boat.dev VM reset before each run, the repository's own tests.

Proven: the replacement test apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx fails at the test commit 1022d3f508 and passes on the head cf65fb553f, both on main e0661db2c8.

BeforeAfter
Commit1022d3f508cf65fb553f
Resultfailed with "to be '中文'"passed
first csv screenBefore: first csv screen Before: first csv screen (changed region)
The first row shows replacement characters until the rest of the preview catches up.
After: first csv screen After: first csv screen (changed region)
The first table the preview displays shows the Chinese characters correctly.
failureBefore: failure
RecordingBefore: recordingAfter: recording

Tests

  • 1022d3f508 adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed e0661db2c851d1c8c2f126d37c40dc3e665e5ec6 passed on head.

Not in this change

  • A prefix that is valid as both UTF-8 and GB18030, in a file whose first invalid UTF-8 byte comes later, still paints the UTF-8 reading and then switches once the worker sees the invalid byte. Main does the same from both the first screen and the worker's provisional page 0. Avoiding it means either hiding the instant first screen for most UTF-8 CJK files (their bytes are usually valid GB18030 too) or holding worker pages until the whole file (up to 256 MB) is read, which is a separate decision.
  • Files that are neither UTF-8 nor GB18030 now skip the instant first screen and wait for the worker's existing error instead of painting garbled rows.
  • The in-memory text prop path was already decoded and is unchanged.
  • Mobile does not use this viewer, so it is unchanged.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Duplicate check judged by Claude Opus 5.5, in Claude Code
  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by Claude Opus 5.5 and GPT 6.2 Sol

    1. Pushed5a47c67

    2. The automated pipeline ran the reported steps in the real app without this change, and the problem did not appear. So it cannot show that this change fixes anything.

      What was run on 7b6a2c96f6, the commit before this change:

      On each commit, open the web app, attach short.csv and a 1.1 MB long.csv containing GBK bytes for 中文, open the short preview, close it, open long.csv, wait for 中文 in the preview, and capture the rendered preview.

      How: Web scenario runner with fresh seeded demo project, real local server/browser, synthetic GBK CSV bytes injected through the composer file input; compared base and head.

      Closing this pull request. If you can share the exact steps, what you see, and the version and platform you are on, it can be reopened.

    3. juliusmarminge closed this

    4. juliusmarminge removed labelstakeover:in-progress

    5. juliusmarminge added labelstakeover:blocked

Sign in to join this conversation.