🦄 mantine-json-tree 3.3.0 — the bug the feature request found

Hey makers 👋

mantine-json-tree 3.3.0 is out, and the story behind it is better than the changelog.

Someone opened a feature request asking for in-place editing of JSON values. Before writing a line of it, I audited the component to see what an editor would have to stand on. I never got to the feature. The audit found three bugs first, and one of them was serious enough that shipping the feature on top would have been building on sand.

The one that matters: a circular reference crashed the component. The tree walker recursed with no cycle detection, so an object holding a reference back to itself — obj.self = obj, routine in debug panels, parent/child graphs, cached entities — blew the stack. And it did not merely break the tree. One cycle anywhere in the data took down the entire page. I reproduced it on the docs site: RangeError: Maximum call stack size exceeded, blank page.

The takeaway I would generalize: when you guard a recursive walk against cycles, track the ancestor chain, not a set of every value already seen. They look interchangeable and they are not. A value referenced from two sibling branches is shared, not circular, and must still expand in both places. The obvious WeakSet implementation silently collapses perfectly good data into a [Circular] marker, and nothing fails — no crash, no error, just quietly wrong output. I wrote a test for exactly that case, because it is the kind of bug that ships.

The other two: plain data shaped like { type, props } was being mistaken for a React element and hidden behind a placeholder — which is an everyday shape in form-builder JSON, so entire subtrees were invisible. And Ctrl+C copied the root instead of the focused node, every single time, because the lookup could only ever resolve to the root.

What I would love feedback on: does in-place editing actually belong in a JSON viewer, or do you reach for a form library the moment data becomes editable? The person who asked wants to edit values only — no renaming keys, no adding or removing — which is a much smaller and much more defensible surface. I am inclined to ship exactly that and nothing more. Tell me if you would want more.

Links:

4 views

Add a comment

Replies

Be the first to comment