⚡ Bolt: Optimize search highlight rendering loop #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
💡 What:
Moved the
escapeHtmlutility function to the global scope and refactored the search highlighting logic. Instead of creating a newRegExpand querying the DOM for the search term for every single PDF card during a render, we now calculate the regex once at the start ofrenderPDFsand pass it down tocreatePDFCard.🎯 Why:
When rendering a list of 50-100+ PDFs, the previous implementation performed N DOM lookups (
document.getElementById) and Nnew RegExpcompilations every time the user typed a character. This caused unnecessary main thread work. Additionally, typing an invalid regex character (like() would previously crash the application; this is now handled safely.📊 Impact:
🔬 Measurement:
Verified by typing "chem" in the search bar. The highlighting works exactly as before, but the underlying execution is more efficient. A Playwright script confirmed the
class="highlight"span is correctly applied to matching text.PR created automatically by Jules for task 2515816655690988592 started by @MrAlokTech