Deep nested conversations
The recursive implementation is elegant but might hit stack overflow with deeply nested data. Has anyone benchmarked this?
Good point. I tested with 10,000 nodes and it started throwing errors around depth 5000.
You could use a trampolined version to avoid stack overflow. Here's a snippet that converts recursion to iteration.
Nice! Though for React components, I'd recommend keeping depth under 100 for performance reasons.
Agreed. We implemented a depth limit of 50 with a 'continue thread' button for deeper discussions.
I wonder if virtualization would help here. Only render visible nodes in the tree?
For production use, I'd go with iteration + explicit stack. More verbose but predictable.
The TypeScript types for this are interesting. Anyone have a good recursive type definition?
type Comment = { id: string; content: string; replies: Comment[] } should work. The key is the self-referencing replies array.