feat: virtualized rendering for large JSON (#32)#80
Open
brycewc wants to merge 8 commits into
Open
Conversation
Replace the recursive-DOM renderer with a flatten -> window architecture so
documents with tens of thousands of nodes stay fast.
- src/core: pure flatten() turns src + a path-keyed expand store into an ordered
list of visible rows (collapsed subtrees are never walked); reuses the existing
isCollapsed helpers.
- @tanstack/react-virtual windows the rows, mounting only what's in view with
dynamic measurement.
- Volatile state (collapse/edit/add/delete/long-string) lifted out of per-node
useState into central path-keyed stores so it survives scroll unmount/remount.
- Split Config/Handlers contexts + React.memo row comparator so scrolling and
edits only re-render changed rows.
New props (backward-compatible defaults): virtual ('auto'), rowVirtualThreshold,
height, maxHeight, estimatedRowHeight, overscan. Under 'auto', small documents
render inline as before; windowing engages past the threshold or when a height
is set.
Breaking (0.3.0):
- Large data renders in a bounded scroll box; opt out with virtual={false}.
- onCollapse no longer fires on mount and isCollapsing is no longer inverted.
onEdit/onDelete/onAdd/onChange payloads are unchanged.
Adds Vitest test infra (43 tests: flatten, callback/custom parity, windowing).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the recursive-DOM renderer with a flatten -> window architecture so
documents with tens of thousands of nodes stay fast.
- src/core: pure flatten() turns src + a path-keyed expand store into an ordered
list of visible rows (collapsed subtrees are never walked); reuses the existing
isCollapsed helpers.
- @tanstack/react-virtual windows the rows, mounting only what's in view with
dynamic measurement.
- Volatile state (collapse/edit/add/delete/long-string) lifted out of per-node
useState into central path-keyed stores so it survives scroll unmount/remount.
- Split Config/Handlers contexts + React.memo row comparator so scrolling and
edits only re-render changed rows.
New props (backward-compatible defaults): virtual ('auto'), rowVirtualThreshold,
height, maxHeight, estimatedRowHeight, overscan. Under 'auto', small documents
render inline as before; windowing engages past the threshold or when a height
is set.
Breaking (0.3.0):
- Large data renders in a bounded scroll box; opt out with virtual={false}.
- onCollapse no longer fires on mount and isCollapsing is no longer inverted.
onEdit/onDelete/onAdd/onChange payloads are unchanged.
Adds Vitest test infra (43 tests: flatten, callback/custom parity, windowing).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…eact18-json-view into virtualization-support
…eact18-json-view into virtualization-support
…age always owning it
|
@brycewc is attempting to deploy a commit to the Suni's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #32.
Summary
Adds windowed (virtualized) rendering so large JSON documents stay fast to render and interact with. The tree is now built from a flattened list of visible rows, and large documents are windowed with
@tanstack/react-virtualso only the rows in view are mounted — keeping rendering smooth on documents with tens of thousands of nodes.What changed
.jv-rowelements indented viapadding-left. Core logic lives insrc/core/flatten.ts,src/core/row.ts,src/core/path.ts, andsrc/core/expand-state.ts.src/components/virtual-list.tsx+src/components/row.tsxrender the visible window via@tanstack/react-virtual.scrollRefprop. Lets consumers own the scroll container instead of the package always owning it.New props
virtualboolean | 'auto''auto''auto'windows only when visible-row count exceedsrowVirtualThresholdor aheight/maxHeightis set.rowVirtualThresholdinteger100virtual='auto', the row count above which windowing turns on.heightnumber | stringmaxHeightnumber | string'70vh'when windowedestimatedRowHeightinteger20overscaninteger8Behavior / compatibility notes
This is a breaking (major) change of the rendering internals (v0.3):
virtual={false}to restore the old unbounded layout.onCollapsesemantics fixed — no longer fires on mount;isCollapsingis nowtruewhen collapsing (previously inverted); fires only on user toggles.onEdit/onDelete/onAdd/onChangepayloads (depth,parentPath,indexOrName,parentType) are unchanged.virtual={false}to server-render very large documents.Tests
Adds a Vitest setup with characterization tests (
src/test/characterization/*) covering render, callbacks, and customization, plussrc/test/virtualization.test.tsxandsrc/core/flatten.test.ts.