Add a maximum nesting depth for collapsible details

Thanks for the quick investigation and fix!
I think separating them into two PRs would be better, so the performance fix can be reviewed and merged independently without waiting for the new setting.
I also support the configurable depth limit, with 0 as the default for backward compatibility.