mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-15 21:28:33 -05:00
[PR #1947] [MERGED] perf(book): stop unbounded full-document rescans in quiz numbering fix #34671
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1947
Author: @farhan523
Created: 7/7/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/sidebar-quiz-numbering-perf📝 Commits (1)
854c602perf(book): stop unbounded full-document rescans in quiz numbering fix📊 Changes
1 file changed (+10 additions, -5 deletions)
View changed files
📝
book/quarto/assets/scripts/sidebar-auto-collapse.js(+10 -5)📄 Description
Problem
book/quarto/assets/scripts/sidebar-auto-collapse.js(loaded on every book page) sets up:Every DOM mutation anywhere on the page schedules a fresh, un-debounced
fixQuizNumbering()pass, and each pass runs a full-documentquerySelectorAllover all quiz callouts plus aconsole.logper renamed element. Consequences on long chapter pages:fixQuizNumbering()itself writestextContent, re-triggering the very observer it runs under.console.logspam here and insetNavbarActiveState()on every pass.Users feel this as slower time-to-interactive, scroll/typing jank while SocratiQ streams, and battery drain on long reading sessions.
Fix
data-quiz-number-fixedand exclude them via:not([data-quiz-number-fixed])in the selector — repeat passes match nothing and return immediately. Callouts whose title element isn't rendered yet stay unmarked, so the existing staggered retries (100/500/1000/2000 ms) still pick them up.childList, so setting the marker attribute cannot re-trigger it.)console.logfrom thefixQuizNumbering()andsetNavbarActiveState()hot paths.Behavior
No visible change: quiz titles are still renamed ("Self-Check: Question 1.3" → "Self-Check: Question 3"), same retry schedule, and dynamically injected callouts are still processed (new nodes lack the marker attribute). Only the redundant re-scanning is eliminated.
Verified with
node --check; diff is +10/−5 lines in one file.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.