     private var visibleChildren: [Int: [Item]] = [:]
 
     private func visibleChildren(for section: Int) -> [Item] {
-        return visibleChildren[section, default: displayedRows[section].visibleChildren(isCollapsed)]
+        if visibleChildren[section] == nil {
+            visibleChildren[section] = displayedRows[section].visibleChildren(isCollapsed)
+        }
+        return visibleChildren[section] ?? []
     }
 }

        toggleCollapse(viewModel)
        if wasCollapsed {
            tableView.insertRows(at: indexPaths, with: (hasAnimation ? .automatic : .none))
        } else {
            delegate?.collapsableTableViewDataSource(self, willHideCellsAt: indexPaths, at: tableView)
            tableView.deleteRows(at: indexPaths, with: (hasAnimation ? .top : .none))
        }
        tableView.reloadRows(at: [indexPath], with: .none)
        visibleChildren.removeValue(forKey: indexPath.section)
        tableView.endUpdates()
        return true
    }

        }
        
        let neededChildrenCount: Int
        let neededVisibleChildren: [Item]
        if isCollapsed(viewModel) {
            var visibleSubschildren: [Item] = []
            visibleSubschildren.reserveCapacity(viewModel.children.count * 2)
            for i in viewModel.children.indices {
                visibleSubschildren.append(viewModel.children[i])
                visibleSubschildren.append(contentsOf: viewModel.children[i].visibleChildren(isCollapsed))
            }
            neededVisibleChildren = visibleSubschildren
            neededChildrenCount = neededVisibleChildren.count
        } else {
            neededVisibleChildren = viewModel.visibleChildren(isCollapsed)
            neededChildrenCount = neededVisibleChildren.count
        }
        let range = indexPath.row+1...indexPath.row+neededChildrenCount
        let indexPaths = range.map { return IndexPath(row: $0, section: indexPath.section) }
