Repository navigation
Description
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
- Builds on Use compact summary.json instead of full manifest.json for dataset detail page #29 (summary.json fast path)
- Adjacent: Generate + serve compact summary.json alongside manifest.json (small artifact for path-only views) nemar-cli#558 / closed epic Dashboard omits collaborated datasets (nm000974) and Collaborators button redirects to 404 on private datasets #559 (generator already emits per-subject path data we need)
Activity
review(#64): address pr-review-toolkit findings
Merge pull request #69 from nemarOrg/feature/issue-64-progressive-bid…
Phase 3: page-bundle endpoint for one-RTT dataset detail SSR (#624)