Fix snippet TOC always showing first file's headings
What does this MR do and why?
Fixes TOC in a snippet always shows first file's head... (#603300 - closed).
Cause
document.querySelector returns only the first match in the document,
so every TOC instance in a multi-file snippet grabbed the first blob viewer
regardless of which file was selected.
Approach
- Scoped the query to the containing
.file-holder, which wraps each file's header, content, and TOC in both snippet and repository views. - Wrapped the template in a
<div>so thatthis.$elis never a comment node, which has noclosest()method.
Red → Green Cycle
- 64d7f9e0: Add spec for TOC with multiple files
→
🔴 RED — at this point due to the existing bug (job log) - 0b555a29: Scope the query to
.file-holder→🟢 GREEN
Screenshots
Manually verified in GDK-in-a-box:
Notes
- I don't work on the frontend regularly, so a careful look at this approach would be very helpful.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by skkzsh
