Skip to content

feat: fold blocks in the large-response body viewer - #52

Merged
axbarchuk merged 3 commits into
voleeo:mainfrom
lucasAguiar11:feat/fold-large-response-body
Aug 18, 2026
Merged

feat: fold blocks in the large-response body viewer#52
axbarchuk merged 3 commits into
voleeo:mainfrom
lucasAguiar11:feat/fold-large-response-body

Conversation

@lucasAguiar11

@lucasAguiar11 lucasAguiar11 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What & why

Collapse chevrons disappeared once a response got large. Bodies over 256 KB render in the virtualized viewer, which never had fold controls — so on a 31 MB payload the only ways to navigate were scrolling ~1.4M lines or the JSONPath filter, which answers "show me this path", not "what's in here".

This PR adds folding to the windowed viewer:

  • Backend: fold_ends walks the pretty-printed body once with a bracket stack, inside the parse that already runs for windowing, and every BodyWindow carries the closing line of each line it returns. The frontend only holds a slice at a time, so it can't find a block's end itself. Unbalanced (non-JSON) text yields no folds.
  • Frontend: collapsed blocks become runs of hidden lines, so rows on screen no longer map one to one onto the body. The visual ↔ real translation lives in lib/lineFolds.ts (pure, tested); useLineFolds owns the state.
  • A folded row renders { … }, the way CodeMirror does — the closing line's own text when it's loaded, the mirrored bracket when it isn't.
  • A search hit inside a collapsed block opens it before scrolling.
  • The scrolled content moves out of VirtualBody into VirtualBodyLines to stay under the 250-line limit.

Small responses are untouched: the Rust and React entry points sit behind the same 256 KB gate (response.rs:93, BodyTab.tsx:93), so nothing on the CodeMirror path reaches a changed line. BodyWindow is the only shared type that changed, and it exists solely on the windowed path.

Closes #51

Folding individual blocks

Captura de Tela 2026-08-07 às 11 10 01

Collapsing the whole array

Captura de Tela 2026-08-07 às 11 10 14

How to test

  1. GET https://jsonplaceholder.typicode.com/photos — 1.0 MB, past the 256 KB threshold
  2. Chevrons should appear in the gutter beside every block-opening line
  3. Collapse a nested object and the root array; line numbers stay real and skip the hidden range
  4. ⌘F for a term inside a collapsed block — it should open and scroll to the match
  5. Apply a JSONPath filter; fold state resets with the new body
  6. A small response (/comments, 158 KB) still renders in CodeMirror, unchanged

Out of scope

The line-wrap toggle, which the issue mentions for the same reason. Row heights are uniform today; wrapping makes them depend on line lengths the viewer only learns as blocks load, so the scrollbar would drift on a 1.4M-line body. Worth its own change.

Checklist

  • bun run typecheck, bun run lint, and the cargo checks pass (see CONTRIBUTING.md)
    • also bun run test (9 new lineFolds tests), bun run check:sizes, cargo test --workspace
  • New Tauri commands are registered in collect_commands! and bun run codegen was run
    • n/a — no new commands; codegen re-run because BodyWindow gained a field
  • Follows the rules in AGENTS.md (file-size limits, render-loop rules, no migration shims)

lucasAguiar11 and others added 3 commits August 7, 2026 11:06
The windowed viewer only ever holds a slice of the body, so it cannot tell
where a block ends. fold_ends walks the pretty-printed text once with a
bracket stack, and each window carries the ends of its own lines.
Responses over 256 KB render in the virtualized viewer, which had no fold
controls — the bigger the payload, the less there was to navigate with.

Collapsed blocks become runs of hidden lines, so rows on screen no longer
map one to one onto the body and have to be translated back before anything
is fetched or searched. That math lives in lib/lineFolds.ts with its own
tests; useLineFolds owns the state, and the scrolled content moves out of
VirtualBody to keep both files under the size limit.

Closes voleeo#51
@axbarchuk
axbarchuk merged commit 5cec9ce into voleeo:main Aug 18, 2026
1 check passed
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.

Block folding is missing in the large-response body viewer

2 participants