Store the hierarchy as normalized nodes and parent-child indexes, then derive a flattened visible preorder from expanded folders. Keep focus, selection, editing, loading, and mutations separate so lazy responses, virtualization, and concurrent changes cannot silently rewrite the user's current context.
A file explorer is often introduced as recursive rendering. Recursion is the easy part. The hard part appears when a folder opens before its children arrive, focus moves through only visible rows, selection spans collapsed branches, a rename conflicts, or a virtualizer removes the active row.
Derive rows from hierarchy and expansion
Persist stable node and parent relationships. Render a flat visible list produced by preorder traversal: include a node, then include its children only when it is expanded and those children are available. Each row carries node ID, depth, sibling position, parent ID, and expansion capability.
The flattened list gives keyboard navigation, windowing, range selection, and scrolling one shared coordinate system. The normalized tree remains the source of truth. Row indexes are temporary positions in the current projection.
The public interview prompt
Design a reusable tree view and file explorer for a cloud workspace. Explain:
- normalized nodes, child indexes, path data, stable IDs, and visible-row flattening;
- lazy expansion, caching, pagination, retries, cancellation, and stale responses;
- ARIA tree semantics, arrow keys, type-ahead, focus, selection, and multi-select;
- inline rename, create, delete, move, drag alternatives, undo, and conflicts;
- cycle prevention, permissions, symbolic links or shortcuts, and deleted parents;
- large-tree virtualization, variable row detail, search, reveal, and scroll restoration;
- subscriptions, offline limits, instrumentation, tests, and rollout.
Assume one workspace can contain a million nodes, but fewer than 200 visible rows are normally near the viewport. Folder children arrive in pages. Other users can rename, move, or delete nodes. These are interview assumptions, not product measurements. File content editing and operating-system file transfer are outside version one.
What the premium solution covers
The full solution defines the normalized hierarchy, deterministic flattening, child-load state machine, generation guards, focus and selection models, APG keyboard behavior, rename and move transactions, cycle and permission checks, virtualized hierarchy metadata, reveal-by-path, subscriptions, degraded states, observability, tests, and an interview answer rubric.
Original media follows a lazy folder through load and cache reuse, maps normalized records into visible rows, separates four interaction rails, and validates a subtree move. Two deterministic labs exercise keyboard navigation and a stale-response race.