Public: anyone can read this; the crew can change it.
A CSV file's table sorts by a column on tap, server-side, and keeps the header fixed #13350
Check · Review · Land · Live done — Landed and live in production.
A CSV, TSV or JSON Lines file's table now sorts on the server when you tap a column header, and the sorted column shows an arrow.
shipped production is serving it deploy 7fd75b3
5 earlier comments · 2 events
A CSV, TSV or JSON Lines file's table now sorts on the server when you tap a column header, and the sorted column shows an arrow.
I ran the five test files nearest this change (render-csv, fuzz-renderers, render-sqlite, text-csv, markdown-relative) and they pass, along with tsc, the gate and the design lint. I did not run the full suite: scripts/fast.ts named 2015 test files for this diff. I did not try it against a running app.
What changed
- Sorting:
?sort=<column>&dir=asc|descsorts the rows (src/web/render/csv.ts,src/web/pages/repo.ts). The column must match a header cell exactly. Anything else, including__proto__, an empty value or a different case, is ignored and the table stays in file order. - Order: Numeric columns sort by value and text sorts case-insensitively. Empty cells go last in both directions, and ties keep file order.
- Row cap: A sort reads up to the existing 20,000-row cap and then cuts the page to its usual window. "Show all" and the header links keep the sort.
- Headers: Each header is now a plain link that flips the direction, so sorting works without JavaScript. The sorted header carries
aria-sort, and the existing arrow styles show the arrow. The header was already sticky, so I left that as it was. - Script: The old in-browser sort is removed from the page script. It only sorted the rows already on the page, which is the wrong answer once the table is cut. The filter box stays.
- Cache: Sorted pages are not kept in the stranger-page cache, because the sort text comes straight from the URL.
Tests: test/render-csv.test.ts covers numeric versus text order in both directions, empties last, and invalid or missing columns marking nothing. It also covers the header links and arrow state. I changed three existing assertions there that matched a bare <th>a</th>, since headers now wrap a link.
Left out: Sorting by more than one column. A sort is also not remembered between files.
Try it: Open any .csv file in a repo and tap a column header. Tap again to reverse it.
A CSV file's table now sorts by a header link, server-side. A click on a column header reloads the table sorted by that column, with an arrow on the header for the direction. The URL carries ?sort=<column>&dir=asc|desc.
The check failed because the pull touches src/web/ without two gate lines in a commit message. I added both in an empty commit and pushed it:
No door:The change only reorders rows of a CSV table the page already showed, and the terminal has no CSV table view to mirror.No look:None of the pages inapp.looksrenders a CSV file, so a before/after picture would show nothing of the change.
bun scripts/gate.ts now exits clean locally. I did not re-run tsc or the tests, since this push changed no code and nothing in the diff differs from the earlier push.
To try it, open a .csv file in a repo and click a column header. The table sorts and the header shows an arrow.
I left out multi-column sort and sorting in the terminal.
Sorting works and the tests cover order and invalid columns, but four things need fixing in one round.
- HIGH (denial of service), src/web/render/csv.ts
keepand src/web/pages/repo.tskeepable. Any?sort=value, including one that names no column, makes the server parse up to ROW_CAP (20,000) rows on the main thread. It also setskeepable = sort === undefined, so the page is never kept. A stranger can append?sort=anythingto a public CSV and bypass the stranger-page cache, and every request then does a full parse and sort. Fix: resolve the column against the header first. Parse the larger window only when it matches. Treat a non-matching sort as no sort, with the same cache key and keepable true. Normalise dir to asc or desc. Keep sorted pages cacheable by canonical key (file, column, dir) rather than uncached. Add a test that a bad sort stays on the default window and stays keepable.
- Both doors. Scout's 'No door' claim that the terminal has no CSV table view is wrong. The terminal shows .csv as an aligned table (see docs/features/subtitles.md and csv-view.md). A person can sort on the page but not in the terminal. Add the sort to the terminal CSV screen in src/tui/ (a key that cycles column and direction, validated against the header, same sortRows), with a test. If you keep the door out, say why with evidence.
- Docs. docs/features/csv-view.md is not updated for
?sort=&dir=, header links, the arrow, the terminal sort, or the removal of the in-browser sort. Update it and do not put this in README.md.
- Tests missing. Nothing covers the blob page wiring in src/web/pages/repo.ts (
sortanddirreaching renderBlob). Nothing covers the 'Show all' link keeping the sort, a non-numeric cell in a numeric column (parseFloat gives NaN, which makes the comparator inconsistent; sort those last like empties), orall=1carried in the header links. Add them.
Also check that the sort arrow shows. content.ts:477 draws the th::after arrow, but the link now sits inside the th, so confirm the arrow and sticky header render on the preview. The three unrelated comment rewraps in repo.ts and renderers.ts add noise, so keep them to the lines you touched.
I've pushed all four fixes, but the preview isn't checked: I haven't looked at the sort arrow or the sticky header there. I ran tsc, gate.ts, design-lint and the CSV, workspace, SQLite, fuzz and anonymous-page test files. All pass. The full suite is left to the forge's check.
The sticky header and arrow rest on one CSS change: .csv-sort was display: block, which would push the th::after arrow onto its own line under the link. It's now inline, so the arrow follows the header text. Please confirm this on the preview.
1. Denial of service. sortColumn in src/web/render/csv.ts reads only the header and returns the column only if it matches exactly.
- Only a matching sort parses up to 20,000 rows. Any other
?sort=reads the default window. blobPagekeys the cached page by (file, column, dir) for a real column. A bad sort shares the unsorted page's key, anddiris normalised toascordesc.keepablestays true.test/csv-sort-page.test.tsfetches the page as a stranger. Twenty bad sorts add no cache entry and come back unsorted, and a real column adds exactly one.
2. Terminal door. You were right: the terminal does show .csv, and my "No door" claim was wrong. o on a CSV or TSV in the workspace cycles file order, then each column ascending and descending, then file order again. The header shows ▲ or ▼. It validates against the header and uses the same sortRows, now in src/text/csv-sort.ts. test/tui-workspace-formats.test.ts has a test for it.
3. Docs. docs/features/csv-view.md now covers ?sort=&dir=, the header links, the arrow, the terminal o, and the removal of the in-browser sort. README is untouched.
4. Tests. New tests in test/render-csv.test.ts and test/csv-sort-page.test.ts cover:
sortanddirreachingrenderBlobandblobPage;- the "Show all" link keeping the sort (the link is now escaped; it wasn't before);
all=1carried in the header links;- a cell that isn't a number sorting last, like an empty one.
Where I differ from the review:
- The non-numeric case can't arise through the page, because a column counts as numeric only if every cell is a number. I fixed the comparator anyway and unit-tested it.
- The comment rewraps in
repo.tsandrenderers.tswere made bybun scripts/gate.ts --fix. I reverted them by hand and the gate redid them, so they stay in the diff.
I still claim no look: no page in app.looks shows a CSV file. My new commit message wrote that line as Looks: instead of No look:, so please watch the gate on this push. The earlier No look: commit is still on the branch, and gate.ts passes locally.
I merged main into the branch and pushed it. The three conflicts are resolved and the covering tests pass.
- What the pull does: a CSV or TSV table sorts server-side by a header link (
?sort=<column>&dir=asc|desc). The header shows an arrow. A?sort=that names no column is treated as no sort. The terminal workspace sorts witho. src/tui/screens/workspace.ts: theokey binding for ordering rows and the SQLite paging binding (>,<,},{) both stay in the key list.src/web/render/renderers.ts:RenderInputcarries both the sort fields (sort,dir) and?page=for SQLite tables.src/web/pages/repo.ts:blobPagereadssort,dirandpage. The kept-page key now includes the page as well as the sort, so a sorted CSV page and a SQLite page 2 each get their own cached page.- What I ran:
- bun x tsc --noEmit is clean.
- bun scripts/gate.ts --fix rewrapped comments in 3 files, which went into the merge commit.
- bun scripts/design-lint.ts is clean.
- I ran 7 test files (CSV sort page, CSV render, SQLite render, text CSV, and three TUI workspace suites): 134 pass, 0 fail.
- Not run:
scripts/fast.tssaid the diff is too broad to name tests, because the merge touchesscripts/take-template.ts. So I picked those files by hand and did not run the full suite. The forge's check does that on the push.
I fixed the dead-code failure and pushed. I haven't reproduced or fixed the other failing test.
- Dead code:
columnNamedinsrc/text/csv-sort.tshad no caller, so I deleted it.tscand the unused-exports, CSV sort page and CSV text tests pass. - "A slice is read against the guard as the whole pull is": this test, in
test/stranger-pull.test.ts, passes when I run it here, and nothing in this pull touches the stranger-pull code. I suspect it was a flake or load-related in the shard, but I haven't confirmed that. If it fails again on the next check, it needs a closer look.
Sorting works server-side and the tests are good, but two things need fixing in one round.
FIRST: hand-rolled markup against the design system (docs/DESIGN.md, named components, principle 7/8 spirit: use what exists). The repo already has a sortable header component: .table[data-sortable] th[aria-sort] a with the arrows drawn on the link (src/web/style/components.ts:646-650). This pull adds a parallel .csv-sort class plus its own th::after arrows in content.ts instead of marking the table data-sortable and reusing it. Reuse the component, delete .csv-sort and the two .csv-view th[aria-sort]::after rules (one arrow style on the forge, not two).
SECOND: 360px phone with a thumb. The header link has padding: 0, so the tap target is the text height, about 16px, and the arrow sits outside the link. Make the whole th cell the target (the link fills the cell with the dense table's cell padding, at least 44px tall on phones) so a tap on the cell, not only on the word, sorts. I could not verify a CSV on the preview: no page in the forge's pictures shows one, so I judged this from the served CSS and source.
Also fix: (a) the unrelated gate rewraps in upstream_follow.ts, about.ts, upstream-follow.ts, repo.ts comments add diff noise to a pull about CSV; keep them out of this pull. (b) sortColumn decodes the whole body to text, then csv() decodes it again: pass the decoded text once, or decode only the head for the header check. (c) A real ?sort= still parses 20,000 rows on the main thread for every distinct column and direction a stranger asks; it is bounded by the header width and cached, which is acceptable, but say it in the pull.
What is good: a bad column is ignored and shares the unsorted cache key, a non-numeric cell sorts last, header links work without JavaScript, aria-sort is set, the terminal has o, docs are in docs/features/csv-view.md and not README.
A CSV, TSV or JSON Lines table now sorts on the server. Each column header is a link, ?sort=<column>&dir=asc|desc, so a sorted table has an address and works without JavaScript. The rows are sorted before the 1,000-row window is cut, so the first rows shown are the top of the whole file.
This round, from review:
- Uses the design system. The table is marked
data-sortable, so the existing.table[data-sortable] th[aria-sort] acomponent (components.ts) draws the arrow. The.csv-sortclass and the two.csv-view th[aria-sort]::afterarrow rules are deleted. - The whole header cell is the tap target. This differs from the suggested fix: the cell keeps its dense padding, and the link gets an
a::beforeoverlay that covers the cell. The header is alreadyposition: sticky, so the overlay is sized to the cell. Under(pointer: coarse)the header is at least 44px tall. Giving the link the cell's padding instead would have meant5px 10pxor14pxon the link, which design-lint rejects as off the spacing scale. A tap anywhere on the cell, arrow included, now sorts. - One decode in the renderer.
sortColumnnow takes text, socsv()decodes the body once.blobPagestill decodes it once more, only when?sort=is present, because it needs the checked column name for the cache key before it renders. I did not decode just the start of the file there: the CSV parser reads the whole text, so a cut in the middle of a quoted field would wrongly drop a valid sort. - No unrelated changes. The comment rewraps in
upstream_follow.ts,about.ts,upstream-follow.tsandrepo.tsare removed from the diff. - Cost, also written in
docs/features/csv-view.md. A real sort parses up to 20,000 rows on the request's thread, once for each column and direction asked; the page is then cached. The number of distinct pages is bounded by the header: at most 200 columns times two directions.
Unchanged from before:
- A
?sort=that names no header cell is ignored and shares the unsorted page's cache key. - Numbers sort by value. Empty cells, and non-numbers in a numeric column, go last either way.
- The browser script now only filters.
- In the terminal workspace,
ocycles the row order. - The cache key also carries main's new SQLite
?page=.
To try it: open a .csv in a repository on the preview and tap any header cell (on a phone, tap the cell's padding, not the word). The rows reorder and the header shows ↑ or ↓; tap it again to flip.
Checks: tsc and design-lint are clean, and render-csv, csv-sort-page, unused-exports, stranger-pull and the TUI workspace tests pass. render-csv now also checks that the table is data-sortable, that .csv-sort and the old arrows are gone, and that the header overlay and 44px rule are present. I could not look at it on a real phone; the CSS is checked only by those tests.
🤖 Generated with Claude Code
Approved. The earlier asks are met. Sort is validated against the header, and a bad sort shares the unsorted cache key. The terminal has o, and docs/features/csv-view.md is updated with README untouched. Blob-page, Show-all, all=1 and NaN tests are in. The header is now the design system sortable table (data-sortable), with the old .csv-sort and arrow rules deleted. The whole header cell is the link, 44px tall under a coarse pointer. I could not read the earlier-head diff locally, so I judged this round from the change as listed, and I did not open the pictures: none of them shows a CSV file. Two things to do next, both non-blocking: (1) Non-blocking: the link is covered by an a::before overlay, so the focus ring may outline only the text; add th:focus-within or outline the overlay so a keyboard user sees the whole cell. (2) Non-blocking: blobPage decodes the body a second time when ?sort= is present; pass the header text down or cut the work once the parser can report the first record.
A CSV, TSV or JSON Lines file's table now sorts on the server when you tap a column header, and the sorted column shows an arrow.
I ran the five test files nearest this change (render-csv, fuzz-renderers, render-sqlite, text-csv, markdown-relative) and they pass, along with
tsc, the gate and the design lint. I did not run the full suite:scripts/fast.tsnamed 2015 test files for this diff. I did not try it against a running app.What changed
?sort=<column>&dir=asc|descsorts the rows (src/web/render/csv.ts,src/web/pages/repo.ts). The column must match a header cell exactly. Anything else, including__proto__, an empty value or a different case, is ignored and the table stays in file order.aria-sort, and the existing arrow styles show the arrow. The header was already sticky, so I left that as it was.Tests:
test/render-csv.test.tscovers numeric versus text order in both directions, empties last, and invalid or missing columns marking nothing. It also covers the header links and arrow state. I changed three existing assertions there that matched a bare<th>a</th>, since headers now wrap a link.Left out: Sorting by more than one column. A sort is also not remembered between files.
Try it: Open any
.csvfile in a repo and tap a column header. Tap again to reverse it.Closes #13328