Skip to content

feat(admin-ui): improve the collection API document viewer — shallower expansion, copy/download, later a JSON mode #99

Description

@58bits

Background

ApiView renders the whole document payload with shouldExpandNode={allExpanded}:

  • packages/host-tanstack-start/src/admin-shell/collections/api.tsx

For documents with rich text, blocks, multiple locales, and populated relations this produces a long tree that is both expensive to mount and hard to scan.

Evidence

Profiled in the admin UI against a seeded docs document on the dev server:

  • Page total: 5396 DOM nodes, of which 4182 (78%) belong to .byline-api-viewer.
  • The first layout of that freshly mounted tree costs roughly 740 ms in a dev build. Incremental re-layout of the same page afterwards is ~1 ms whether the viewer is displayed or hidden — so the cost is tied to mounting the expanded tree, not to repeated work.

react-json-view-lite does not mount collapsed descendants, so reducing the initial expansion genuinely reduces DOM size rather than just hiding nodes.

Scope

Keep the current tree viewer. Do not switch libraries for this — there is no comparative profile establishing a benefit.

  1. Shallower initial expansion. Show document metadata and the first level of content fields; leave deeper structures collapsed. Keep the expansion callback referentially stable so unrelated renders do not reset the reader's choices.
  2. Copy JSON / Download JSON. Both operate on the complete loaded document regardless of what is collapsed, and retain the existing locale and populate-depth controls.
  3. A lazily loaded, read-only JSON mode (later). CodeMirror is the natural fit — the repo already has a code editor with JSON and read-only support at packages/admin/src/fields/code/code-editor.tsx. It renders only the visible portion plus a margin, and its search extension searches the document rather than relying on browser Find over rendered text.

That existing editor needs adaptation before reuse as an inspector: search and folding configuration, keyboard focus in read-only mode, and reliable document replacement when locale or depth changes. Its current synchronization deliberately ignores external updates while focused, which suits editing but not an inspector.

Known limitation

Shallow expansion helps nested documents. Expanding an array with thousands of entries still renders all of them, so it does not solve every large-payload case.

Success criterion

Less blocking on mount and a faster usable view, with layout still correct. The
console warning disappearing is not the goal on its own — a change that only
stops Chrome attributing the reflow to JavaScript, while the same layout work
still happens at paint, has not improved anything for the reader.

Validation

Check against representative rich-text and populated documents, not a minimal one.

Compare initial navigation before and after with identical data and viewport,
take repeated measurements rather than one sample, and back them with a browser
performance trace. The numbers quoted above are single samples from a dev build and
are indicative only — they are not a baseline anyone should compare against
directly.

Note

This is a usability improvement first. It is also the change most likely to move the [Violation] Forced reflow warning reported on this view, because it reduces the DOM that must be laid out on mount — see the companion issue on the tabs measurement for why the breadcrumb work did not resolve it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: admin-uiAdmin interface, routes, and shellenhancementNew feature or requestpriority: nextKnown and queued for coming PRs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions