Skip to content

Progressive BIDS tree: render skeleton sync, lazy-load subject contents #64

Closed

Description

@neuromechanist

Symptom

ww2.nemar.org/api/dataset/<id>/tree?v=<v> returns a single monolithic HTML blob that the client paints in one go. For on005505, this is 3.3 MB of HTML for 5,409 paths (136 subjects). On a low-bandwidth connection the file panel blocks for many seconds before anything renders, even though all the data needed for the first useful view (top-level folders + subject names) is a few hundred bytes.

Root cause (design)

src/pages/api/dataset/[id]/tree.ts builds the entire BIDS tree from summary.paths and ships every node — including every file under every subject — in the initial response. The page can't show anything in the file panel until the whole blob arrives, parses, and inserts.

summary.json already has the structure needed for a progressive view:

  • subjects (count + names)
  • paths (full flat list, used today)
  • totals.files, totals.bytes

Proposal

Render the tree in two stages:

Stage 1 — Skeleton (synchronous, < 50 KB)

From summary.json alone:

  • Top-level non-subject entries (README, dataset_description.json, code/, .nemar/, etc.) with file/folder badges
  • One row per subject (collapsed), showing sub-XYZ (N files) derived from a per-subject path-prefix count
  • Total file count + size

Return this as the first response from /api/dataset/<id>/tree?v=<v>. Even on cold edge this is < 50 KB and < 200 ms.

Stage 2 — Expand a subject (lazy)

When the user clicks a subject row, fetch only that subject's subtree:

GET /api/dataset/<id>/tree?v=<v>&subject=sub-NDARAC904DMU

The handler filters summary.paths to that prefix and returns just the rendered subtree. Cached per (id, version, subject) at the edge.

Alternatives considered:

  • Server-side virtual list: still ships everything, doesn't help bandwidth.
  • Client-side filter on the full blob: still pays the 3.3 MB download.

Acceptance

  • First tree paint for on005505 in < 500 ms on a cold isolate (Stage 1 < 50 KB)
  • Subject expand fetches < 100 KB and renders in < 300 ms
  • BIDS tree visual parity with current monolithic render once everything is expanded
  • Keyboard nav (focus, enter to expand) still works
  • Works for datasets without subjects (rare; falls back to old monolithic render)

Related

Activity

  1. added
    enhancement
    on May 26, 2026
  2. added 2 commits that reference this issue on May 26, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions