Add a maximum nesting depth for collapsible details

Hi @scavin, thanks for reporting this and for providing the reproduction details.

I’ve been investigating the Markdown endpoint slowdown you described and identified an issue in MarkdownEndpoint::CookedProcessor#replace_details: nested <details> elements were being converted repeatedly, resulting in exponential processing.

I’ve opened a draft upstream PR with a fix:

At eight nesting levels, the fix reduced recursive conversions from 255 to 8, with approximately a 31× speedup in my local benchmark. The PR has passed its initial GitHub CI checks.

I’m also working on your proposed details_max_nesting_depth site setting within the built-in Details plugin, using 0 for unlimited nesting to preserve existing behaviour. The initial implementation is written, but its integration tests are still in progress.

The performance fix addresses the server-side Markdown conversion problem; the configurable limit would provide an additional safeguard, particularly for browser-side performance.

I’d welcome feedback on the proposed setting and whether it would be preferable to include it in the same PR or submit it separately.

1 Like