Skip to content

feat(logs): render request/response bodies with CodeMirror - #24

Open
lmk123 wants to merge 1 commit into
mainfrom
feat/logs-json-codemirror-viewer
Open

lmk123 wants to merge 1 commit into
mainfrom
feat/logs-json-codemirror-viewer

Conversation

@lmk123

@lmk123 lmk123 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What

The log-trace dialog rendered request/response bodies as a raw <pre>
string, which is unpleasant to read for large JSON payloads. This swaps
that for a proper read-only CodeMirror viewer.

Changes

  • New src/renderer/src/components/json-view.tsx — a read-only CodeMirror
    viewer with syntax highlighting, code folding, line numbers, and
    Cmd/Ctrl-F search. It's read-only but stays focusable, so search and
    text selection work. Background is transparent to blend into the
    surrounding bg-muted/40 panel; font size matches text-xs; theme
    follows the app's light/dark preference (next-themes + GitHub theme).
  • log-trace-dialog.tsxBodyBlock now uses JsonView. prettyBody
    became formatBody, parsing once to return both the pretty text and an
    isJson flag. Non-JSON bodies (SSE streams, bodies truncated to invalid
    JSON) fall back to a plain-text mode that keeps search/scroll/wrap. Each
    body block gains a copy-to-clipboard button (reusing copyText + sonner
    toast). All three call sites — client request, upstream request, upstream
    response — are covered by this single change.
  • i18n — added toast.bodyCopied and logs.detail.copyBody to both
    en.ts and zh.ts.
  • Dependencies — added @uiw/react-codemirror, @codemirror/lang-json,
    and @uiw/codemirror-theme-github to devDependencies (renderer-only,
    bundled by Vite, matching the existing convention).

Notes for reviewers

  • Scope is deliberately narrow: no changes to the data flow / IPC, headers
    table, or any editing capability — display only.
  • CSP is unaffected: style-src already allows 'unsafe-inline' for
    CodeMirror's injected <style>, and script-src 'self' needs no eval.
  • The viewer keeps a visible caret when focused (the cost of being a
    focusable read-only editor so search works). Easy to hide via the theme's
    caret setting if we'd rather not show it.

Verification

pnpm typecheck and pnpm lint both pass. There is no JS/TS test runner
in this repo, so that is the full verification per project convention.

The log-trace dialog showed request/response bodies as a raw `<pre>`
string, which is hard to read for large JSON payloads.

Replace the `<pre>` in `BodyBlock` with a new read-only `JsonView`
component built on CodeMirror, giving syntax highlighting, code folding,
line numbers, and Cmd/Ctrl-F search. The viewer is read-only but stays
focusable so search and text selection work. Its theme follows the app's
light/dark preference and blends into the surrounding muted panel.

Non-JSON bodies (SSE streams, bodies truncated to invalid JSON) fall
back to a plain-text mode that keeps search/scroll/wrap. Each body block
gets a copy-to-clipboard button reusing the existing clipboard + toast
helpers. All three call sites (client request, upstream request,
upstream response) are covered by the single BodyBlock change.

Adds @uiw/react-codemirror, @codemirror/lang-json and
@uiw/codemirror-theme-github as dev dependencies (renderer-only, bundled
by Vite). New i18n keys: toast.bodyCopied and logs.detail.copyBody.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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