Skip to content

fix(json-format): restore large JSON results and optimize folding - #672

Open
Souvenirser wants to merge 24 commits into
zxlie:masterfrom
Souvenirser:souvenirser/fix-large-json-render
Open

Souvenirser wants to merge 24 commits into
zxlie:masterfrom
Souvenirser:souvenirser/fix-large-json-render

Conversation

@Souvenirser

@Souvenirser Souvenirser commented Oct 15, 2026 •

Copy link
Copy Markdown

Large valid JSON could leave the result pane blank because the synchronous large-document render ran before the result-ready state was enabled. After adding folding, expanding a parent or all nodes could also stall the browser on nested fold-marker updates and gutter scans. This PR restores visible results and makes repeated folding and partial expansion responsive while retaining the complete JSON for copying and downloading.

Changes:

  • Set the successful result state before calling Formatter, and dispose/clear the previous view when input is empty or invalid.
  • Reuse the bundled CodeMirror 5 and its MIT-licensed folding addons for a read-only, viewport-rendered large-JSON view. Package the assets for both the tool page and automatic formatting, with the existing complete-text fallback when folding is unavailable.
  • Index fold ranges once, collapse only container starts in child-first adaptive batches, skip hidden gutter ranges, and coalesce gutter updates. Reuse folded/expanded documents and avoid CodeMirror's repeated nested-fold width scans when clearing a visible fold. Reset the editor and pending timers on input changes.
  • Give keys, strings, numbers, and booleans/null distinct colors in light and dark themes. Use neutral keys, green strings, red numbers, and muted punctuation to match the requested reference palette. The bundled mode marks keys as both cm-string and cm-property; scoped CSS overrides preserve viewport rendering without adding JavaScript work.
  • Cover repeated expand/collapse, partial expansion, restored child arrows, dirty cached documents, view switches and cleanup. Add a reproducible browser fixture in test/browser.

Validation:

  • Full npm test: 38 files, 329 tests passed.
  • npm run build passed; the package retains all 36 tool entry pages and includes the folding assets.
  • The updated formatter has no additional ESLint diagnostics compared with its existing baseline; the vendored gutter passes node --check. Existing lint findings remain.
  • Chrome exercised the real components from the minified build over HTTP using the original 54,545-line / 2,796,387-character formatted sample for 30 cycles. P95 click-to-first-frame was 39.7 ms for the root, 44 ms for the largest child, and 30.7 ms for expand-all; the longest observed task in the measurement window was 85 ms. These are local measurements, not cross-device guarantees.
  • 2x and 5x stress inputs passed five cycles each, including visible tail-data checks. Actual gutter/ellipsis clicks, a full-content copy event (2,796,387 characters), and the downloaded JSON (2,969,924 bytes, exact comparison) passed. Direct chrome-extension runtime and system-clipboard paste remain manual checks because browser automation cannot access those surfaces.
  • Reverified token colors in the minified build in both themes: all four token classes differ and exceed 4.5:1 contrast. The original sample also passed another 30 fold/expand cycles with complete text and preserved child folds after the CSS change.
  • The published branch tree exactly matches the locally tested tree: 286a5fea65d399813bcc3620745b4ed5f7317d17.

No npm dependencies or original sample data are added. Includes the upstream changes already incorporated into this branch and supersedes #671 under souvenirser/fix-large-json-render.

Exercise the real page and Formatter with long text, node-budget input, small JSON, view transitions, invalid input and auto-decode. Preserve the synchronous boolean return contract.
@Souvenirser Souvenirser changed the title fix(json-format): restore large JSON results and add folding support fix(json-format): restore large JSON results and optimize folding Oct 15, 2026

This branch has not been deployed

No deployments
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