Skip to content

Conversation

@MrAlokTech
Copy link
Owner

💡 What:
Moved the escapeHtml utility function to the global scope and refactored the search highlighting logic. Instead of creating a new RegExp and querying the DOM for the search term for every single PDF card during a render, we now calculate the regex once at the start of renderPDFs and pass it down to createPDFCard.

🎯 Why:
When rendering a list of 50-100+ PDFs, the previous implementation performed N DOM lookups (document.getElementById) and N new RegExp compilations 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:

  • Reduces RegExp compilation from O(N) to O(1) per render.
  • Reduces DOM access from O(N) to O(1) per render.
  • Prevents application crashes on invalid regex search terms.

🔬 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

- Move `escapeHtml` to global scope to reduce closure creation.
- Pre-compile `highlightRegex` in `renderPDFs` once per render cycle instead of O(N) times inside `createPDFCard`.
- Pass `highlightRegex` to `createPDFCard` to avoid repeated DOM access and RegExp instantiation.
- Add try-catch block for regex creation to prevent crashes on invalid input (e.g. "(").

Co-authored-by: MrAlokTech <107493955+MrAlokTech@users.noreply.github.com>
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cloudflare-workers-and-pages
Copy link

Deploying classnotes with  Cloudflare Pages  Cloudflare Pages

Latest commit: bdef999
Status: ✅  Deploy successful!
Preview URL: https://15f176e9.classnotes.pages.dev
Branch Preview URL: https://bolt-optimize-search-render.classnotes.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant